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): picks in a chat's add field wait as chips for Add

raullopez-sandbox533428d011d8
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 363aa9e71..2f8a680a3 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
@@ -24,6 +24,7 @@ import { useNavigate } from '@renderer/lib/layout/navigation-provider';
import { useShowModal } from '@renderer/lib/modal/modal-provider';
import { useWorkspaceAgents } from '@renderer/lib/stores/use-workspace-agents';
import { Button } from '@renderer/lib/ui/button';
+import { ConfirmButton } from '@renderer/lib/ui/confirm-button';
import { Input } from '@renderer/lib/ui/input';
import {
InputGroup,
@@ -243,10 +244,38 @@ export async function addToChat(
const ADD_PARTICIPANT_INPUT = 'chat-add-participant';
+/** The Add button's label: how many it adds once there is more than one. */
+export function addLabel(count: number): string {
+ return count > 1 ? `Add ${count}` : 'Add';
+}
+
/**
- * The New room dialog's participant field, adding each pick at once: an agent
- * the workspace shows (the server decides who may use which) or a person on
- * its roster, never someone already in the chat.
+ * Adds each pick in turn through the chats API, telling `onAdded` of each
+ * success; resolves to the picks the server refused, each with its reason.
+ * One at a time, so each add sees the chat as the one before left it.
+ */
+export async function addAllToChat(
+ api: Pick<typeof rpc.chats, 'addAgent' | 'addMember'>,
+ serverId: string,
+ roomId: string,
+ picks: Participant[],
+ onAdded: (added: Awaited<ReturnType<typeof addToChat>>) => void
+): Promise<{ participant: Participant; reason: string }[]> {
+ const failures: { participant: Participant; reason: string }[] = [];
+ for (const participant of picks) {
+ try {
+ onAdded(await addToChat(api, serverId, roomId, participant));
+ } catch (cause) {
+ failures.push({ participant, reason: chatFailure(cause).message });
+ }
+ }
+ return failures;
+}
+
+/**
+ * The New room dialog's participant field: picks gather as chips, and Add
+ * puts them all in the chat. It offers the agents the viewer may add and the
+ * people on the roster, never someone already in the chat.
*/
const ChatAddParticipantPanel = observer(function ChatAddParticipantPanel({
serverId,
@@ -280,8 +309,9 @@ const ChatAddParticipantPanel = observer(function ChatAddParticipantPanel({
],
queryFn: () => rpc.chats.agentCandidates({ serverId, roomId: chat.roomId }),
});
- const [adding, setAdding] = useState<string | null>(null);
- const [error, setError] = useState<string | null>(null);
+ const [picked, setPicked] = useState<Participant[]>([]);
+ const [adding, setAdding] = useState(false);
+ const [refused, setRefused] = useState<string[]>([]);
const candidates = [
...addableAgents(agents.data ?? [], allowed.data ?? []).map((agent) =>
agentParticipant(agent, knownAgentTypeDisplayName(agent.knownAgentType) ?? 'Agent')
@@ -289,37 +319,53 @@ const ChatAddParticipantPanel = observer(function ChatAddParticipantPanel({
...addablePeople(roster.data ?? [], memberIds).map(personParticipant),
];
- async function add(participant: Participant) {
- setAdding(participant.id);
- setError(null);
- try {
- const added = await addToChat(rpc.chats, serverId, chat.roomId, participant);
+ async function addAll() {
+ if (adding || picked.length === 0) return;
+ setAdding(true);
+ setRefused([]);
+ const failures = await addAllToChat(rpc.chats, serverId, chat.roomId, picked, (added) => {
if (added.kind === 'agent') chatsStore.add(serverId, added.chat);
else onAddedPeople(added.members);
- } catch (cause) {
- setError(`${participant.name} was not added — ${chatFailure(cause).message}`);
- } finally {
- setAdding(null);
- }
+ });
+ setPicked(failures.map((failure) => failure.participant));
+ setRefused(
+ failures.map(({ participant, reason }) => `${participant.name} was not added — ${reason}`)
+ );
+ setAdding(false);
}
return (
<div className="flex flex-col gap-2 pt-1">
- <ParticipantPicker
- inputId={ADD_PARTICIPANT_INPUT}
- autoFocus={false}
- busy={adding !== null}
- overlay
- candidates={candidates}
- picked={[]}
- onChange={(next) => {
- const picked = next.at(-1);
- if (picked) void add(picked);
- }}
- serverId={serverId}
- loading={agents.isPending || allowed.isPending || (tenantId !== null && roster.isPending)}
- />
- {error !== null && <p className="text-xs text-destructive">{error}</p>}
+ <div className="flex items-start gap-2">
+ <div className="min-w-0 flex-1">
+ <ParticipantPicker
+ inputId={ADD_PARTICIPANT_INPUT}
+ autoFocus={false}
+ busy={adding}
+ overlay
+ candidates={candidates}
+ picked={picked}
+ onChange={setPicked}
+ serverId={serverId}
+ loading={
+ agents.isPending || allowed.isPending || (tenantId !== null && roster.isPending)
+ }
+ />
+ </div>
+ <ConfirmButton
+ size="sm"
+ className="h-8 shrink-0"
+ disabled={picked.length === 0 || adding}
+ onClick={() => void addAll()}
+ >
+ {addLabel(picked.length)}
+ </ConfirmButton>
+ </div>
+ {refused.map((line) => (
+ <p key={line} className="text-xs text-destructive">
+ {line}
+ </p>
+ ))}
{(agents.isError || allowed.isError) && (
<p className="text-xs text-destructive">
{failureText(agents.error ?? allowed.error, 'Could not list the agents.')}
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.ts
index 98b09ed32..f34c206bb 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
@@ -3,12 +3,15 @@ import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it, vi } from 'vitest';
import {
+ addAllToChat,
+ addLabel,
addToChat,
chatMembersQueryKey,
InviteHint,
RoomConfigurationPanel,
} from '@renderer/features/switch-rooms/room-configuration-panel';
import type { ChatSummary } from '@shared/core/chats/chats';
+import { RpcError } from '@shared/lib/ipc/rpc-error';
const chat = vi.hoisted(() => ({ current: null as ChatSummary | null }));
vi.mock('@renderer/lib/ipc', () => ({ events: { on: vi.fn() }, rpc: {} }));
@@ -84,6 +87,8 @@ describe('RoomConfigurationPanel for a group chat', () => {
expect(field).toBeGreaterThan(html.indexOf('Add participants'));
expect(html.indexOf('Don&#x27;t see someone?')).toBeGreaterThan(field);
expect(html.indexOf('aria-label="Remove Helper"')).toBeGreaterThan(field);
+ // Nothing picked yet: Add sits beside the field, disabled.
+ expect(html).toMatch(/<button[^>]* disabled=""[^>]*><span[^>]*>Add<span data-slot="shortcut"/);
});
it('shows the participants without controls to someone who cannot manage', () => {
@@ -167,3 +172,46 @@ describe('addToChat', () => {
expect(api.addMember).toHaveBeenCalledWith({ serverId: 's', roomId: 'r', userId: 'u2' });
});
});
+
+describe('adding the picked participants', () => {
+ const agentPick = {
+ kind: 'agent' as const,
+ id: 'a1',
+ name: 'helper',
+ iconUrl: null,
+ detail: 'Agent · Claude Code',
+ };
+ const refusedPick = { ...agentPick, id: 'a2', name: 'agent-b' };
+ const bobPick = { kind: 'person' as const, id: 'u2', name: 'Bob', detail: '[email protected]' };
+
+ it('counts the picks on the button', () => {
+ expect(addLabel(0)).toBe('Add');
+ expect(addLabel(1)).toBe('Add');
+ expect(addLabel(3)).toBe('Add 3');
+ });
+
+ it('adds every pick and gives back only the refused ones, with the reason', async () => {
+ render(true);
+ const api = {
+ addAgent: vi.fn(async ({ agentId }: { agentId: string }) => {
+ if (agentId === 'a2')
+ throw new RpcError({
+ __switchConsoleRpcError: true,
+ code: 'ChatApiError',
+ message: 'You may not chat with this agent here.',
+ data: { apiCode: 'AGENT_NOT_ALLOWED', status: 403 },
+ });
+ return chat.current!;
+ }),
+ addMember: vi.fn(async () => [{ userId: 'u2', name: 'Bob', isOwner: false }]),
+ };
+ const onAdded = vi.fn();
+ const failures = await addAllToChat(api, 's', 'r', [agentPick, refusedPick, bobPick], onAdded);
+ expect(api.addAgent).toHaveBeenCalledTimes(2);
+ expect(api.addMember).toHaveBeenCalledWith({ serverId: 's', roomId: 'r', userId: 'u2' });
+ expect(onAdded).toHaveBeenCalledTimes(2);
+ expect(failures).toEqual([
+ { participant: refusedPick, reason: 'You may not chat with this agent here.' },
+ ]);
+ });
+});