Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
feat(console): leave a room, as any member
raullopez-sandbox15cfd742e930
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/chat-removal.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/chat-removal.tsindex a3e30168b..43cf591f8 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/chat-removal.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/chat-removal.ts@@ -1,6 +1,6 @@-/** Where the person goes once a chat is deleted or archived: nowhere unless it was the one open. */+/** Where the person goes once a chat is deleted, archived or left: nowhere unless it was the one open. */export type ChatRemovalNavigation = {- /** The chat view shows the removed chat: leave it. */+ /** The chat view, or the room view, shows the removed chat: leave it. */leaveChatView: boolean;/** The agent page points at the removed chat: drop it, so the page opens another or starts one. */clearAgentChat: boolean;@@ -8,10 +8,12 @@ export type ChatRemovalNavigation = {export function chatRemovalNavigation(roomId: string,- nav: { currentViewId: string; chatRoomId?: string; agentRoomId?: string }+ nav: { currentViewId: string; chatRoomId?: string; roomRoomId?: string; agentRoomId?: string }): ChatRemovalNavigation {return {- leaveChatView: nav.currentViewId === 'chat' && nav.chatRoomId === roomId,+ leaveChatView:+ (nav.currentViewId === 'chat' && nav.chatRoomId === roomId) ||+ (nav.currentViewId === 'room' && nav.roomRoomId === roomId),clearAgentChat: nav.agentRoomId === roomId,};}diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-actions.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-actions.tsxindex a52cdbcdd..de751ffd8 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-actions.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-actions.tsx@@ -1,4 +1,4 @@-import { Archive, Pencil, Trash2 } from 'lucide-react';+import { Archive, LogOut, Pencil, Trash2 } from 'lucide-react';import { Fragment, type ReactNode } from 'react';import { failureText } from '@renderer/lib/errors/describe-failure';import { toast } from '@renderer/lib/hooks/use-toast';@@ -7,6 +7,7 @@ import { appState } from '@renderer/lib/stores/app-state';import { DropdownMenuItem, DropdownMenuSeparator } from '@renderer/lib/ui/dropdown-menu';import type { ChatSummary } from '@shared/core/chats/chats';import { chatRemovalNavigation } from '../chat-removal';+import { chatFailure } from '../stores/chat-errors';import { chatsStore } from '../stores/chats';export type ChatAction = {@@ -31,6 +32,7 @@ function leaveIfOpen(roomId: string): void {const { leaveChatView, clearAgentChat } = chatRemovalNavigation(roomId, {currentViewId: navigation.currentViewId,chatRoomId: navigation.viewParamsStore.chat?.roomId,+ roomRoomId: (navigation.viewParamsStore.room as { roomId?: string } | undefined)?.roomId,agentRoomId: navigation.viewParamsStore.managedAgent?.roomId,});if (leaveChatView) navigation.navigate('home');@@ -38,12 +40,44 @@ function leaveIfOpen(roomId: string): void {}/**- * What can be done to a chat from its row or its header. Each acts on the room- * for everyone in it, so each is offered only to its managers: the room's owner- * or a workspace admin, the same rule the server applies.+ * Leave a chat after asking: it goes from the lists and its open view closes.+ * A refusal, such as owning an agent in it, leaves everything as it was and+ * says why.+ */+export function confirmLeaveChat(serverId: string, chat: ChatSummary): void {+ showModal('confirmActionModal', {+ title: `Leave ${chat.name}?`,+ description:+ 'You stop seeing its messages and it leaves your lists. Someone who manages it can add you back.',+ confirmLabel: 'Leave room',+ onSuccess: () =>+ void (async () => {+ try {+ await chatsStore.leave(serverId, chat.roomId);+ } catch (error) {+ toast({ title: chatFailure(error).message, variant: 'destructive' });+ return;+ }+ leaveIfOpen(chat.roomId);+ })(),+ });+}++/**+ * What can be done to a chat from its row or its header. Leaving is anyone's;+ * the rest act on the room for everyone in it, so each is offered only to its+ * managers: the room's owner or a workspace admin, the same rule the server+ * applies.*/export function chatActions(serverId: string, chat: ChatSummary): ChatAction[] {- if (!chat.canManage) return [];+ const leave: ChatAction = {+ key: 'leave',+ label: 'Leave room…',+ icon: <LogOut className="size-4" />,+ separatorBefore: true,+ run: () => confirmLeaveChat(serverId, chat),+ };+ if (!chat.canManage) return [leave];const { roomId } = chat;return [{@@ -80,6 +114,7 @@ export function chatActions(serverId: string, chat: ChatSummary): ChatAction[] {}, 'Could not delete the chat.'),}),},+ leave,];}diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.tsindex ef3202d5e..89638632c 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts@@ -36,6 +36,7 @@ export type ChatsApi = {archive: (serverId: string, roomId: string) => Promise<void>;delete: (serverId: string, roomId: string) => Promise<void>;markRead: (serverId: string, roomId: string, seq: number) => Promise<void>;+ removeMember: (serverId: string, roomId: string, userId: string) => Promise<void>;};/** How long reading settles before the read position is sent. */@@ -182,6 +183,14 @@ export class ChatsStore {await switchRoomsStore.refreshRoomState();}+ /** Leaves the chat; throws, leaving it listed and open, if the server refuses. */+ async leave(serverId: string, roomId: string): Promise<void> {+ if (this.userId === null) throw new Error('Not signed in to this chat’s server yet.');+ await this.api.removeMember(serverId, roomId, this.userId);+ this.remove(roomId, 'access');+ await switchRoomsStore.refreshRoomState();+ }+message(serverId: string, message: ChatMessage): void {if (serverId !== this.serverId) return;this.timelines.peek(serverId, message.roomId)?.apply(message);diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.tsindex f66665d68..f9d365d9f 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats.ts@@ -31,6 +31,8 @@ export const chatsStore = new ChatsStore(}),archive: (serverId, roomId) => rpc.chats.archive(serverId, roomId),delete: (serverId, roomId) => rpc.chats.delete(serverId, roomId),+ removeMember: (serverId, roomId, userId) =>+ rpc.chats.removeMember({ serverId, roomId, userId }),markRead: (serverId, roomId, seq) =>rpc.chats.markRead({ serverId, roomId, seq }).catch((error: unknown) => {// The count stays at 0 here; the server's comes back with the next summary.diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsxindex 8ab2c1fcb..0f1c8617a 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx@@ -3,6 +3,7 @@ import { ExternalLink, FileText, Loader2, Plus, RefreshCw, Search, X } from 'lucimport { observer } from 'mobx-react-lite';import { useState } from 'react';import { chatMembersQueryKey, workspaceRosterQuery } from '@renderer/features/chats/chat-people';+import { confirmLeaveChat } from '@renderer/features/chats/components/chat-actions';import { opensAsConsoleChat } from '@renderer/features/chats/console-chat-redirect';import { chatFailure } from '@renderer/features/chats/stores/chat-errors';import { chatsStore } from '@renderer/features/chats/stores/chats';@@ -103,6 +104,24 @@ const ChatConfiguration = observer(function ChatConfiguration({</p>)}<ChatParticipantsSection serverId={serverId} workspaceId={workspaceId} chat={chat} />+ <section className="border-t border-border pt-6">+ <div className="flex items-center justify-between gap-3">+ <div className="space-y-0.5">+ <h3 className="text-sm font-medium text-foreground">Leave room</h3>+ <p className="text-xs text-foreground-muted">+ You stop seeing its messages; someone who manages it can add you back.+ </p>+ </div>+ <Button+ variant="outline"+ size="sm"+ className="shrink-0"+ onClick={() => confirmLeaveChat(serverId, chat)}+ >+ Leave room…+ </Button>+ </div>+ </section></div></div>);diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.tsindex 279f1fae1..19a042635 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-configuration.test.ts@@ -97,6 +97,8 @@ describe('RoomConfigurationPanel for a group chat', () => {expect(html).toContain('Bob');expect(html).not.toContain('Add participants');expect(html).not.toContain('id="chat-add-participant"');+ // Leaving needs no manager rights.+ expect(html).toContain('Leave room…');expect(html).not.toContain('aria-label="Remove');});});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-removal.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-removal.test.tsindex 640840133..3fe729d5c 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-removal.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-removal.test.ts@@ -12,6 +12,14 @@ describe('chatRemovalNavigation', () => {expect(chatRemovalNavigation('!b', { currentViewId: 'chat', chatRoomId: '!a' })).toEqual(stay);});+ it('leaves the room view only when it shows the removed chat', () => {+ expect(chatRemovalNavigation('!a', { currentViewId: 'room', roomRoomId: '!a' })).toEqual({+ leaveChatView: true,+ clearAgentChat: false,+ });+ expect(chatRemovalNavigation('!b', { currentViewId: 'room', roomRoomId: '!a' })).toEqual(stay);+ });+it('drops the agent page chat only when it is the removed one', () => {expect(chatRemovalNavigation('!a', { currentViewId: 'managedAgent', agentRoomId: '!a' })diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.tsindex e21d4571a..b43c499c6 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts@@ -91,6 +91,7 @@ function setup(archive: vi.fn(async () => {}),delete: vi.fn(async () => {}),markRead: vi.fn(async () => {}),+ removeMember: vi.fn(async () => {}),};const store = new ChatsStore(api, events);return {@@ -276,6 +277,7 @@ async function viewer() {let onSummary: Parameters<ChatsEvents['onSummary']>[0] = () => {};let onMessage: Parameters<ChatsEvents['onMessage']>[0] = () => {};const markRead = vi.fn(async () => {});+ const removeMember = vi.fn(async (_serverId: string, _roomId: string, _userId: string) => {});const events: ChatsEvents = {onMessage: (cb) => {onMessage = cb;@@ -300,6 +302,7 @@ async function viewer() {archive: async () => {},delete: async () => {},markRead,+ removeMember,},events);@@ -309,6 +312,7 @@ async function viewer() {push: (chat: ChatSummary) => onSummary({ serverId: 's1', chat }),emit: (m: ChatMessage) => onMessage({ serverId: 's1', message: m }),markRead,+ removeMember,group,};}@@ -368,3 +372,21 @@ describe('ChatsStore unread counts', () => {}});});++describe('ChatsStore leave', () => {+ it('removes the viewer and drops the chat from the list', async () => {+ const { store, removeMember } = await viewer();+ await store.leave('s1', 'g');+ expect(removeMember).toHaveBeenCalledWith('s1', 'g', 'u');+ expect(store.chat('g')).toBeUndefined();+ expect(store.removed.has('g')).toBe(true);+ });++ it('keeps the chat as it was when the server refuses', async () => {+ const { store, removeMember } = await viewer();+ removeMember.mockRejectedValueOnce(new Error('You own an agent in this chat.'));+ await expect(store.leave('s1', 'g')).rejects.toThrow('You own an agent in this chat.');+ expect(store.chat('g')).toBeDefined();+ expect(store.removed.has('g')).toBe(false);+ });+});