Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

feat(console): list the rooms you are in, not only the ones you own

raullopez-sandboxa6eec2a4d1be
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
index 874779787..d364544d4 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
@@ -2899,6 +2899,7 @@ type RoomSummaryJson = {
bridge_type?: string | null;
external_channel_url?: string | null;
owner_id?: string | null;
+ viewer_is_member?: boolean;
archived: boolean;
created_at: string;
};
@@ -2914,6 +2915,7 @@ function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {
bridgeType: r.bridge_type ?? null,
externalChannelUrl: r.external_channel_url ?? null,
ownerId: r.owner_id ?? null,
+ viewerIsMember: r.viewer_is_member ?? false,
archived: r.archived,
createdAt: r.created_at,
};
diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.ts
new file mode 100644
index 000000000..e749b679c
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it, vi } from 'vitest';
+
+vi.mock('@renderer/lib/ipc', () => ({ events: { on: vi.fn() }, rpc: {} }));
+
+const { managedIdentities } = await import('./sidebar-tree-data');
+const { queryClient } = await import('@renderer/lib/query-client');
+
+describe('managedIdentities', () => {
+ it('names the managed agents the list last read, so their rooms are reconciled too', () => {
+ queryClient.setQueryData(
+ ['managed-agents', 'srv', 'ws-a', 'user'],
+ [{ agentId: 'buddy', workspaceId: 'ws-a' }]
+ );
+ queryClient.setQueryData(['managed-agents', 'srv-2', 'ws-b', 'user'], null);
+ expect(managedIdentities()).toEqual([{ workspaceId: 'ws-a', switchAgentId: 'buddy' }]);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts
index adb275583..8ef5d4c71 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts
@@ -1,14 +1,17 @@
import { agentsStore } from '@renderer/features/locations/stores/agents-store';
import type { LocationStore } from '@renderer/features/locations/stores/location';
+import { MANAGED_AGENTS_KEY } from '@renderer/features/managed-agents/use-managed-agents-key';
import type { SessionStore } from '@renderer/features/sessions/stores/session-store';
import { serverAvailability } from '@renderer/features/switch-servers/server-availability';
import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { toast } from '@renderer/lib/hooks/use-toast';
import { rpc } from '@renderer/lib/ipc';
+import { queryClient } from '@renderer/lib/query-client';
import { sidebarStore } from '@renderer/lib/stores/app-state';
import { log } from '@renderer/utils/logger';
import type { Agent } from '@shared/core/agents/agents';
+import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';
import type { AgentIconBackfill } from '@shared/core/switch-servers/switch-servers';
/**
@@ -106,6 +109,17 @@ export function switchIdentities(): { workspaceId: string; switchAgentId: string
return identities;
}
+/**
+ * The user's managed agents, as the shared list last read them: their rooms
+ * belong in the sidebar too, wherever the agents run.
+ */
+export function managedIdentities(): { workspaceId: string; switchAgentId: string }[] {
+ return queryClient
+ .getQueriesData<ManagedAgentView[] | null>({ queryKey: [MANAGED_AGENTS_KEY] })
+ .flatMap(([, agents]) => (Array.isArray(agents) ? agents : []))
+ .map((agent) => ({ workspaceId: agent.workspaceId, switchAgentId: agent.agentId }));
+}
+
/**
* Re-read everything the sidebar's trees are built from: this install's agents,
* their room membership, and the room catalogue.
@@ -123,7 +137,9 @@ export function switchIdentities(): { workspaceId: string; switchAgentId: string
export async function refreshSidebarRoomState(force: boolean): Promise<void> {
await agentsStore.load();
await Promise.all([
- switchRoomsStore.ensureMembershipsFor(switchIdentities(), { force }),
+ switchRoomsStore.ensureMembershipsFor([...switchIdentities(), ...managedIdentities()], {
+ force,
+ }),
switchRoomsStore.loadRoomNames(),
]);
void giveExistingAgentsAnIcon();
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.test.ts
index dfb30ad2c..28e9daffd 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.test.ts
@@ -102,6 +102,7 @@ describe('withConsoleGroupChats', () => {
bridgeType: null,
externalChannelUrl: null,
ownerId: 'u',
+ viewerIsMember: false,
archived: false,
createdAt: '',
});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts
index 275089cae..d39129234 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts
@@ -52,6 +52,7 @@ export function withConsoleGroupChats(
externalChannelUrl: null,
// shortcut: a chat summary names no owner, so a chat-only row offers no delete; read it from the room detail if one is wanted.
ownerId: null,
+ viewerIsMember: true,
archived: false,
createdAt: chat.lastMessage?.sentAt ?? '',
})
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-by-messaging-app.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-by-messaging-app.test.ts
index 15540da3e..813190959 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-by-messaging-app.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-by-messaging-app.test.ts
@@ -12,6 +12,7 @@ const room = (id: string, bridgeType: string | null): RemoteRoomSummary => ({
bridgeType,
externalChannelUrl: null,
ownerId: null,
+ viewerIsMember: false,
archived: false,
createdAt: '',
});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts
index ff67ef714..e9ff2994b 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts
@@ -51,6 +51,7 @@ function room(id: string, ownerId: string | null, overrides: Partial<RemoteRoomS
bridgeType: null,
externalChannelUrl: null,
ownerId,
+ viewerIsMember: false,
archived: false,
createdAt: '2026-01-01T00:00:00Z',
...overrides,
@@ -111,6 +112,53 @@ describe('listed rooms', () => {
expect(store.listedRoomsInActiveScope.map((r: { id: string }) => r.id)).toEqual(['mine']);
});
+ it('also lists the rooms the signed-in user is a member of, not every room', async () => {
+ listRooms.mockImplementation(async (workspaceId: string) =>
+ workspaceId === 'ws-a'
+ ? [
+ room('mine', 'user-of-srv-a'),
+ room('invited', 'user-of-someone-else', { viewerIsMember: true }),
+ room('someone-elses', 'user-of-someone-else'),
+ ]
+ : []
+ );
+
+ const store = new SwitchRoomsStore();
+ await store.loadRoomNames();
+
+ expect(store.listedRoomsInActiveScope.map((r: { id: string }) => r.id)).toEqual([
+ 'invited',
+ 'mine',
+ ]);
+ });
+
+ it('lists the rooms the user’s agents are in, and drops one when that membership ends', async () => {
+ listRooms.mockImplementation(async (workspaceId: string) =>
+ workspaceId === 'ws-a'
+ ? [room('agents-room', 'user-of-someone-else'), room('unrelated', 'user-of-someone-else')]
+ : []
+ );
+ const membership = {
+ roomId: 'agents-room',
+ roomName: 'agents-room',
+ archived: false,
+ status: 'active',
+ roomRole: null,
+ };
+ listAgentRooms.mockResolvedValueOnce([membership]);
+
+ const store = new SwitchRoomsStore();
+ await store.loadRoomNames();
+ await store.ensureMembershipsFor([{ workspaceId: 'ws-a', switchAgentId: 'buddy' }]);
+ expect(store.listedRoomsInActiveScope.map((r: { id: string }) => r.id)).toEqual([
+ 'agents-room',
+ ]);
+
+ listAgentRooms.mockResolvedValueOnce([]);
+ await store.refreshRoomState();
+ expect(store.listedRoomsInActiveScope.map((r: { id: string }) => r.id)).toEqual([]);
+ });
+
it('shows only the active workspace’s rooms, not every connected one’s', async () => {
listRooms.mockImplementation(async (workspaceId: string) => [
room(`${workspaceId}-room`, `user-of-${workspaces.serverIdFor(workspaceId)}`),
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
index cfdae24e8..7cc6f08e3 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
@@ -163,8 +163,9 @@ export class SwitchRoomsStore {
*
* In a workspace on a server this install manages, that is **every** room: you
* run the deployment, so there is nothing on it you should have to go
- * elsewhere to see. Anywhere else it is the rooms you created, which would
- * otherwise disappear the moment you made one and put no agent in it.
+ * elsewhere to see. Anywhere else it is the rooms you created (which would
+ * otherwise disappear the moment you made one and put no agent in it), the
+ * rooms you are a member of, and the rooms your agents are in.
*
* The sidebar tree shows one workspace at a time, so these follow the same
* scope rule as locations do — including that no active workspace hides
@@ -183,11 +184,14 @@ export class SwitchRoomsStore {
listedRoomsInWorkspace(workspaceId: string): RemoteRoomSummary[] {
const serverId = workspacesStore.serverIdFor(workspaceId);
const managed = switchServersStore.servers.find((s) => s.id === serverId)?.managed ?? false;
- return (
- (managed
- ? this.allRoomsByWorkspace.get(workspaceId)
- : this.ownedRoomsByWorkspace.get(workspaceId)) ?? []
+ if (managed) return this.allRoomsByWorkspace.get(workspaceId) ?? [];
+ const own = this.ownedRoomsByWorkspace.get(workspaceId) ?? [];
+ const ownIds = new Set(own.map((room) => room.id));
+ // And the rooms the user's agents are in, managed ones included, by their membership.
+ const ofAgents = (this.allRoomsByWorkspace.get(workspaceId) ?? []).filter(
+ (room) => !ownIds.has(room.id) && this.localMemberIdsByRoom.has(room.id)
);
+ return [...own, ...ofAgents];
}
/**
@@ -340,7 +344,9 @@ export class SwitchRoomsStore {
this.allRoomsByWorkspace.set(workspace.id, active);
this.ownedRoomsByWorkspace.set(
workspace.id,
- signedInUserId ? active.filter((r) => r.ownerId === signedInUserId) : []
+ signedInUserId
+ ? active.filter((r) => r.ownerId === signedInUserId || r.viewerIsMember)
+ : []
);
});
} catch (cause) {
diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
index 27a05a2b6..1f440ad1b 100644
--- a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
@@ -331,6 +331,8 @@ export type RemoteRoomSummary = {
* Rooms the signed-in user owns stay listed in the sidebar even with no live
* session, so a room you just made never vanishes on you. */
ownerId: string | null;
+ /** The signed-in user is a member of the room. False from a server that does not say. */
+ viewerIsMember: boolean;
archived: boolean;
createdAt: string;
};