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): create a group chat from New room
raullopez-sandbox794934675eb9
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 9a33865b3..a99e51f28 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@@ -1,6 +1,9 @@import { useQuery } from '@tanstack/react-query';+import { MessagesSquare } from 'lucide-react';import { observer } from 'mobx-react-lite';import { useCallback, useState } from 'react';+import { chatFailure } from '@renderer/features/chats/stores/chat-errors';+import { chatsStore } from '@renderer/features/chats/stores/chats';import { agentsStore } from '@renderer/features/locations/stores/agents-store';import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { openRoomView } from '@renderer/features/sidebar/sidebar-room-grouping';@@ -12,7 +15,7 @@ import {ChosenAgentTile,agentProviderLabelFor,} from '@renderer/lib/components/agent-picker';-import { BridgeTile, bridgeUnusableReason } from '@renderer/lib/components/bridge-tile';+import { BridgeTile, bridgeUnusableReason, ChoiceTile } from '@renderer/lib/components/bridge-tile';import { PickerCombobox } from '@renderer/lib/components/picker-combobox';import { failureText } from '@renderer/lib/errors/describe-failure';import { rpc } from '@renderer/lib/ipc';@@ -30,6 +33,7 @@ import { DisclosureRow } from '@renderer/lib/ui/disclosure-row';import { Input } from '@renderer/lib/ui/input';import { Textarea } from '@renderer/lib/ui/textarea';import type { RemoteAgentSummary } from '@shared/core/switch-servers/switch-servers';+import { canCreate, roomCreateRequest } from './room-create-request';import { switchServersStore } from './switch-servers-store';import { useMyIdentities } from './use-my-identities';@@ -59,6 +63,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({const [description, setDescription] = useState('');const [instructions, setInstructions] = useState('');const [instructionsOpen, setInstructionsOpen] = useState(false);+ /** The chosen messaging app; null is Switch Console, the default, which needs none. */const [bridgeId, setBridgeId] = useState<string | null>(null);const [agents, setAgents] = useState<RemoteAgentSummary[]>([]);const [isSubmitting, setIsSubmitting] = useState(false);@@ -116,40 +121,44 @@ export const CreateRoomModal = observer(function CreateRoomModal({const allBridges = bridgesQuery.data ?? [];const activeBridges = allBridges.filter((b) => b.status === 'active');const bridges = activeBridges.filter((b) => b.canCreateChannels);- const selectedBridge =- bridges.find((b) => b.id === bridgeId) ??- bridges.find((b) => b.isDefault) ??- bridges[0] ??- null;+ const selectedBridge = bridges.find((b) => b.id === bridgeId) ?? null;const loaded = !bridgesQuery.isLoading;const noBridgesAtAll = loaded && allBridges.length === 0;const noneRunning = loaded && allBridges.length > 0 && activeBridges.length === 0;const noneCanCreateChannels = loaded && activeBridges.length > 0 && bridges.length === 0;const trimmedName = name.trim();- const trimmedDescription = description.trim();const canSubmit =workspaceId !== null &&- !!trimmedName &&- !!trimmedDescription &&- !!selectedBridge &&+ canCreate({ bridgeId: selectedBridge?.id ?? null, name, description }) &&!isSubmitting;const handleSubmit = useCallback(async () => {- if (!canSubmit || !selectedBridge) return;+ if (!canSubmit) return;setIsSubmitting(true);setCloseGuard(true);setError(null);try {- const result = await rpc.workspaces.createRoom({+ const request = roomCreateRequest({+ serverId,workspaceId: workspaceId as string,- name: trimmedName,- description: trimmedDescription,- instructions: instructions.trim() || undefined,- bridgeId: selectedBridge.id,+ bridgeId: selectedBridge?.id ?? null,+ name,+ description,+ instructions,agentIds: agents.map((a) => a.id),+ requestId: crypto.randomUUID(),});+ if (request.kind === 'chat') {+ const chat = await rpc.chats.create(request.params);+ chatsStore.add(serverId, chat);+ sidebarStore.setGrouping('room');+ openRoomView(chat.roomId);+ onSuccess({ roomId: chat.roomId });+ return;+ }+ const result = await rpc.workspaces.createRoom(request.params);if (result.kind !== 'created') {setError(messageFor(result));@@ -174,7 +183,11 @@ export const CreateRoomModal = observer(function CreateRoomModal({onSuccess({ roomId: result.room.id });} catch (cause) {- setError(failureText(cause, 'Could not create the room.'));+ setError(+ selectedBridge+ ? failureText(cause, 'Could not create the room.')+ : chatFailure(cause).message+ );} finally {setIsSubmitting(false);setCloseGuard(false);@@ -182,9 +195,10 @@ export const CreateRoomModal = observer(function CreateRoomModal({}, [canSubmit,selectedBridge,+ serverId,workspaceId,- trimmedName,- trimmedDescription,+ name,+ description,instructions,agents,onSuccess,@@ -220,6 +234,17 @@ export const CreateRoomModal = observer(function CreateRoomModal({</span></div><div className="grid grid-cols-2 gap-2.5">+ <ChoiceTile+ icon={<MessagesSquare className="size-5 text-foreground-muted" />}+ title="Switch Console"+ disabled={false}+ selected={selectedBridge === null}+ onSelect={() => setBridgeId(null)}+ >+ <span className="truncate text-xs text-foreground-muted">+ Chat here, no messaging app+ </span>+ </ChoiceTile>{allBridges.map((bridge) => (<BridgeTilekey={bridge.id}@@ -233,19 +258,19 @@ export const CreateRoomModal = observer(function CreateRoomModal({))}</div>{noBridgesAtAll && (- <p className="text-xs text-destructive">- This server has no messaging app connected, so a room created here would be- unreachable. Connect one first.+ <p className="text-xs text-foreground-muted">+ This server has no messaging app connected, so a room here is a Switch Console chat.+ Connect one to bridge rooms to it.</p>)}{noneRunning && (- <p className="text-xs text-destructive">- This server's messaging apps are not running, so a room created here would be- unreachable. Start one, or connect another.+ <p className="text-xs text-foreground-muted">+ This server's messaging apps are not running, so a room here is a Switch+ Console chat. Start one, or connect another, to bridge rooms to it.</p>)}{noneCanCreateChannels && (- <p className="text-xs text-destructive">+ <p className="text-xs text-foreground-muted">None of the running messaging apps can create a channel from Switch. Make the chatdirectly in the messaging app instead and add the app's bot to it — it becomesa room here once it exists.@@ -280,17 +305,20 @@ export const CreateRoomModal = observer(function CreateRoomModal({)}</FormRow>- <FormRow label="Description">- <Input- placeholder="What this room is for"- value={description}- onChange={(e) => {- setDescription(e.target.value);- setError(null);- }}- onKeyDown={submitOnEnter}- />- </FormRow>+ {/* A chat has no description or instructions of its own to create with. */}+ {selectedBridge && (+ <FormRow label="Description">+ <Input+ placeholder="What this room is for"+ value={description}+ onChange={(e) => {+ setDescription(e.target.value);+ setError(null);+ }}+ onKeyDown={submitOnEnter}+ />+ </FormRow>+ )}</div><section className="flex flex-col gap-3">@@ -338,23 +366,25 @@ export const CreateRoomModal = observer(function CreateRoomModal({</span></section>- <div>- <DisclosureRow- open={instructionsOpen}- title="Instructions"- meta="shown to agents when they enter"- onToggle={() => setInstructionsOpen((v) => !v)}- />- {instructionsOpen && (- <Textarea- className="mt-3"- placeholder="Optional guidance shown to agents when they enter a room"- value={instructions}- onChange={(e) => setInstructions(e.target.value)}- rows={3}+ {selectedBridge && (+ <div>+ <DisclosureRow+ open={instructionsOpen}+ title="Instructions"+ meta="shown to agents when they enter"+ onToggle={() => setInstructionsOpen((v) => !v)}/>- )}- </div>+ {instructionsOpen && (+ <Textarea+ className="mt-3"+ placeholder="Optional guidance shown to agents when they enter a room"+ value={instructions}+ onChange={(e) => setInstructions(e.target.value)}+ rows={3}+ />+ )}+ </div>+ )}{error && <p className="text-xs text-destructive">{error}</p>}</div>diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.tsnew file mode 100644index 000000000..03a815987--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts@@ -0,0 +1,51 @@+import { describe, expect, it } from 'vitest';+import { canCreate, roomCreateRequest } from './room-create-request';++const form = {+ serverId: 's',+ workspaceId: 'w',+ name: ' Ship review ',+ description: ' Reviews ',+ instructions: '',+ agentIds: ['a1', 'a2'],+ requestId: 'req',+};++describe('roomCreateRequest', () => {+ it('creates a Switch Console chat when no messaging app is chosen', () => {+ expect(roomCreateRequest({ ...form, bridgeId: null })).toEqual({+ kind: 'chat',+ params: {+ serverId: 's',+ name: 'Ship review',+ agentIds: ['a1', 'a2'],+ memberUserIds: [],+ requestId: 'req',+ greeting: null,+ },+ });+ });++ it('creates a bridged room as before when an app is chosen', () => {+ expect(roomCreateRequest({ ...form, bridgeId: 'b1', agentIds: [] })).toEqual({+ kind: 'room',+ params: {+ workspaceId: 'w',+ name: 'Ship review',+ description: 'Reviews',+ instructions: undefined,+ bridgeId: 'b1',+ agentIds: [],+ },+ });+ });+});++describe('canCreate', () => {+ it('asks a chat only for a name, a bridged room for a description too', () => {+ expect(canCreate({ bridgeId: null, name: 'x', description: '' })).toBe(true);+ expect(canCreate({ bridgeId: 'b1', name: 'x', description: '' })).toBe(false);+ expect(canCreate({ bridgeId: 'b1', name: 'x', description: 'd' })).toBe(true);+ expect(canCreate({ bridgeId: null, name: ' ', description: 'd' })).toBe(false);+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.tsnew file mode 100644index 000000000..c8467dd66--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts@@ -0,0 +1,66 @@+/** What the New room dialog asks the server for: a Switch Console chat when no messaging app is chosen, else a room bridged to the chosen one. */+export type RoomCreateRequest =+ | {+ kind: 'chat';+ params: {+ serverId: string;+ name: string;+ agentIds: string[];+ memberUserIds: string[];+ requestId: string;+ greeting: null;+ };+ }+ | {+ kind: 'room';+ params: {+ workspaceId: string;+ name: string;+ description: string;+ instructions: string | undefined;+ bridgeId: string;+ agentIds: string[];+ };+ };++export function roomCreateRequest(form: {+ serverId: string;+ workspaceId: string;+ /** Null for Switch Console. */+ bridgeId: string | null;+ name: string;+ description: string;+ instructions: string;+ agentIds: string[];+ requestId: string;+}): RoomCreateRequest {+ const name = form.name.trim();+ if (form.bridgeId === null)+ return {+ kind: 'chat',+ params: {+ serverId: form.serverId,+ name,+ agentIds: form.agentIds,+ memberUserIds: [],+ requestId: form.requestId,+ greeting: null,+ },+ };+ return {+ kind: 'room',+ params: {+ workspaceId: form.workspaceId,+ name,+ description: form.description.trim(),+ instructions: form.instructions.trim() || undefined,+ bridgeId: form.bridgeId,+ agentIds: form.agentIds,+ },+ };+}++/** A chat needs only a name; a bridged room also needs a description. */+export function canCreate(form: { bridgeId: string | null; name: string; description: string }) {+ return form.name.trim() !== '' && (form.bridgeId === null || form.description.trim() !== '');+}diff --git a/console/apps/switch-console-desktop/src/renderer/lib/components/bridge-tile.tsx b/console/apps/switch-console-desktop/src/renderer/lib/components/bridge-tile.tsxindex cb662c9cc..cd6fa0396 100644--- a/console/apps/switch-console-desktop/src/renderer/lib/components/bridge-tile.tsx+++ b/console/apps/switch-console-desktop/src/renderer/lib/components/bridge-tile.tsx@@ -54,11 +54,57 @@ export function BridgeTile({unusable: string | null;selected: boolean;onSelect: () => void;+}) {+ return (+ <ChoiceTile+ icon={+ hasBridgeIcon(bridge.type) ? (+ <BridgeIcon bridgeType={bridge.type} size={20} />+ ) : (+ <MessageSquare className="size-5 text-foreground-muted" />+ )+ }+ title={bridge.displayName}+ disabled={unusable !== null}+ selected={selected}+ onSelect={onSelect}+ >+ {/* Three different things, never conflated: why this app cannot be+ used, which account on it is you, or that Switch cannot tell. */}+ {unusable !== null ? (+ <span className="truncate text-xs text-foreground-muted">{unusable}</span>+ ) : !identitiesKnown ? null : identity === null ? (+ <span className="truncate text-xs text-amber-600 dark:text-amber-500">+ No account linked+ </span>+ ) : (+ <span className="truncate text-xs text-foreground-muted">{handleOf(identity)}</span>+ )}+ </ChoiceTile>+ );+}++/** A selectable tile in a grid of choices: an icon, a title and a line under it. */+export function ChoiceTile({+ icon,+ title,+ disabled,+ selected,+ onSelect,+ children,+}: {+ icon: React.ReactNode;+ title: string;+ disabled: boolean;+ selected: boolean;+ onSelect: () => void;+ /** The line under the title. */+ children: React.ReactNode;}) {return (<buttontype="button"- disabled={unusable !== null}+ disabled={disabled}aria-pressed={selected}onClick={onSelect}className={cn(@@ -67,29 +113,13 @@ export function BridgeTile({// exactly the dialog's own surface: the hover was being drawn, in the// colour of the thing behind it.selected ? 'border-foreground bg-[var(--sel)]' : 'border-border hover:bg-[var(--sel-soft)]',- unusable !== null && 'cursor-not-allowed opacity-50 hover:bg-transparent'+ disabled && 'cursor-not-allowed opacity-50 hover:bg-transparent')}>- <span className="flex size-6 shrink-0 items-center justify-center">- {hasBridgeIcon(bridge.type) ? (- <BridgeIcon bridgeType={bridge.type} size={20} />- ) : (- <MessageSquare className="size-5 text-foreground-muted" />- )}- </span>+ <span className="flex size-6 shrink-0 items-center justify-center">{icon}</span><span className="flex min-w-0 flex-col">- <span className="truncate text-sm text-foreground">{bridge.displayName}</span>- {/* Three different things, never conflated: why this app cannot be- used, which account on it is you, or that Switch cannot tell. */}- {unusable !== null ? (- <span className="truncate text-xs text-foreground-muted">{unusable}</span>- ) : !identitiesKnown ? null : identity === null ? (- <span className="truncate text-xs text-amber-600 dark:text-amber-500">- No account linked- </span>- ) : (- <span className="truncate text-xs text-foreground-muted">{handleOf(identity)}</span>- )}+ <span className="truncate text-sm text-foreground">{title}</span>+ {children}</span></button>);