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
fix(console): New chat reuses only an empty 1:1, never a group
raullopez-sandboxe6526bf03c15
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.test.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.test.tsindex d85b03295..c0f60d7ec 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.test.ts@@ -405,7 +405,7 @@ describe('EmptyChatFinder', () => {expect(finder.find('agent-1')).toBeNull();});- it('handles multi-agent chat default name', () => {+ it('never reuses a chat with more than one agent, which is a group', () => {const chat = makeChat({roomId: 'room-1',name: 'Chat with Ada, Bob',@@ -444,6 +444,36 @@ describe('EmptyChatFinder', () => {timeline: () => undefined,});- expect(finder.find('agent-1')).toBe(chat);+ expect(finder.find('agent-1')).toBeNull();+ });++ describe('only the viewer’s own 1:1 with the agent', () => {+ const finder = (chat: ChatSummary) =>+ new EmptyChatFinder({+ chatsOfAgent: () => [chat],+ userId: () => 'user-1',+ timeline: () => undefined,+ });++ it('reuses an empty direct chat with just the viewer in it', () => {+ const chat = makeChat({ memberUserIds: ['user-1'], memberCount: 1 });+ expect(finder(chat).find('agent-1')).toBe(chat);+ });++ it('never reuses an empty group, even one that was a direct chat', () => {+ const converted = makeChat({+ channelType: 'channel_private',+ memberUserIds: ['user-1', 'user-2'],+ memberCount: 2,+ });+ expect(finder(converted).find('agent-1')).toBeNull();+ const peopleInDirect = makeChat({ memberUserIds: ['user-1', 'user-2'], memberCount: 2 });+ expect(finder(peopleInDirect).find('agent-1')).toBeNull();+ });++ it('never reuses a bridged room or another agent’s chat', () => {+ expect(finder(makeChat({ bridgeType: 'slack' })).find('agent-1')).toBeNull();+ expect(finder(makeChat()).find('agent-2')).toBeNull();+ });});});diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.tsindex ede662e92..949414236 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/empty-chat-finder.ts@@ -1,3 +1,4 @@+import { isConsoleDirectChatSummary } from '@renderer/features/switch-servers/room-filters';import type { ChatMessage, ChatSummary } from '@shared/core/chats/chats';export type LoadedTimeline = {@@ -14,6 +15,9 @@ export type EmptyChatFinderDeps = {/*** Finds the most recent empty chat for an agent, where "empty" means the* current user has sent no messages. Agent greetings don't count as use.+ * Only the viewer's own 1:1 with that agent qualifies: a group, even one that+ * began as a direct chat, or a bridged room would carry a private message to+ * others.*/export class EmptyChatFinder {constructor(private readonly deps: EmptyChatFinderDeps) {}@@ -23,7 +27,9 @@ export class EmptyChatFinder {if (!userId) return null;const chats = this.deps.chatsOfAgent(agentId);- const empty = chats.filter((chat) => this.isEmpty(chat, userId));+ const empty = chats.filter(+ (chat) => isOwnDirectChat(chat, agentId, userId) && this.isEmpty(chat, userId)+ );return empty[0] ?? null;}@@ -55,3 +61,15 @@ export class EmptyChatFinder {);}}++/**+ * A Switch Console 1:1 between the viewer and this one agent: direct, unbridged,+ * that agent alone, and nobody else in it (where the server says who is).+ */+export function isOwnDirectChat(chat: ChatSummary, agentId: string, userId: string): boolean {+ return (+ isConsoleDirectChatSummary(chat) &&+ chat.agents[0]?.id === agentId &&+ chat.memberUserIds.every((member) => member === userId)+ );+}