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): open group chats in the room view

raullopez-sandbox86c8b93be8a8
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/chat-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/chat-view.tsx
index b389f4ea0..e29b1efcb 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/chat-view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/chat-view.tsx
@@ -3,6 +3,7 @@ import { useEffect } from 'react';
import type { GuardResult, ViewDefinition } from '@renderer/app/view-registry';
import { managedAgentLabel } from '@renderer/features/managed-agents/managed-agent-state';
import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';
+import { isConsoleGroupChatSummary } from '@renderer/features/switch-servers/room-filters';
import { Titlebar } from '@renderer/lib/components/titlebar/Titlebar';
import { useParams } from '@renderer/lib/layout/navigation-provider';
import { appState } from '@renderer/lib/stores/app-state';
@@ -66,9 +67,29 @@ function useLeaveWhenChatsOff(params: ChatParams): boolean | undefined {
return enabled;
}
+/**
+ * A group chat opens as a room, including a direct chat the moment it becomes
+ * one; its draft and loaded messages are held by chat, so they come along.
+ */
+function useOpenGroupAsRoom(roomId: string): void {
+ const chat = chatsStore.chat(roomId);
+ const group = chat !== undefined && isConsoleGroupChatSummary(chat);
+ useEffect(() => {
+ if (!group) return;
+ appState.history.prune(
+ (entry) =>
+ entry.kind === 'view' &&
+ entry.viewId === 'chat' &&
+ (entry.params as { roomId?: string }).roomId === roomId
+ );
+ appState.navigation.navigate('room', { roomId });
+ }, [group, roomId]);
+}
+
const ChatMainPanel = observer(function ChatMainPanel(): React.JSX.Element | null {
const { params } = useParams('chat');
const enabled = useLeaveWhenChatsOff(params);
+ useOpenGroupAsRoom(params.roomId);
if (enabled !== true) return null;
return (
<ChatPanel
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/console-chat-redirect.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/console-chat-redirect.tsx
index 29b8aedd0..06652a5b0 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/console-chat-redirect.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/console-chat-redirect.tsx
@@ -1,13 +1,26 @@
import { observer } from 'mobx-react-lite';
import { useEffect } from 'react';
import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';
-import { isConsoleDirectChatSummary } from '@renderer/features/switch-servers/room-filters';
+import {
+ isConsoleDirectChatSummary,
+ isConsoleGroupChatSummary,
+} from '@renderer/features/switch-servers/room-filters';
import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';
import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';
import { appState } from '@renderer/lib/stores/app-state';
import { consoleChatRoute } from './console-chat-route';
import { chatsStore } from './stores/chats';
+/**
+ * Whether the room page shows a room as a Console chat: a group chat, or a
+ * chat just lost, whose panel says so rather than falling back to the room's
+ * messaging app.
+ */
+export function opensAsConsoleChat(roomId: string): boolean {
+ const chat = chatsStore.chat(roomId);
+ return chat ? isConsoleGroupChatSummary(chat) : chatsStore.removed.has(roomId);
+}
+
/**
* On the room page, with agent_chats on: a 1-1 Console chat is not a room, so
* it opens in the chat UI instead, whether reached from a deep link, search, a
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx
index ec95a8a95..5c0f7f04b 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx
@@ -1,6 +1,7 @@
import { ExternalLink, Loader2, MessagesSquare, RefreshCw } from 'lucide-react';
import { observer } from 'mobx-react-lite';
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
+import { opensAsConsoleChat } from '@renderer/features/chats/console-chat-redirect';
import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';
import { bridgePlatformLabel } from '@renderer/lib/components/bridge-platform';
import { failureText } from '@renderer/lib/errors/describe-failure';
@@ -111,6 +112,8 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {
(appState.navigation.viewParamsStore.room as { roomId?: string } | undefined)?.roomId ?? null;
const slot = roomEmbedSlotStore.slot;
const activeRoomId = slot?.roomId ?? navigatedRoomId;
+ // A Console chat has no channel to embed; the room view draws its conversation.
+ const consoleChat = activeRoomId !== null && opensAsConsoleChat(activeRoomId);
const layerRef = useRef<HTMLDivElement>(null);
const slotBox = useBoxWithin(slot?.element ?? null, layerRef);
@@ -165,7 +168,7 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {
// Resolve a room the first time it is opened, and evict the oldest beyond the
// cap. Rooms already resolved are left alone — that is the whole point.
useEffect(() => {
- if (!activeRoomId) return;
+ if (!activeRoomId || consoleChat) return;
orderRef.current = [...orderRef.current.filter((id) => id !== activeRoomId), activeRoomId];
const evicted = orderRef.current.slice(0, -MAX_LIVE_EMBEDS);
@@ -181,7 +184,7 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {
}
if (!startedRef.current.has(activeRoomId)) void resolve(activeRoomId);
- }, [activeRoomId, resolve]);
+ }, [activeRoomId, consoleChat, resolve]);
// The room list is read again every little while; a room whose channel link
// has come back since it was opened is opened again.
@@ -230,6 +233,7 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {
const visible =
(slot ? slotBox !== null : isRoomView) &&
activeRoomId !== null &&
+ !consoleChat &&
roomTabStore.tabFor(activeRoomId, slot ? embeddedRoomFallbackTab(activeRoomId) : 'chat') ===
'chat';
const active = activeState;
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/view.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/view.tsx
index 220b75a7c..5751213a7 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/view.tsx
@@ -2,7 +2,12 @@ import { DoorOpen, ExternalLink } from 'lucide-react';
import { observer } from 'mobx-react-lite';
import { useLayoutEffect, useRef } from 'react';
import type { GuardResult, ViewDefinition } from '@renderer/app/view-registry';
-import { ConsoleChatRedirect } from '@renderer/features/chats/console-chat-redirect';
+import { ChatPanel } from '@renderer/features/chats/components/chat-panel';
+import {
+ ConsoleChatRedirect,
+ opensAsConsoleChat,
+} from '@renderer/features/chats/console-chat-redirect';
+import { chatsStore } from '@renderer/features/chats/stores/chats';
import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';
import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';
import { bridgePlatformLabel } from '@renderer/lib/components/bridge-platform';
@@ -96,7 +101,8 @@ export const RoomTabs = observer(function RoomTabs({
*/
const RoomTitlebar = observer(function RoomTitlebar() {
const { params } = useParams('room');
- const name = switchRoomsStore.roomNameById(params.roomId);
+ const name =
+ switchRoomsStore.roomNameById(params.roomId) ?? chatsStore.chat(params.roomId)?.name ?? null;
const bridgeType = switchRoomsStore.roomBridgeTypeById(params.roomId);
return (
@@ -128,15 +134,25 @@ const RoomTitlebar = observer(function RoomTitlebar() {
);
});
-/** Settings when the room is showing them; otherwise nothing, and the
- * conversation drawn by `RoomEmbedLayer` above shows through. */
+/** A Console chat's conversation, drawn here rather than by `RoomEmbedLayer`. */
+const ConsoleChat = observer(function ConsoleChat({ roomId }: { roomId: string }) {
+ const serverId = chatsStore.serverId;
+ if (!serverId || !opensAsConsoleChat(roomId)) return null;
+ return <ChatPanel key={`${serverId}:${roomId}`} serverId={serverId} roomId={roomId} />;
+});
+
+/** Settings when the room is showing them; otherwise a Console chat's
+ * conversation, or nothing, and the conversation drawn by `RoomEmbedLayer`
+ * above shows through. */
const RoomMainPanel = observer(function RoomMainPanel(): React.JSX.Element {
const { params } = useParams('room');
return (
<>
<ConsoleChatRedirect roomId={params.roomId} />
- {roomTabStore.tabFor(params.roomId, 'chat') === 'configuration' && (
+ {roomTabStore.tabFor(params.roomId, 'chat') === 'configuration' ? (
<RoomConfigurationPanel roomId={params.roomId} />
+ ) : (
+ <ConsoleChat roomId={params.roomId} />
)}
</>
);
@@ -165,8 +181,10 @@ export const EmbeddedRoom = observer(function EmbeddedRoom({ roomId }: { roomId:
}, [roomId]);
return (
<div ref={ref} data-testid="embedded-room" className="min-h-0 flex-1">
- {roomTabStore.tabFor(roomId, embeddedRoomFallbackTab(roomId)) === 'configuration' && (
+ {roomTabStore.tabFor(roomId, embeddedRoomFallbackTab(roomId)) === 'configuration' ? (
<RoomConfigurationPanel roomId={roomId} />
+ ) : (
+ <ConsoleChat roomId={roomId} />
)}
</div>
);
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 00d276985..f59463187 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
@@ -1,5 +1,12 @@
import { describe, expect, it } from 'vitest';
-import { isConsoleDirectChat, isConsoleDirectChatSummary } from './room-filters';
+import type { ChatSummary } from '@shared/core/chats/chats';
+import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
+import {
+ isConsoleDirectChat,
+ isConsoleDirectChatSummary,
+ isConsoleGroupChatSummary,
+ withConsoleGroupChats,
+} from './room-filters';
const agent = { id: 'a', name: 'a', displayName: null, iconUrl: null, provider: null, alias: null, ownerName: null, ownedByViewer: false };
@@ -45,3 +52,54 @@ describe('isConsoleDirectChatSummary', () => {
).toBe(false);
});
});
+
+const chat = (roomId: string, extra: Partial<ChatSummary> = {}): ChatSummary => ({
+ roomId,
+ name: roomId,
+ channelType: 'channel_private',
+ bridgeType: null,
+ channelName: null,
+ agents: [agent],
+ canManage: false,
+ ownsAgent: false,
+ lastMessage: null,
+ ...extra,
+});
+
+describe('isConsoleGroupChatSummary', () => {
+ it('is an unbridged chat that is not 1-1, people-only included', () => {
+ expect(isConsoleGroupChatSummary(chat('g'))).toBe(true);
+ expect(isConsoleGroupChatSummary(chat('g', { agents: [] }))).toBe(true);
+ expect(isConsoleGroupChatSummary(chat('d', { channelType: 'direct' }))).toBe(false);
+ });
+
+ it('leaves bridged rooms to their messaging app', () => {
+ for (const bridgeType of ['slack', 'mattermost'])
+ expect(isConsoleGroupChatSummary(chat('b', { bridgeType }))).toBe(false);
+ });
+});
+
+describe('withConsoleGroupChats', () => {
+ const room = (id: string): RemoteRoomSummary => ({
+ id,
+ name: id,
+ description: '',
+ channelType: 'channel_private',
+ agentCount: 1,
+ bridgeDisplayName: null,
+ bridgeType: null,
+ externalChannelUrl: null,
+ ownerId: 'u',
+ archived: false,
+ createdAt: '',
+ });
+
+ it('adds the group chats not already listed, sorted by name', () => {
+ const listed = withConsoleGroupChats(
+ [room('b'), room('d')],
+ [chat('a'), chat('b'), chat('c', { channelType: 'direct' }), chat('e', { bridgeType: 'slack' })]
+ );
+ expect(listed.map((each) => each.id)).toEqual(['a', 'b', 'd']);
+ expect(listed[1].ownerId).toBe('u');
+ });
+});
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 52e651f33..275089cae 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
@@ -20,3 +20,42 @@ export function isConsoleDirectChatSummary(
): boolean {
return isConsoleDirectChat({ ...chat, agentCount: chat.agents.length });
}
+
+/** A Console group chat: an unbridged chat that is not a 1-1 Console chat. It opens as a room. */
+export function isConsoleGroupChatSummary(
+ chat: Pick<ChatSummary, 'channelType' | 'bridgeType' | 'agents'>
+): boolean {
+ return chat.bridgeType === null && !isConsoleDirectChatSummary(chat);
+}
+
+/**
+ * `rooms` and, as rooms, the group chats not among them: the room list holds
+ * only rooms you own or that are public, so a person invited to a chat would
+ * not see it otherwise.
+ */
+export function withConsoleGroupChats(
+ rooms: RemoteRoomSummary[],
+ chats: Iterable<ChatSummary>
+): RemoteRoomSummary[] {
+ const listed = new Set(rooms.map((room) => room.id));
+ const added = [...chats]
+ .filter((chat) => isConsoleGroupChatSummary(chat) && !listed.has(chat.roomId))
+ .map(
+ (chat): RemoteRoomSummary => ({
+ id: chat.roomId,
+ name: chat.name,
+ description: '',
+ channelType: chat.channelType,
+ agentCount: chat.agents.length,
+ bridgeDisplayName: null,
+ bridgeType: null,
+ 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,
+ archived: false,
+ createdAt: chat.lastMessage?.sentAt ?? '',
+ })
+ );
+ if (added.length === 0) return rooms;
+ return [...rooms, ...added].sort((a, b) => a.name.localeCompare(b.name));
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts
index ab2f8e340..2aa2399fd 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts
@@ -1,8 +1,9 @@
import { computed } from 'mobx';
+import { chatsStore } from '@renderer/features/chats/stores/chats';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';
import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
-import { isConsoleDirectChat } from './room-filters';
+import { isConsoleDirectChat, withConsoleGroupChats } from './room-filters';
import { switchRoomsStore } from './switch-rooms-store';
import { switchServersStore } from './switch-servers-store';
@@ -17,23 +18,32 @@ function filterConsoleDirectChats(
/**
* Rooms listed in the sidebar and on the Your Rooms page, filtered by the
* agent_chats flag: when on, 1-1 Console chats (see `isConsoleDirectChat`)
- * are hidden. Bridged DMs and multi-agent rooms stay visible.
+ * are hidden and the group chats you are in are listed. Bridged DMs and
+ * multi-agent rooms stay visible.
*/
export function useListedRoomsInActiveScope(): RemoteRoomSummary[] {
const flags = useFeatureFlags(switchServersStore.activeServerId);
return computed(() =>
- filterConsoleDirectChats(switchRoomsStore.listedRoomsInActiveScope, flags.agent_chats)
+ withConsoleGroupChats(
+ filterConsoleDirectChats(switchRoomsStore.listedRoomsInActiveScope, flags.agent_chats),
+ flags.agent_chats ? chatsStore.chats.values() : []
+ )
).get();
}
/**
- * Readable rooms in a workspace, filtered by the agent_chats flag when on.
+ * Readable rooms in a workspace, filtered by the agent_chats flag when on, with
+ * the group chats you are in when it is the active workspace, which is the one
+ * chats follow.
*/
export function useReadableRoomsInWorkspace(workspaceId: string | null): RemoteRoomSummary[] {
const flags = useFeatureFlags(workspaceId && workspacesStore.serverIdFor(workspaceId));
if (workspaceId === null) return [];
- return filterConsoleDirectChats(
- switchRoomsStore.readableRoomsInWorkspace(workspaceId),
- flags.agent_chats
+ return withConsoleGroupChats(
+ filterConsoleDirectChats(
+ switchRoomsStore.readableRoomsInWorkspace(workspaceId),
+ flags.agent_chats
+ ),
+ flags.agent_chats && workspaceId === workspacesStore.activeId ? chatsStore.chats.values() : []
);
}