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): New room asks for a name and who is in it, in one field

raullopez-sandboxd7f3f7fb7d85
diff --git a/console/apps/switch-console-desktop/src/main/core/chats/controller.ts b/console/apps/switch-console-desktop/src/main/core/chats/controller.ts
index 415d11d8d..b521ac86b 100644
--- a/console/apps/switch-console-desktop/src/main/core/chats/controller.ts
+++ b/console/apps/switch-console-desktop/src/main/core/chats/controller.ts
@@ -161,10 +161,12 @@ export const chatsController = createRPCController({
name: string | null;
requestId: string;
greeting: string | null;
+ kind?: 'group';
}): Promise<ChatSummary> => {
const chat = await onServer(params.serverId, (server) => createChat(server, params));
const agentIds = params.agentIds ?? [];
- if (agentIds.length === 1)
+ // A group's agent answers only when mentioned, so there is no first turn to get ready for.
+ if (agentIds.length === 1 && params.kind !== 'group')
void warmChat(
{ serverId: params.serverId, agentId: agentIds[0], roomId: chat.roomId },
false
diff --git a/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts b/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts
index 2936eb880..cd20be15f 100644
--- a/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/chats/gateway.test.ts
@@ -107,6 +107,32 @@ describe('createChat', () => {
body: { requestId: 'req-1', agentId: 'agent-1' },
});
});
+
+ it('asks for a group of one agent when kind is group', async () => {
+ const server = { id: 'server-1' } as SwitchServer;
+ vi.mocked(gatewayFetch).mockResolvedValueOnce(
+ new Response(JSON.stringify({ chat: row('room-new', 'channel_private') }), { status: 200 })
+ );
+ await createChat(server, {
+ agentIds: ['agent-1'],
+ memberUserIds: [],
+ name: 'Solo',
+ requestId: 'req-1',
+ greeting: null,
+ kind: 'group',
+ });
+ expect(gatewayFetch).toHaveBeenCalledWith(server, '/chats', {
+ authenticated: true,
+ method: 'POST',
+ body: {
+ requestId: 'req-1',
+ agentId: 'agent-1',
+ memberUserIds: [],
+ name: 'Solo',
+ kind: 'group',
+ },
+ });
+ });
});
describe('addChatAgent', () => {
diff --git a/console/apps/switch-console-desktop/src/main/core/chats/gateway.ts b/console/apps/switch-console-desktop/src/main/core/chats/gateway.ts
index a33e42584..1eb039da2 100644
--- a/console/apps/switch-console-desktop/src/main/core/chats/gateway.ts
+++ b/console/apps/switch-console-desktop/src/main/core/chats/gateway.ts
@@ -121,6 +121,8 @@ export async function createChat(
name: string | null;
requestId: string;
greeting: string | null;
+ /** `group` makes a group even of one agent and nobody else. */
+ kind?: 'group';
}
): Promise<ChatSummary> {
const agentIds = input.agentIds ?? [];
@@ -132,6 +134,7 @@ export async function createChat(
if (input.memberUserIds) body.memberUserIds = input.memberUserIds;
if (input.name) body.name = input.name;
if (input.greeting !== null) body.greeting = input.greeting;
+ if (input.kind) body.kind = input.kind;
return (await json(server, '/chats', chatCreatedSchema, { method: 'POST', body })).chat;
}
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.tsx
index 0e5ad4008..a46da55f7 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
@@ -29,7 +29,10 @@ import { Textarea } from '@renderer/lib/ui/textarea';
import { cn } from '@renderer/utils/utils';
import { agentInitials } from '@shared/core/agents/agent-avatar';
import { type ChatSummary, chatAgentLabel } from '@shared/core/chats/chats';
-import { providerDisplayName } from '@shared/core/providers/agent-provider-registry';
+import {
+ knownAgentTypeDisplayName,
+ providerDisplayName,
+} from '@shared/core/providers/agent-provider-registry';
import { runsOnThisComputer } from '@shared/core/switch-servers/switch-servers';
import type {
RemoteAgentSummary,
@@ -37,7 +40,7 @@ import type {
} from '@shared/core/switch-servers/switch-servers';
import { administersWorkspace } from '@shared/core/workspaces/workspaces';
import { channelOnDeleteSummary } from './room-delete-wording';
-import { addablePeople, membershipSummary, roomTitle } from './room-labels';
+import { addableAgents, addablePeople, membershipSummary, roomTitle } from './room-labels';
import { openRoomChannel } from './room-links';
/** Query key for one room's own settings — shared so a save can write the
@@ -237,7 +240,6 @@ const ChatAddAgentPanel = observer(function ChatAddAgentPanel({
chat: ChatSummary;
}) {
const agents = useWorkspaceAgents(workspaceId);
- const inChat = new Set(chat.agents.map((agent) => agent.id));
return (
<AddParticipantPanel
noun="agent"
@@ -246,16 +248,14 @@ const ChatAddAgentPanel = observer(function ChatAddAgentPanel({
allInText="Every agent in this workspace is already in this chat."
loading={agents.isPending}
loadError={agents.isError ? failureText(agents.error, 'Could not list the agents.') : null}
- candidates={(agents.data ?? [])
- .filter((agent) => !inChat.has(agent.id))
- .map((agent) => ({
- id: agent.id,
- name: agent.displayName ?? agent.name,
- mark: (
- <AgentAvatar name={agent.name} iconUrl={agent.iconUrl} serverId={serverId} size={22} />
- ),
- detail: providerDisplayName(agent.knownAgentType) ?? 'Agent',
- }))}
+ candidates={addableAgents(agents.data ?? [], chat.agents).map((agent) => ({
+ id: agent.id,
+ name: agent.displayName ?? agent.name,
+ mark: (
+ <AgentAvatar name={agent.name} iconUrl={agent.iconUrl} serverId={serverId} size={22} />
+ ),
+ detail: knownAgentTypeDisplayName(agent.knownAgentType) ?? 'Agent',
+ }))}
onAdd={async (agentId) => {
try {
chatsStore.add(
@@ -1072,5 +1072,5 @@ function agentKindFor(
): string {
const providerId = localAgentFor(switchAgentId, workspaceId)?.providerId ?? null;
const knownType = remoteById.get(switchAgentId)?.knownAgentType ?? null;
- return providerDisplayName(providerId) ?? providerDisplayName(knownType) ?? 'agent';
+ return providerDisplayName(providerId) ?? knownAgentTypeDisplayName(knownType) ?? 'agent';
}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.test.ts
index 416571840..fbde1b86e 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { addablePeople, membershipSummary, roomTitle } from './room-labels';
+import { addableAgents, addablePeople, membershipSummary, roomTitle } from './room-labels';
describe('roomTitle', () => {
it('marks a bridged room as the channel it is', () => {
@@ -40,3 +40,9 @@ describe('addablePeople', () => {
expect(addablePeople(roster, new Set(['u3'])).map((person) => person.userId)).toEqual(['u2']);
});
});
+
+describe('addableAgents', () => {
+ it('offers only the agents not in the chat yet', () => {
+ expect(addableAgents([{ id: 'a1' }, { id: 'a2' }], [{ id: 'a1' }])).toEqual([{ id: 'a2' }]);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.ts
index 7b0b6ef48..3f63ab6bc 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-labels.ts
@@ -35,3 +35,12 @@ export function addablePeople<T extends { userId: string; serviceAccount: boolea
): T[] {
return roster.filter((person) => !person.serviceAccount && !memberIds.has(person.userId));
}
+
+/** The agents not in the chat yet: one already in is not offered again. */
+export function addableAgents<T extends { id: string }>(
+ agents: T[],
+ inChat: { id: string }[]
+): T[] {
+ const ids = new Set(inChat.map((agent) => agent.id));
+ return agents.filter((agent) => !ids.has(agent.id));
+}
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.tsx
index 60fced13b..5d51a1e6a 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,22 +1,16 @@
import { useQuery } from '@tanstack/react-query';
-import { MessagesSquare } from 'lucide-react';
import { observer } from 'mobx-react-lite';
-import { useCallback, useState } from 'react';
+import { 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';
import { refreshSidebarRoomState } from '@renderer/features/sidebar/sidebar-tree-data';
+import { addablePeople } from '@renderer/features/switch-rooms/room-labels';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { agentProviderLabel } from '@renderer/lib/components/agent-mark';
-import {
- AgentPickerRow,
- ChosenAgentTile,
- agentProviderLabelFor,
-} from '@renderer/lib/components/agent-picker';
-import { BridgeTile, bridgeUnusableReason, ChoiceTile } from '@renderer/lib/components/bridge-tile';
-import { PickerCombobox } from '@renderer/lib/components/picker-combobox';
+import { agentProviderLabelFor } from '@renderer/lib/components/agent-picker';
import { failureText } from '@renderer/lib/errors/describe-failure';
import { rpc } from '@renderer/lib/ipc';
import { type BaseModalProps, useModalContext } from '@renderer/lib/modal/modal-provider';
@@ -29,13 +23,14 @@ import {
DialogHeader,
DialogTitle,
} from '@renderer/lib/ui/dialog';
-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 { knownAgentTypeDisplayName } from '@shared/core/providers/agent-provider-registry';
+import { MessagingAppSelector, SWITCH_CONSOLE } from './messaging-app-selector';
+import { ParticipantPicker } from './participant-picker';
+import type { Participant } from './participant-search';
import { CreateRequestIds, canCreate, roomCreateRequest } from './room-create-request';
import { switchServersStore } from './switch-servers-store';
-import { useMyIdentities } from './use-my-identities';
type CreateRoomModalArgs = {
/** Create on this server instead of the active one — for callers that are not
@@ -45,6 +40,11 @@ type CreateRoomModalArgs = {
type Props = BaseModalProps<{ roomId: string }> & CreateRoomModalArgs;
+/**
+ * A new room: its name, then who is in it — agents and people found in one
+ * field — and, when the server has a messaging app that can make channels,
+ * where it lives. Switch Console is the default and needs no app.
+ */
export const CreateRoomModal = observer(function CreateRoomModal({
serverId: overrideServerId,
onSuccess,
@@ -57,15 +57,15 @@ export const CreateRoomModal = observer(function CreateRoomModal({
// looking, and then wonder where it went.
const serverId = overrideServerId ?? switchServersStore.activeServerId ?? '';
const workspaceId = workspacesStore.idOnServerInScope(serverId || null);
+ const workspace = workspacesStore.workspaces.find((each) => each.id === workspaceId) ?? null;
const server = switchServersStore.servers.find((s) => s.id === serverId) ?? null;
+ const myUserId = switchServersStore.statusFor(serverId)?.user?.id ?? null;
const [name, setName] = useState('');
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 [where, setWhere] = useState(SWITCH_CONSOLE);
+ const [picked, setPicked] = useState<Participant[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const [requestIds] = useState(() => new CreateRequestIds(() => crypto.randomUUID()));
@@ -80,57 +80,61 @@ export const CreateRoomModal = observer(function CreateRoomModal({
queryFn: () => rpc.workspaces.listAgents(workspaceId as string),
enabled: workspaceId !== null,
});
- // Which account on each app is the person creating the room. A room on an app
- // they have not claimed an account on works, but their own messages in it are
- // from a stranger as far as the agents are concerned — so it is said here,
- // while the app is being chosen, rather than discovered later.
- const { identities } = useMyIdentities(workspaceId);
+ const tenantId = workspace?.tenantId ?? null;
+ const rosterQuery = useQuery({
+ queryKey: ['workspace-members', serverId, tenantId],
+ queryFn: () => rpc.chats.workspaceMembers({ serverId, tenantId: tenantId as string }),
+ enabled: tenantId !== null,
+ });
const managedQuery = useManagedAgents(serverId || null);
- /**
- * Only agents this install registered on the server, and the user's managed
- * agents, which Console drives through the server wherever they run.
- *
- * The server answers with everyone registered on it, including agents
- * belonging to somebody else's Switch Console. Those cannot be shown under a
- * room here or driven from here, so offering them in the picker promises
- * something this app cannot deliver — the same rule the room views already
- * follow.
- */
+ // Only a running bridge allowed to create channels can back a new room.
+ const bridges = (bridgesQuery.data ?? []).filter(
+ (b) => b.status === 'active' && b.canCreateChannels
+ );
+ const selectedBridge = bridges.find((b) => b.id === where) ?? null;
+
const managedProviders = new Map(
(managedQuery.data ?? []).map((managed) => [managed.agentId, managed.definition.provider])
);
- const providerLabel = (agentId: string) =>
+ const providerLabel = (agentId: string, knownType: string | null) =>
managedProviders.has(agentId)
? agentProviderLabel(managedProviders.get(agentId))
- : agentProviderLabelFor(agentId, workspaceId);
- const invitableAgents = (agentsQuery.data ?? []).filter((remote) =>
- workspaceId === null
- ? false
- : managedProviders.has(remote.id) ||
- agentsStore
- .agentsInWorkspace(workspaceId)
- .some((local) => local.switchAgentId === remote.id)
+ : (knownAgentTypeDisplayName(knownType) ?? agentProviderLabelFor(agentId, workspaceId));
+ // A bridged room is driven from this install, so it takes only the agents
+ // this install registered or manages, and no people at creation. A Switch
+ // Console room is driven through the server: any agent the workspace shows,
+ // the server refusing one the person may not use, and its people.
+ const agentCandidates = (agentsQuery.data ?? []).filter(
+ (remote) =>
+ !selectedBridge ||
+ (workspaceId !== null &&
+ (managedProviders.has(remote.id) ||
+ agentsStore
+ .agentsInWorkspace(workspaceId)
+ .some((local) => local.switchAgentId === remote.id)))
);
-
- // Only a running bridge can back a new room, and creating a room here means
- // creating a channel on it — a bridge withheld from that (an operator's
- // switch, or a platform like Telegram that has no such call at all) is just
- // as unusable for this form. Every connected app is shown, but an unusable
- // one is not selectable and says which of these it is: an app that is simply
- // absent from the grid explains nothing, and the user goes looking for it.
- 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) ?? 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;
-
- // A chat is driven through the server, not this install, so any agent in the
- // workspace may be offered; the server refuses one the person may not use.
- const pickableAgents = selectedBridge ? invitableAgents : (agentsQuery.data ?? []);
+ const candidates: Participant[] = [
+ ...agentCandidates.map(
+ (agent): Participant => ({
+ kind: 'agent',
+ id: agent.id,
+ name: agent.displayName ?? agent.name,
+ iconUrl: agent.iconUrl,
+ detail: `Agent · ${providerLabel(agent.id, agent.knownAgentType)}`,
+ })
+ ),
+ ...addablePeople(selectedBridge ? [] : (rosterQuery.data ?? []), new Set([myUserId ?? ''])).map(
+ (person): Participant => ({
+ kind: 'person',
+ id: person.userId,
+ name: person.name,
+ detail: person.email ?? '',
+ })
+ ),
+ ];
+ const agentIds = picked.filter((each) => each.kind === 'agent').map((each) => each.id);
+ const memberUserIds = picked.filter((each) => each.kind === 'person').map((each) => each.id);
const trimmedName = name.trim();
const canSubmit =
@@ -138,26 +142,24 @@ export const CreateRoomModal = observer(function CreateRoomModal({
canCreate({ bridgeId: selectedBridge?.id ?? null, name, description }) &&
!isSubmitting;
- const handleSubmit = useCallback(async () => {
+ async function handleSubmit() {
if (!canSubmit) return;
setIsSubmitting(true);
setCloseGuard(true);
setError(null);
try {
+ const bridgeId = selectedBridge?.id ?? null;
const request = roomCreateRequest({
serverId,
workspaceId: workspaceId as string,
- bridgeId: selectedBridge?.id ?? null,
+ bridgeId,
name,
description,
instructions,
- agentIds: agents.map((a) => a.id),
- requestId: requestIds.for({
- bridgeId: selectedBridge?.id ?? null,
- name,
- agentIds: agents.map((a) => a.id),
- }),
+ agentIds,
+ memberUserIds,
+ requestId: requestIds.for({ bridgeId, name, agentIds, memberUserIds }),
});
if (request.kind === 'chat') {
const chat = await rpc.chats.create(request.params);
@@ -202,23 +204,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
setIsSubmitting(false);
setCloseGuard(false);
}
- }, [
- canSubmit,
- selectedBridge,
- serverId,
- workspaceId,
- name,
- description,
- instructions,
- agents,
- requestIds,
- onSuccess,
- setCloseGuard,
- ]);
-
- const submitOnEnter = (e: React.KeyboardEvent) => {
- if (e.key === 'Enter' && canSubmit) void handleSubmit();
- };
+ }
return (
<>
@@ -226,7 +212,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
<DialogTitle>New room</DialogTitle>
</DialogHeader>
<DialogContentArea className="pt-0">
- <div className="flex w-full flex-col gap-6">
+ <div className="flex w-full flex-col gap-5">
{!server && (
<p className="text-xs text-destructive">
No Switch server is selected, so there is nowhere to create a room. Choose a server in
@@ -234,194 +220,109 @@ export const CreateRoomModal = observer(function CreateRoomModal({
</p>
)}
- {/* The app comes first because it decides the rest: the room's name
- becomes a channel name there, and who can reach the room is
- whoever is in that workspace. */}
- <section className="flex flex-col gap-3">
- <div className="flex flex-col gap-0.5">
- <span className="text-sm font-medium text-foreground">Messaging app</span>
- <span className="text-sm text-foreground-muted">
- Where the collaboration happens — people and agents talk in this room.
- </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) => (
- <BridgeTile
- key={bridge.id}
- bridge={bridge}
- identity={identities?.find((i) => i.bridgeId === bridge.id) ?? null}
- identitiesKnown={identities !== null}
- unusable={bridgeUnusableReason(bridge, { needsChannelCreation: true })}
- selected={selectedBridge?.id === bridge.id}
- onSelect={() => setBridgeId(bridge.id)}
- />
- ))}
- </div>
- {noBridgesAtAll && (
- <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-foreground-muted">
- This server&apos;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-foreground-muted">
- None of the running messaging apps can create a channel from Switch. Make the chat
- directly in the messaging app instead and add the app&apos;s bot to it — it becomes
- a room here once it exists.
+ <input
+ autoFocus
+ aria-label="Room name"
+ placeholder="Room name"
+ value={name}
+ onChange={(e) => {
+ setName(e.target.value);
+ setError(null);
+ }}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && canSubmit) void handleSubmit();
+ }}
+ className="w-full border-b border-border bg-transparent pb-2 text-xl font-semibold text-foreground outline-none placeholder:font-normal placeholder:text-foreground-passive focus:border-foreground-muted"
+ />
+ {/* What the name becomes, where it becomes it: a bridged room is a
+ channel of the same name in its app. */}
+ {trimmedName !== '' && selectedBridge && (
+ <span className="-mt-3 text-xs text-foreground-muted">
+ Created as #{trimmedName} in {selectedBridge.displayName}.
+ </span>
+ )}
+
+ <section className="flex flex-col gap-2">
+ <span className="text-xs font-semibold tracking-wide text-foreground-muted uppercase">
+ Participants
+ </span>
+ <ParticipantPicker
+ candidates={candidates}
+ picked={picked}
+ onChange={setPicked}
+ serverId={serverId || null}
+ loading={agentsQuery.isLoading || rosterQuery.isLoading}
+ />
+ <span className="text-xs text-foreground-muted">
+ Agents answer only when someone @-mentions them.
+ </span>
+ {agentsQuery.isError && (
+ <p className="text-xs text-destructive">
+ {failureText(agentsQuery.error, 'Could not load the agents.')}
</p>
)}
- {bridgesQuery.isError && (
+ {rosterQuery.isError && (
<p className="text-xs text-destructive">
- {failureText(bridgesQuery.error, 'Could not load messaging apps.')}
+ {failureText(rosterQuery.error, 'Could not load the people.')}
</p>
)}
</section>
- <div className="flex flex-col gap-4">
- <FormRow label="Name">
+ {/* A bridged room's own settings; a Switch Console room has none to start with. */}
+ {selectedBridge && (
+ <section className="flex flex-col gap-3">
<Input
- autoFocus
- placeholder="e.g. design-review"
- value={name}
+ placeholder="What this room is for"
+ aria-label="Description"
+ value={description}
onChange={(e) => {
- setName(e.target.value);
+ setDescription(e.target.value);
setError(null);
}}
- onKeyDown={submitOnEnter}
/>
- {/* What the name becomes, where it becomes it. A room is a channel
- in the app it is bridged to, and the two names are the same
- one — saying so here is what makes that predictable. */}
- {trimmedName !== '' && selectedBridge && (
- <span className="text-xs text-foreground-muted">
- Created as #{trimmedName} in {selectedBridge.displayName}.
- </span>
- )}
- </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">
- <div className="flex items-center justify-between gap-3">
- <span className="text-sm font-medium text-foreground">Agents</span>
- {agents.length > 0 && (
- <span className="text-sm text-foreground-muted">{agents.length} added</span>
- )}
- </div>
-
- {agents.length > 0 && (
- <div className="grid grid-cols-3 gap-2.5">
- {agents.map((agent) => (
- <ChosenAgentTile
- key={agent.id}
- agent={agent}
- serverId={serverId || null}
- subtitle={providerLabel(agent.id)}
- onRemove={() =>
- setAgents((current) => current.filter((a) => a.id !== agent.id))
- }
- />
- ))}
- </div>
- )}
-
- <PickerCombobox
- items={pickableAgents.filter((a) => !agents.some((s) => s.id === a.id))}
- onPick={(next) => setAgents((current) => [...current, next])}
- searchText={(item) => item.name}
- renderItem={(item) => (
- <AgentPickerRow
- agent={item}
- serverId={serverId || null}
- subtitle={providerLabel(item.id)}
- />
- )}
- disabled={agentsQuery.isLoading}
- placeholder={agentsQuery.isLoading ? 'Loading agents…' : 'Search agents to add...'}
- emptyText="No agents found"
- />
-
- <span className="text-xs text-foreground-muted">
- Optional — agents can be added to the room later.
- </span>
- </section>
-
- {selectedBridge && (
- <div>
- <DisclosureRow
- open={instructionsOpen}
- title="Instructions"
- meta="shown to agents when they enter"
- onToggle={() => setInstructionsOpen((v) => !v)}
+ <Textarea
+ placeholder="Optional guidance shown to agents when they enter the room"
+ aria-label="Instructions"
+ value={instructions}
+ onChange={(e) => setInstructions(e.target.value)}
+ rows={3}
/>
- {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>
+ </section>
)}
+ {bridgesQuery.isError && (
+ <p className="text-xs text-destructive">
+ {failureText(bridgesQuery.error, 'Could not load messaging apps.')}
+ </p>
+ )}
{error && <p className="text-xs text-destructive">{error}</p>}
</div>
</DialogContentArea>
- <DialogFooter>
- <Button variant="outline" onClick={onClose} disabled={isSubmitting}>
- Cancel
- </Button>
- <ConfirmButton onClick={() => void handleSubmit()} disabled={!canSubmit}>
- {isSubmitting ? 'Creating…' : 'Create room'}
- </ConfirmButton>
+ <DialogFooter className="sm:justify-between">
+ <MessagingAppSelector
+ bridges={bridges}
+ value={where}
+ onChange={(next) => {
+ setWhere(next);
+ setError(null);
+ // A bridged room starts with agents only.
+ if (next !== SWITCH_CONSOLE)
+ setPicked((current) => current.filter((each) => each.kind === 'agent'));
+ }}
+ />
+ <div className="ml-auto flex items-center gap-2">
+ <Button variant="outline" onClick={onClose} disabled={isSubmitting}>
+ Cancel
+ </Button>
+ <ConfirmButton onClick={() => void handleSubmit()} disabled={!canSubmit}>
+ {isSubmitting ? 'Creating…' : 'Create room'}
+ </ConfirmButton>
+ </div>
</DialogFooter>
</>
);
});
-/** A labelled row: the setting's name on the left, the control on the right. */
-function FormRow({ label, children }: { label: string; children: React.ReactNode }) {
- return (
- <div className="flex items-start gap-4">
- <span className="w-24 shrink-0 pt-2 text-sm text-foreground">{label}</span>
- <div className="flex min-w-0 flex-1 flex-col gap-1.5">{children}</div>
- </div>
- );
-}
-
/** Turn a failed create into something the user can act on. */
function messageFor(result: { kind: string; message?: string }): string {
switch (result.kind) {
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.tsx
new file mode 100644
index 000000000..814f35291
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/messaging-app-selector.tsx
@@ -0,0 +1,83 @@
+import { ChevronDown, MessagesSquare } from 'lucide-react';
+import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuRadioGroup,
+ DropdownMenuRadioItem,
+ DropdownMenuTrigger,
+} from '@renderer/lib/ui/dropdown-menu';
+import type { RemoteBridge } from '@shared/core/switch-servers/switch-servers';
+
+/** Value of the Switch Console option, which needs no messaging app. */
+export const SWITCH_CONSOLE = '';
+
+type Option = { value: string; label: string; type: string | null };
+
+/** Switch Console, then each app a room can be created on. */
+export function messagingOptions(bridges: readonly RemoteBridge[]): Option[] {
+ return [
+ { value: SWITCH_CONSOLE, label: 'Switch Console', type: null },
+ ...bridges.map((bridge) => ({
+ value: bridge.id,
+ label: bridge.displayName,
+ type: bridge.type,
+ })),
+ ];
+}
+
+function OptionIcon({ type }: { type: string | null }) {
+ return type !== null && hasBridgeIcon(type) ? (
+ <BridgeIcon bridgeType={type} size={14} className="shrink-0" />
+ ) : (
+ <MessagesSquare className="size-3.5 shrink-0 text-foreground-muted" />
+ );
+}
+
+/**
+ * Where the room lives, as a pill in the dialog's footer. Absent when Switch
+ * Console is the only choice: a selector with one option is a label pretending
+ * to be a control.
+ */
+export function MessagingAppSelector({
+ bridges,
+ value,
+ onChange,
+}: {
+ /** The apps a room can be created on: running, and allowed to create channels. */
+ bridges: readonly RemoteBridge[];
+ value: string;
+ onChange: (value: string) => void;
+}) {
+ const options = messagingOptions(bridges);
+ if (options.length < 2) return null;
+ const selected = options.find((option) => option.value === value) ?? options[0];
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ aria-label={`Messaging app: ${selected.label}`}
+ className="flex h-8 cursor-pointer items-center gap-1.5 rounded-full border border-border px-3 text-sm text-foreground transition-colors hover:bg-[var(--sel-soft)]"
+ >
+ <OptionIcon type={selected.type} />
+ <span className="max-w-40 truncate">{selected.label}</span>
+ <ChevronDown className="size-3.5 shrink-0 text-foreground-muted" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="min-w-52">
+ <DropdownMenuRadioGroup value={selected.value}>
+ {options.map((option) => (
+ <DropdownMenuRadioItem
+ key={option.value}
+ value={option.value}
+ onClick={() => onChange(option.value)}
+ >
+ <span className="flex items-center gap-2">
+ <OptionIcon type={option.type} />
+ {option.label}
+ </span>
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+}
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.ts
new file mode 100644
index 000000000..485df3225
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/new-room-dialog.test.ts
@@ -0,0 +1,93 @@
+import { createElement } from 'react';
+import { renderToStaticMarkup } from 'react-dom/server';
+import { describe, expect, it, vi } from 'vitest';
+import type { RemoteBridge } from '@shared/core/switch-servers/switch-servers';
+import { MessagingAppSelector, messagingOptions, SWITCH_CONSOLE } from './messaging-app-selector';
+import { ParticipantPicker } from './participant-picker';
+import type { Participant } from './participant-search';
+
+vi.mock('@renderer/lib/stores/use-avatar-settings', () => ({
+ useAvatarSettings: () => ({ thirdPartyAvatarsEnabled: false }),
+ useThirdPartyAvatarsEnabled: () => false,
+}));
+
+const slack: RemoteBridge = {
+ id: 'b-slack',
+ type: 'slack',
+ displayName: 'Acme Slack',
+ status: 'active',
+ isDefault: true,
+ homeUrl: null,
+ channelCreationSupported: true,
+ canCreateChannels: true,
+} as RemoteBridge;
+
+const helper: Participant = {
+ kind: 'agent',
+ id: 'a1',
+ name: 'helper',
+ iconUrl: 'https://example.com/helper.png',
+ detail: 'Agent · Claude Code',
+};
+const bob: Participant = {
+ kind: 'person',
+ id: 'u2',
+ name: 'Bob Member',
+ detail: '[email protected]',
+};
+
+describe('MessagingAppSelector', () => {
+ it('is hidden when Switch Console is the only choice', () => {
+ const html = renderToStaticMarkup(
+ createElement(MessagingAppSelector, {
+ bridges: [],
+ value: SWITCH_CONSOLE,
+ onChange: () => {},
+ })
+ );
+ expect(html).toBe('');
+ });
+
+ it('shows the chosen app with its icon, and lists Switch Console and each app', () => {
+ const html = renderToStaticMarkup(
+ createElement(MessagingAppSelector, {
+ bridges: [slack],
+ value: 'b-slack',
+ onChange: () => {},
+ })
+ );
+ expect(html).toContain('Acme Slack');
+ expect(html).toContain('<svg');
+ expect(
+ renderToStaticMarkup(
+ createElement(MessagingAppSelector, {
+ bridges: [slack],
+ value: SWITCH_CONSOLE,
+ onChange: () => {},
+ })
+ )
+ ).toContain('Switch Console');
+ expect(messagingOptions([slack])).toEqual([
+ { value: SWITCH_CONSOLE, label: 'Switch Console', type: null },
+ { value: 'b-slack', label: 'Acme Slack', type: 'slack' },
+ ]);
+ });
+});
+
+describe('ParticipantPicker', () => {
+ it('shows the picked agents and people as removable chips inside the field', () => {
+ const html = renderToStaticMarkup(
+ createElement(ParticipantPicker, {
+ candidates: [helper, bob],
+ picked: [helper, bob],
+ onChange: () => {},
+ serverId: 's',
+ loading: false,
+ })
+ );
+ expect(html).toContain('aria-label="Remove helper"');
+ expect(html).toContain('aria-label="Remove Bob Member"');
+ expect(html).toContain('src="https://example.com/helper.png"');
+ expect(html).toContain('>BM<');
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-picker.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-picker.tsx
new file mode 100644
index 000000000..cdb9282a9
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-picker.tsx
@@ -0,0 +1,201 @@
+import { X } from 'lucide-react';
+import { useState } from 'react';
+import { useAgentAccent } from '@renderer/lib/components/agent-accent';
+import { AgentAvatar } from '@renderer/lib/components/agent-avatar';
+import { cn } from '@renderer/utils/utils';
+import { agentInitials } from '@shared/core/agents/agent-avatar';
+import { type Participant, pickerKey, searchParticipants } from './participant-search';
+
+/** A person's initials disc, as the chat timeline draws people. */
+function Initials({ name, size }: { name: string; size: number }) {
+ return (
+ <span
+ aria-hidden
+ style={{ width: size, height: size, fontSize: Math.round(size * 0.42) }}
+ className="flex shrink-0 items-center justify-center rounded-full bg-[var(--fill-2)] font-medium text-foreground"
+ >
+ {agentInitials(name)}
+ </span>
+ );
+}
+
+function Mark({
+ participant,
+ serverId,
+ size,
+}: {
+ participant: Participant;
+ serverId: string | null;
+ size: number;
+}) {
+ return participant.kind === 'agent' ? (
+ <AgentAvatar
+ name={participant.name}
+ iconUrl={participant.iconUrl}
+ serverId={serverId}
+ size={size}
+ />
+ ) : (
+ <Initials name={participant.name} size={size} />
+ );
+}
+
+/** A picked participant: an agent tinted with its avatar's colour, a person in grey. */
+export function ParticipantChip({
+ participant,
+ serverId,
+ onRemove,
+}: {
+ participant: Participant;
+ serverId: string | null;
+ onRemove: () => void;
+}) {
+ const accent = useAgentAccent(participant.kind === 'agent' ? participant : null, serverId);
+ return (
+ <span
+ className={cn(
+ 'flex h-7 max-w-full items-center gap-1.5 rounded-full py-0.5 pr-1 pl-1 text-sm text-foreground',
+ !accent && 'bg-[var(--fill-2)]'
+ )}
+ style={
+ accent ? { backgroundColor: `color-mix(in srgb, ${accent} 20%, transparent)` } : undefined
+ }
+ >
+ <Mark participant={participant} serverId={serverId} size={20} />
+ <span className="truncate">{participant.name}</span>
+ <button
+ type="button"
+ aria-label={`Remove ${participant.name}`}
+ onClick={onRemove}
+ className="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-full text-foreground-muted hover:bg-[var(--sel-soft)] hover:text-foreground"
+ >
+ <X className="size-3" />
+ </button>
+ </span>
+ );
+}
+
+/**
+ * One field that finds agents and people together and keeps the picked ones
+ * as chips inside it. Up and down move through the results, Enter adds,
+ * Backspace on an empty field takes the last chip back, Escape closes the list.
+ */
+export function ParticipantPicker({
+ candidates,
+ picked,
+ onChange,
+ serverId,
+ loading,
+}: {
+ candidates: Participant[];
+ picked: Participant[];
+ onChange: (next: Participant[]) => void;
+ serverId: string | null;
+ loading: boolean;
+}) {
+ const [query, setQuery] = useState('');
+ const [open, setOpen] = useState(false);
+ const [active, setActive] = useState(0);
+ const results = searchParticipants(candidates, picked, query);
+ const current = Math.min(active, Math.max(results.length - 1, 0));
+
+ const add = (participant: Participant) => {
+ onChange([...picked, participant]);
+ setQuery('');
+ setActive(0);
+ };
+
+ return (
+ <div>
+ <div
+ className="flex min-h-11 flex-wrap items-center gap-1.5 rounded-[10px] border border-border px-2 py-1.5 focus-within:border-foreground-muted"
+ onClick={(event) =>
+ (event.currentTarget.querySelector('input') as HTMLInputElement | null)?.focus()
+ }
+ >
+ {picked.map((participant) => (
+ <ParticipantChip
+ key={`${participant.kind}:${participant.id}`}
+ participant={participant}
+ serverId={serverId}
+ onRemove={() => onChange(picked.filter((each) => each !== participant))}
+ />
+ ))}
+ <input
+ role="combobox"
+ aria-expanded={open}
+ aria-controls="new-room-participants"
+ aria-label="Add agents or people"
+ placeholder={picked.length === 0 ? 'Add agents or people…' : ''}
+ className="h-7 min-w-32 flex-1 bg-transparent px-1 text-sm outline-none placeholder:text-foreground-passive"
+ value={query}
+ onChange={(event) => {
+ setQuery(event.target.value);
+ setActive(0);
+ setOpen(true);
+ }}
+ onFocus={() => setOpen(true)}
+ onBlur={() => setOpen(false)}
+ onKeyDown={(event) => {
+ const action = pickerKey(event.key, {
+ query,
+ open,
+ active: current,
+ results: results.length,
+ picked: picked.length,
+ });
+ if (!action) return;
+ event.preventDefault();
+ event.stopPropagation();
+ if (action.type === 'move') {
+ setOpen(true);
+ setActive(action.active);
+ } else if (action.type === 'add') add(results[current]);
+ else if (action.type === 'removeLast') onChange(picked.slice(0, -1));
+ else setOpen(false);
+ }}
+ />
+ </div>
+ {open && (
+ // In the flow rather than floating: the dialog clips what overflows it, so the list grows it instead.
+ <div
+ id="new-room-participants"
+ role="listbox"
+ className="mt-1 max-h-60 overflow-y-auto rounded-[10px] border border-border bg-background p-1 shadow-sm"
+ >
+ {loading ? (
+ <p className="px-2.5 py-2 text-sm text-foreground-muted">Loading…</p>
+ ) : results.length === 0 ? (
+ <p className="px-2.5 py-2 text-sm text-foreground-muted">
+ {query.trim() === ''
+ ? 'Everyone you can add is already in.'
+ : `No agent or person matches “${query.trim()}”.`}
+ </p>
+ ) : (
+ results.map((participant, index) => (
+ <div
+ key={`${participant.kind}:${participant.id}`}
+ role="option"
+ aria-selected={index === current}
+ // Keeps focus in the field, so the list stays open for the next pick.
+ onMouseDown={(event) => event.preventDefault()}
+ onMouseEnter={() => setActive(index)}
+ onClick={() => add(participant)}
+ className={cn(
+ 'flex cursor-pointer items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm',
+ index === current && 'bg-[var(--sel-soft)]'
+ )}
+ >
+ <Mark participant={participant} serverId={serverId} size={22} />
+ <span className="min-w-0 flex-1 truncate text-foreground">{participant.name}</span>
+ <span className="shrink-0 truncate text-xs text-foreground-muted">
+ {participant.detail}
+ </span>
+ </div>
+ ))
+ )}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-search.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-search.test.ts
new file mode 100644
index 000000000..e8fd2f475
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-search.test.ts
@@ -0,0 +1,56 @@
+import { describe, expect, it } from 'vitest';
+import { type Participant, pickerKey, searchParticipants } from './participant-search';
+
+const helper: Participant = {
+ kind: 'agent',
+ id: 'a1',
+ name: 'helper',
+ iconUrl: null,
+ detail: 'Agent · Claude Code',
+};
+const reviewer: Participant = { ...helper, id: 'a2', name: 'reviewer', detail: 'Agent · Codex' };
+const bob: Participant = { kind: 'person', id: 'u2', name: 'Bob', detail: '[email protected]' };
+// The same id as an agent must not hide a person.
+const sameId: Participant = { kind: 'person', id: 'a1', name: 'Ada', detail: '[email protected]' };
+const all = [helper, reviewer, bob, sameId];
+
+describe('searchParticipants', () => {
+ it('finds agents and people together, by name, provider or email', () => {
+ expect(searchParticipants(all, [], '')).toEqual(all);
+ expect(searchParticipants(all, [], 'B')).toEqual([bob]);
+ expect(searchParticipants(all, [], 'codex')).toEqual([reviewer]);
+ expect(searchParticipants(all, [], 'example.com')).toEqual([bob, sameId]);
+ });
+
+ it('leaves out who is already picked', () => {
+ expect(searchParticipants(all, [helper, bob], '')).toEqual([reviewer, sameId]);
+ });
+});
+
+describe('pickerKey', () => {
+ const state = { query: '', open: true, active: 0, results: 3, picked: 2 };
+
+ it('moves through the results, wrapping', () => {
+ expect(pickerKey('ArrowDown', state)).toEqual({ type: 'move', active: 1 });
+ expect(pickerKey('ArrowDown', { ...state, active: 2 })).toEqual({ type: 'move', active: 0 });
+ expect(pickerKey('ArrowUp', state)).toEqual({ type: 'move', active: 2 });
+ expect(pickerKey('ArrowDown', { ...state, results: 0 })).toBeNull();
+ });
+
+ it('adds with Enter only from an open list with results', () => {
+ expect(pickerKey('Enter', state)).toEqual({ type: 'add' });
+ expect(pickerKey('Enter', { ...state, open: false })).toBeNull();
+ expect(pickerKey('Enter', { ...state, results: 0 })).toBeNull();
+ });
+
+ it('takes back the last chip with Backspace on an empty field only', () => {
+ expect(pickerKey('Backspace', state)).toEqual({ type: 'removeLast' });
+ expect(pickerKey('Backspace', { ...state, query: 'b' })).toBeNull();
+ expect(pickerKey('Backspace', { ...state, picked: 0 })).toBeNull();
+ });
+
+ it('closes the list with Escape, and leaves Escape to the dialog once closed', () => {
+ expect(pickerKey('Escape', state)).toEqual({ type: 'close' });
+ expect(pickerKey('Escape', { ...state, open: false })).toBeNull();
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-search.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-search.ts
new file mode 100644
index 000000000..d27750f10
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/participant-search.ts
@@ -0,0 +1,51 @@
+/** Someone who can be put in a new room: an agent, or a person from the workspace. */
+export type Participant =
+ | { kind: 'agent'; id: string; name: string; iconUrl: string | null; detail: string }
+ | { kind: 'person'; id: string; name: string; detail: string };
+
+const same = (a: Participant, b: Participant) => a.kind === b.kind && a.id === b.id;
+
+/** The candidates not yet picked whose name or detail (provider, email) contains the query. */
+export function searchParticipants(
+ candidates: readonly Participant[],
+ picked: readonly Participant[],
+ query: string
+): Participant[] {
+ const needle = query.trim().toLowerCase();
+ return candidates.filter(
+ (candidate) =>
+ !picked.some((each) => same(each, candidate)) &&
+ (needle === '' || `${candidate.name}\n${candidate.detail}`.toLowerCase().includes(needle))
+ );
+}
+
+export type PickerKeyAction =
+ | { type: 'move'; active: number }
+ | { type: 'add' }
+ | { type: 'removeLast' }
+ | { type: 'close' }
+ | null;
+
+/** What a key in the search field does; null leaves it to the browser and the dialog. */
+export function pickerKey(
+ key: string,
+ state: { query: string; open: boolean; active: number; results: number; picked: number }
+): PickerKeyAction {
+ const { query, open, active, results, picked } = state;
+ switch (key) {
+ case 'ArrowDown':
+ return results > 0 ? { type: 'move', active: open ? (active + 1) % results : 0 } : null;
+ case 'ArrowUp':
+ return results > 0
+ ? { type: 'move', active: open ? (active - 1 + results) % results : results - 1 }
+ : null;
+ case 'Enter':
+ return open && results > 0 ? { type: 'add' } : null;
+ case 'Backspace':
+ return query === '' && picked > 0 ? { type: 'removeLast' } : null;
+ case 'Escape':
+ return open ? { type: 'close' } : null;
+ default:
+ return null;
+ }
+}
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.ts
index 7ab1a9a6a..19af0525e 100644
--- 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.ts
@@ -7,25 +7,38 @@ const form = {
name: ' Ship review ',
description: ' Reviews ',
instructions: '',
- agentIds: ['a1', 'a2'],
+ agentIds: ['a1'],
+ memberUserIds: ['u2'],
requestId: 'req',
};
describe('roomCreateRequest', () => {
- it('creates a Switch Console chat when no messaging app is chosen', () => {
+ it('creates a Switch Console group, people included, even with one agent', () => {
expect(roomCreateRequest({ ...form, bridgeId: null })).toEqual({
kind: 'chat',
params: {
serverId: 's',
name: 'Ship review',
- agentIds: ['a1', 'a2'],
- memberUserIds: [],
+ agentIds: ['a1'],
+ memberUserIds: ['u2'],
requestId: 'req',
greeting: null,
+ kind: 'group',
},
});
});
+ it('never sends an id twice', () => {
+ const request = roomCreateRequest({
+ ...form,
+ bridgeId: null,
+ agentIds: ['a1', 'a1'],
+ memberUserIds: ['u2', 'u2'],
+ });
+ expect(request.params.agentIds).toEqual(['a1']);
+ expect(request.kind === 'chat' && request.params.memberUserIds).toEqual(['u2']);
+ });
+
it('creates a bridged room as before when an app is chosen', () => {
expect(roomCreateRequest({ ...form, bridgeId: 'b1', agentIds: [] })).toEqual({
kind: 'room',
@@ -54,12 +67,13 @@ describe('CreateRequestIds', () => {
it('reuses the id for an unchanged form and takes a new one on a change or a success', () => {
let n = 0;
const ids = new CreateRequestIds(() => `id-${++n}`);
- const chatForm = { bridgeId: null, name: 'Ship review', agentIds: ['a1', 'a2'] };
+ const chatForm = { bridgeId: null, name: 'Ship review', agentIds: ['a1'], memberUserIds: [] };
const first = ids.for(chatForm);
expect(ids.for({ ...chatForm, name: ' Ship review ' })).toBe(first);
- expect(ids.for({ ...chatForm, name: 'Ship reviews' })).not.toBe(first);
- expect(ids.for({ ...chatForm, name: 'Ship reviews', agentIds: ['a1'] })).toBe('id-3');
+ expect(ids.for({ ...chatForm, name: 'Ship reviews' })).toBe('id-2');
+ expect(ids.for({ ...chatForm, name: 'Ship reviews', memberUserIds: ['u2'] })).toBe('id-3');
+ expect(ids.for({ ...chatForm, name: 'Ship reviews', memberUserIds: ['u2'] })).toBe('id-3');
ids.succeeded();
- expect(ids.for({ ...chatForm, name: 'Ship reviews', agentIds: ['a1'] })).toBe('id-4');
+ expect(ids.for({ ...chatForm, name: 'Ship reviews', memberUserIds: ['u2'] })).toBe('id-4');
});
});
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.ts
index 166d10e70..c9709f08b 100644
--- 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.ts
@@ -9,6 +9,8 @@ export type RoomCreateRequest =
memberUserIds: string[];
requestId: string;
greeting: null;
+ /** A room made here is a group even with one agent and nobody else. */
+ kind: 'group';
};
}
| {
@@ -32,19 +34,23 @@ export function roomCreateRequest(form: {
description: string;
instructions: string;
agentIds: string[];
+ /** The people to add; a bridged room is created without them. */
+ memberUserIds: string[];
requestId: string;
}): RoomCreateRequest {
const name = form.name.trim();
+ const agentIds = [...new Set(form.agentIds)];
if (form.bridgeId === null)
return {
kind: 'chat',
params: {
serverId: form.serverId,
name,
- agentIds: form.agentIds,
- memberUserIds: [],
+ agentIds,
+ memberUserIds: [...new Set(form.memberUserIds)],
requestId: form.requestId,
greeting: null,
+ kind: 'group',
},
};
return {
@@ -55,7 +61,7 @@ export function roomCreateRequest(form: {
description: form.description.trim(),
instructions: form.instructions.trim() || undefined,
bridgeId: form.bridgeId,
- agentIds: form.agentIds,
+ agentIds,
},
};
}
@@ -77,8 +83,18 @@ export class CreateRequestIds {
constructor(private readonly newId: () => string) {}
- for(form: { bridgeId: string | null; name: string; agentIds: string[] }): string {
- const key = JSON.stringify([form.bridgeId, form.name.trim(), form.agentIds]);
+ for(form: {
+ bridgeId: string | null;
+ name: string;
+ agentIds: string[];
+ memberUserIds: string[];
+ }): string {
+ const key = JSON.stringify([
+ form.bridgeId,
+ form.name.trim(),
+ form.agentIds,
+ form.memberUserIds,
+ ]);
if (key !== this.key) {
this.key = key;
this.id = this.newId();
diff --git a/console/apps/switch-console-desktop/src/shared/core/providers/agent-provider-registry.ts b/console/apps/switch-console-desktop/src/shared/core/providers/agent-provider-registry.ts
index 22bdde9d5..94ac3f695 100644
--- a/console/apps/switch-console-desktop/src/shared/core/providers/agent-provider-registry.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/providers/agent-provider-registry.ts
@@ -106,6 +106,15 @@ export function providerDisplayName(id: string | null | undefined): string | nul
return getProvider(id)?.name ?? id;
}
+/** What a provider is called, from the agent type the server records (`claude-code`). */
+export function knownAgentTypeDisplayName(type: string | null | undefined): string | null {
+ if (!type) return null;
+ return (
+ agentProviders().find((provider) => provider.knownAgentType === type)?.name ??
+ providerDisplayName(type)
+ );
+}
+
export function getDescriptionForProvider(id: AgentProviderId): string | null {
return getProvider(id)?.description ?? null;
}