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): group chats only where the server offers them
raullopez-sandbox2f455d430c33
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsxindex 9607bcac7..f18e7d490 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx@@ -4,6 +4,7 @@ import { type KeyboardEvent as ReactKeyboardEvent, useEffect, useRef, useState }import { reportBuddyMessage } from '@renderer/features/switch-buddy/buddy-telemetry';import { AgentAvatar } from '@renderer/lib/components/agent-avatar';import { isEditableTarget } from '@renderer/lib/hooks/use-arrow-key-navigation';+import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';import { modalStore } from '@renderer/lib/modal/modal-store';import { Button } from '@renderer/lib/ui/button';import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '@renderer/lib/ui/popover';@@ -25,6 +26,7 @@ import {type MentionToken,mentionUserIds,type RememberedMention,+ withoutGroupMentions,personTargets,shiftMentions,tokenToRemove,@@ -216,16 +218,22 @@ export const ChatComposer = observer(function ChatComposer({/** Where the `@` of a suggestion list Esc closed sits, so it stays closed for that `@`. */const [dismissedAt, setDismissedAt] = useState<number | null>(null);// Text typed rather than picked reads as an agent first where a person shares its name.- const targets = [...agentTargets(agents), ...personTargets(people)];- const tokens = composeMentions(draft, picked, targets);- const mentionable = agents.length > 0 || people.length > 0;+ // A server without group chats takes one agent mention and no people.+ const groupChats = useFeatureFlags(serverId).group_chats;+ const mentionPeople = groupChats ? people : [];+ const targets = [...agentTargets(agents), ...personTargets(mentionPeople)];+ const allowed = (found: MentionToken[]) => (groupChats ? found : withoutGroupMentions(found));+ const tokens = allowed(composeMentions(draft, picked, targets));+ const agentNamed = tokens.some((token) => token.kind === 'agent');+ const mentionable =+ (agents.length > 0 && (groupChats || !agentNamed)) || mentionPeople.length > 0;const query = mentionable ? mentionQuery(draft, caret) : null;const suggestions: Suggestion[] = query? [...filterMentionAgents(agents, query.query).map((agent): Suggestion => ({ kind: 'agent', id: agent.id, agent })),- ...filterMentionPeople(people, query.query).map(+ ...filterMentionPeople(mentionPeople, query.query).map((person): Suggestion => ({ kind: 'person', id: `user:${person.userId}`, person })),]@@ -333,7 +341,7 @@ export const ChatComposer = observer(function ChatComposer({timeline.messages.filter((message) => message.sender.kind === 'human').length +timeline.pending.length);- const sent = composeMentions(body, shiftMentions(draft, body, picked), targets);+ const sent = allowed(composeMentions(body, shiftMentions(draft, body, picked), targets));timeline.send({body,threadRootId: replyTo?.messageId ?? null,diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/mentions.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/mentions.tsindex a3c6f355d..d1fe76351 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/mentions.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/mentions.ts@@ -243,3 +243,9 @@ export function tokensFromSpans(body: string, spans: ChatMentionSpan[]): Mention).sort((a, b) => a.start - b.start);}++/** Without group chats a message may name one agent and no people: the first agent mention, nothing else. */+export function withoutGroupMentions(tokens: MentionToken[]): MentionToken[] {+ const first = tokens.find((token) => token.kind === 'agent');+ return first ? [first] : [];+}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 0f1c8617a..a7991ba32 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@@ -21,6 +21,7 @@ import {personParticipant,} from '@renderer/lib/components/participant-search';import { describeFailure, failureText } from '@renderer/lib/errors/describe-failure';+import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';import { rpc } from '@renderer/lib/ipc';import { useNavigate } from '@renderer/lib/layout/navigation-provider';import { useShowModal } from '@renderer/lib/modal/modal-provider';@@ -140,6 +141,9 @@ const ChatParticipantsSection = observer(function ChatParticipantsSection({const queryClient = useQueryClient();const roomId = chat.roomId;const membersKey = chatMembersQueryKey(serverId, chat);+ // Adding to a chat makes it a group, which the server offers only with its group_chats flag.+ const groupChats = useFeatureFlags(serverId).group_chats;+ const canAdd = chat.canManage && groupChats;const members = useQuery({queryKey: membersKey,queryFn: () => rpc.chats.members(serverId, roomId),@@ -189,7 +193,7 @@ const ChatParticipantsSection = observer(function ChatParticipantsSection({{membershipSummary(agentIds.length, people.length)}</span></div>- {chat.canManage && (+ {canAdd && (<Buttonvariant="outline"size="sm"@@ -203,7 +207,7 @@ const ChatParticipantsSection = observer(function ChatParticipantsSection({)}</div>- {chat.canManage && (+ {canAdd && (<ChatAddParticipantPanelserverId={serverId}workspaceId={workspaceId}diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsxindex f893c8e5c..5f71bf246 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx@@ -18,6 +18,7 @@ import {personParticipant,} from '@renderer/lib/components/participant-search';import { failureText } from '@renderer/lib/errors/describe-failure';+import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';import { rpc } from '@renderer/lib/ipc';import { type BaseModalProps, useModalContext } from '@renderer/lib/modal/modal-provider';import { sidebarStore } from '@renderer/lib/stores/app-state';@@ -103,7 +104,11 @@ export const CreateRoomModal = observer(function CreateRoomModal({const bridges = (bridgesQuery.data ?? []).filter((b) => b.status === 'active' && b.canCreateChannels);- const selectedBridge = bridges.find((b) => b.id === where) ?? null;+ // Without the server's group_chats flag there are no Switch Console rooms: a room is a bridged one.+ const consoleOffered = useFeatureFlags(serverId || null).group_chats;+ const selectedBridge =+ bridges.find((b) => b.id === where) ?? (consoleOffered ? null : (bridges[0] ?? null));+ const nowhere = !consoleOffered && selectedBridge === null && !bridgesQuery.isLoading;const managedProviders = new Map((managedQuery.data ?? []).map((managed) => [managed.agentId, managed.definition.provider])@@ -140,6 +145,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({const trimmedName = name.trim();const canSubmit =workspaceId !== null &&+ !nowhere &&canCreate({ bridgeId: selectedBridge?.id ?? null, name, description }) &&!isSubmitting;@@ -297,6 +303,12 @@ export const CreateRoomModal = observer(function CreateRoomModal({</section>)}+ {nowhere && (+ <p className="text-xs text-destructive">+ This server does not offer Switch Console rooms yet, and none of its messaging apps+ can create a channel, so there is nowhere to create a room.+ </p>+ )}{bridgesQuery.isError && (<p className="text-xs text-destructive">{failureText(bridgesQuery.error, 'Could not load messaging apps.')}@@ -308,6 +320,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({<DialogFooter className="sm:justify-between"><MessagingAppSelectorbridges={bridges}+ consoleOffered={consoleOffered}value={where}onChange={(next) => {setWhere(next);diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.tsindex 4bfb3c4ef..e8bcd3976 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts@@ -4,6 +4,8 @@ import { renderToStaticMarkup } from 'react-dom/server';import { describe, expect, it, vi } from 'vitest';import { CreateRoomModal } from './CreateRoomModal';+const flags = vi.hoisted(() => ({ group_chats: true }));+vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({ useFeatureFlags: () => flags }));vi.mock('@renderer/lib/ipc', () => ({ events: { on: vi.fn() }, rpc: {} }));vi.mock('@renderer/features/chats/stores/chats', () => ({ chatsStore: {} }));vi.mock('@renderer/lib/modal/modal-provider', () => ({@@ -34,5 +36,22 @@ describe('CreateRoomModal', () => {expect(html).toContain('placeholder="Name this room"');expect(html).toMatch(/<label[^>]*for="new-room-participants"[^>]*>Participants<\/label>/);expect(html).not.toContain('uppercase');+ expect(html).not.toContain('does not offer Switch Console rooms');+ });++ it('says there is nowhere to create a room without group chats or a messaging app', () => {+ flags.group_chats = false;+ try {+ const html = renderToStaticMarkup(+ createElement(+ QueryClientProvider,+ { client: new QueryClient() },+ createElement(CreateRoomModal, { onSuccess: () => {}, onClose: () => {} })+ )+ );+ expect(html).toContain('does not offer Switch Console rooms');+ } finally {+ flags.group_chats = true;+ }});});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/messaging-app-selector.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/messaging-app-selector.tsxindex 814f35291..d58d8ba42 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/messaging-app-selector.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/messaging-app-selector.tsx@@ -41,15 +41,20 @@ function OptionIcon({ type }: { type: string | null }) {*/export function MessagingAppSelector({bridges,+ consoleOffered,value,onChange,}: {/** The apps a room can be created on: running, and allowed to create channels. */bridges: readonly RemoteBridge[];+ /** Whether the server offers Switch Console rooms (its `group_chats` flag). */+ consoleOffered: boolean;value: string;onChange: (value: string) => void;}) {- const options = messagingOptions(bridges);+ const options = messagingOptions(bridges).filter(+ (option) => consoleOffered || option.value !== SWITCH_CONSOLE+ );if (options.length < 2) return null;const selected = options.find((option) => option.value === value) ?? options[0];return (diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/new-room-dialog.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/new-room-dialog.test.tsindex c1d42d13a..d0ff739a1 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/new-room-dialog.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/new-room-dialog.test.ts@@ -40,6 +40,7 @@ describe('MessagingAppSelector', () => {it('is hidden when Switch Console is the only choice', () => {const html = renderToStaticMarkup(createElement(MessagingAppSelector, {+ consoleOffered: true,bridges: [],value: SWITCH_CONSOLE,onChange: () => {},@@ -51,6 +52,7 @@ describe('MessagingAppSelector', () => {it('shows the chosen app with its icon, and lists Switch Console and each app', () => {const html = renderToStaticMarkup(createElement(MessagingAppSelector, {+ consoleOffered: true,bridges: [slack],value: 'b-slack',onChange: () => {},@@ -61,6 +63,7 @@ describe('MessagingAppSelector', () => {expect(renderToStaticMarkup(createElement(MessagingAppSelector, {+ consoleOffered: true,bridges: [slack],value: SWITCH_CONSOLE,onChange: () => {},@@ -74,6 +77,32 @@ describe('MessagingAppSelector', () => {});});+describe('MessagingAppSelector without Switch Console rooms', () => {+ const discord = { ...slack, id: 'b-discord', type: 'discord', displayName: 'Acme Discord' };++ it('offers only the apps, and hides with one', () => {+ const one = renderToStaticMarkup(+ createElement(MessagingAppSelector, {+ consoleOffered: false,+ bridges: [slack],+ value: 'b-slack',+ onChange: () => {},+ })+ );+ expect(one).toBe('');+ const two = renderToStaticMarkup(+ createElement(MessagingAppSelector, {+ consoleOffered: false,+ bridges: [slack, discord],+ value: SWITCH_CONSOLE,+ onChange: () => {},+ })+ );+ expect(two).toContain('Acme Slack');+ expect(two).not.toContain('Switch Console');+ });+});+describe('ParticipantPicker', () => {it('shows the picked agents and people as removable chips inside the field', () => {const html = renderToStaticMarkup(diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsxindex f771e3733..bd8406159 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx@@ -16,6 +16,9 @@ import {} from '@renderer/features/chats/stores/chat-timeline-store';import { PromptInput, PromptInputTextarea } from '@renderer/features/chats/ui/prompt-input';+const flags = vi.hoisted(() => ({ group_chats: true }));+vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({ useFeatureFlags: () => flags }));+let container: HTMLDivElement | null = null;let root: Root | null = null;@@ -152,3 +155,44 @@ describe('ChatComposer picked mentions', () => {expect(kinds()).toEqual(['person']);});});++describe('ChatComposer on a server without group chats', () => {+ it('offers no people and badges only the first agent mention', async () => {+ flags.group_chats = false;+ try {+ const one = { ...agent, id: 'a1', name: 'agent-one' };+ const textarea = await render(+ <ChatComposer+ serverId="s"+ timeline={new ChatTimeline('room-flag', {} as TimelineApi)}+ agents={[one, agent]}+ people={[{ userId: 'u1', name: 'Bob Member', email: null }]}+ groupName="Ship review"+ activity={null}+ replyTo={null}+ onClearReply={() => {}}+ disabled={null}+ />+ );+ await act(async () => {+ textarea.focus();+ document.execCommand('insertText', false, '@bo');+ });+ expect(container!.querySelector('[role="listbox"]')).toBeNull();+ await act(async () => {+ textarea.setSelectionRange(0, textarea.value.length);+ document.execCommand('insertText', false, '@agent-one and @agent-two ');+ });+ expect(+ [...container!.querySelectorAll('mark[data-mention]')].map((mark) => mark.textContent)+ ).toEqual(['@agent-one']);+ await act(async () => {+ document.execCommand('insertText', false, '@ag');+ });+ // One agent is named already: the list does not offer another.+ expect(container!.querySelector('[role="listbox"]')).toBeNull();+ } finally {+ flags.group_chats = true;+ }+ });+});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 19a042635..14817746c 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@@ -25,6 +25,8 @@ vi.mock('@renderer/features/chats/stores/chats', () => ({}));const showModal = vi.hoisted(() => vi.fn());+const flags = vi.hoisted(() => ({ group_chats: true }));+vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({ useFeatureFlags: () => flags }));vi.mock('@renderer/lib/modal/modal-provider', () => ({ useShowModal: () => showModal }));const agent = {@@ -92,6 +94,18 @@ describe('RoomConfigurationPanel for a group chat', () => {expect(html).toMatch(/<button[^>]* disabled=""[^>]*><span[^>]*>Add<span data-slot="shortcut"/);});+ it('offers no adding to a manager while the server does not offer group chats', () => {+ flags.group_chats = false;+ try {+ const html = render(true);+ expect(html).not.toContain('Add participants');+ expect(html).not.toContain('id="chat-add-participant"');+ expect(html).toContain('aria-label="Remove Bob"');+ } finally {+ flags.group_chats = true;+ }+ });+it('shows the participants without controls to someone who cannot manage', () => {const html = render(false);expect(html).toContain('Bob');diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-mentions.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-mentions.test.tsindex a1693ed4c..1c8f69958 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-mentions.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-mentions.test.ts@@ -5,6 +5,7 @@ import {editMentions,mentionSpans,tokensFromSpans,+ withoutGroupMentions,shiftMentions,filterMentionAgents,filterMentionPeople,@@ -201,3 +202,15 @@ describe('mention spans', () => {);});});++describe('withoutGroupMentions', () => {+ it('keeps the first agent mention only', () => {+ expect(+ withoutGroupMentions([+ { kind: 'person', id: 'u1', start: 0, end: 4 },+ { kind: 'agent', id: 'a1', start: 5, end: 9 },+ { kind: 'agent', id: 'a2', start: 10, end: 14 },+ ])+ ).toEqual([{ kind: 'agent', id: 'a1', start: 5, end: 9 }]);+ });+});diff --git a/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.ts b/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.tsindex b8d407b8b..18ef386f8 100644--- a/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.ts+++ b/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.ts@@ -17,6 +17,7 @@ export const CONSOLE_FEATURE_FLAGS = ['service_connections','agent_chats','switch_buddy',+ 'group_chats',] as const;export type FeatureFlagKey = (typeof CONSOLE_FEATURE_FLAGS)[number];