Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

New room: answer Petr's review

Simon Flackbf9b6605de3a
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.test.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.test.ts
index 39f00a3d0..ea2aceb24 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.test.ts
@@ -32,6 +32,9 @@ const PARAMS = {
description: 'Where design gets reviewed',
bridgeId: 'bridge-1',
agentIds: ['agent-1'],
+ channel: null,
+ groupId: null,
+ access: null,
};
/** A far-from-expiry JWT, so no renewal path is exercised here. */
@@ -170,6 +173,25 @@ describe('createRoomOnServer', () => {
expect(result.kind === 'invalid' && result.message).toMatch(/Check the id/);
});
+ it('does not blame the messaging app for a proxy’s 502', async () => {
+ fetchMock.mockResolvedValue(response(502, '<html>Bad Gateway</html>'));
+
+ const result = await createRoomOnServer(SERVER, PARAMS);
+ expect(result).toMatchObject({ kind: 'error' });
+ expect(result.kind === 'error' && result.message).not.toMatch(/messaging app/);
+ });
+
+ it('rethrows a 500 the server sent on purpose, even for an existing channel', async () => {
+ fetchMock.mockResolvedValue(response(500, { detail: 'Room missing after create' }));
+
+ await expect(
+ createRoomOnServer(SERVER, {
+ ...PARAMS,
+ channel: { kind: 'existing', externalChannelId: 'C0123ABCD' },
+ })
+ ).rejects.toMatchObject({ status: 500 });
+ });
+
it('rethrows a server fault rather than flattening it into a form error', async () => {
fetchMock.mockResolvedValue(response(500, 'Internal Server Error'));
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.ts
index 1fc29a59d..6cb22c39e 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/create-room.ts
@@ -1,4 +1,5 @@
import { createRoom, GatewayError } from '@main/core/switch-servers/gateway-client';
+import { log } from '@main/lib/logger';
import type {
CreateRoomParams,
CreateRoomResult,
@@ -59,17 +60,30 @@ export async function createRoomOnServer(
? { kind: 'bridge-unavailable', message }
: { kind: 'invalid', message };
}
- // The messaging app turned the request down (`BridgeOperationError`).
+ // The messaging app turned the request down (`BridgeOperationError`): the
+ // server says so in its JSON error. A 502 without one comes from a proxy
+ // in front of the server (while it restarts, say), not the messaging app.
if (cause.kind === 'http' && cause.status === 502)
- return {
- kind: 'error',
- message: `The messaging app could not make the room: ${cause.detail ?? cause.message}`,
- };
- // A named channel the server cannot use fails as a fault rather than a
- // 400: an id the app does not know, a channel its bot is not in, or one
- // another room already uses. Said so, since Console is where the id was typed.
- if (cause.kind === 'http' && cause.status === 500 && params.channel?.kind === 'existing')
+ return cause.detail !== undefined
+ ? {
+ kind: 'error',
+ message: `The messaging app could not make the room: ${cause.detail}`,
+ }
+ : { kind: 'error', message: 'The server could not be reached. Try again in a moment.' };
+ // A named channel the server cannot use (one another room already uses,
+ // or a messaging app error it does not map yet) escapes as an unhandled
+ // 500 with no JSON error. Said so, since Console is where the id was
+ // typed, and logged, since it is still a server fault. A 500 the server
+ // chose to send carries its own detail and is thrown like any other.
+ if (
+ cause.kind === 'http' &&
+ cause.status === 500 &&
+ cause.detail === undefined &&
+ params.channel?.kind === 'existing'
+ ) {
+ log.warn('Creating a room on an existing channel failed on the server', cause);
return { kind: 'invalid', message: EXISTING_CHANNEL_REFUSED };
+ }
if (cause.kind === 'network') return { kind: 'error', message: cause.message };
}
throw cause;
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.test.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.test.ts
index 398b65025..f0dd79c1d 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.test.ts
@@ -648,7 +648,15 @@ describe('room creation', () => {
}) as never
);
- await createRoom(SERVER, { name: 'design', description: 'd', bridgeId: null, agentIds: [] });
+ await createRoom(SERVER, {
+ name: 'design',
+ description: 'd',
+ bridgeId: null,
+ agentIds: [],
+ channel: null,
+ groupId: null,
+ access: null,
+ });
expect(bodyOf(fetchMock.mock.calls[0])).toMatchObject({ bridge_id: null, internal_only: true });
});
@@ -673,6 +681,9 @@ describe('room creation', () => {
description: 'd',
bridgeId: 'b1',
agentIds: ['a1'],
+ channel: null,
+ groupId: null,
+ access: null,
});
const body = bodyOf(fetchMock.mock.calls[0]);
@@ -739,6 +750,8 @@ describe('room creation', () => {
bridgeId: 'b1',
agentIds: [],
channel: { kind: 'existing', externalChannelId: 'C123' },
+ groupId: null,
+ access: null,
});
const body = bodyOf(fetchMock.mock.calls[0]);
@@ -768,6 +781,9 @@ describe('room creation', () => {
instructions: ' ',
bridgeId: 'b1',
agentIds: [],
+ channel: null,
+ groupId: null,
+ access: null,
});
expect(bodyOf(fetchMock.mock.calls[0]).instructions).toBeNull();
@@ -777,7 +793,15 @@ describe('room creation', () => {
fetchMock.mockResolvedValue(errorResponse(400, '{"detail":"Bridge not running: b1"}') as never);
await expect(
- createRoom(SERVER, { name: 'x', description: 'y', bridgeId: 'b1', agentIds: [] })
+ createRoom(SERVER, {
+ name: 'x',
+ description: 'y',
+ bridgeId: 'b1',
+ agentIds: [],
+ channel: null,
+ groupId: null,
+ access: null,
+ })
).rejects.toMatchObject({ status: 400, detail: 'Bridge not running: b1' });
});
@@ -800,7 +824,15 @@ describe('room creation', () => {
fetchMock.mockResolvedValue(errorResponse(502, '<html>bad gateway</html>') as never);
await expect(
- createRoom(SERVER, { name: 'x', description: 'y', bridgeId: 'b1', agentIds: [] })
+ createRoom(SERVER, {
+ name: 'x',
+ description: 'y',
+ bridgeId: 'b1',
+ agentIds: [],
+ channel: null,
+ groupId: null,
+ access: null,
+ })
).rejects.toMatchObject({ status: 502, detail: undefined });
});
});
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
index c78965b6f..b9de8d48f 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
@@ -3659,11 +3659,12 @@ export async function createRoom(
/** Null makes an internal room: no channel, not even on the default app. */
bridgeId: string | null;
agentIds: string[];
- /** A new public channel when absent. */
- channel?: NewRoomChannel;
- groupId?: string | null;
+ /** Null for a new public channel. */
+ channel: NewRoomChannel | null;
+ groupId: string | null;
/** The server's default (open to the workspace) when absent. */
- access?: RoomAccess;
+ /** Null for the server's default. */
+ access: RoomAccess | null;
}
): Promise<RemoteRoomSummary> {
const channel = params.channel ?? { kind: 'new', private: false };
diff --git a/console/apps/switch-console-desktop/src/main/core/workspaces/controller.test.ts b/console/apps/switch-console-desktop/src/main/core/workspaces/controller.test.ts
index 369d1d4d2..a565709d2 100644
--- a/console/apps/switch-console-desktop/src/main/core/workspaces/controller.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/workspaces/controller.test.ts
@@ -783,6 +783,9 @@ describe('an action a workspace whose host has gone down cannot take', () => {
description: '',
bridgeId: 'b1',
agentIds: ['a1'],
+ channel: null,
+ groupId: null,
+ access: null,
})
).rejects.toBeInstanceOf(HostUnreachableError);
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx
index f1309cb4d..bdd11ed02 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx
@@ -41,7 +41,8 @@ export const ACCESS_LABELS: Record<RoomAccess, string> = {
private: 'Only those taking part and admins see it; owner and admins change it',
};
-const ACCESS_ORDER: RoomAccess[] = ['public', 'read_only', 'private'];
+/** The access settings in the order they are offered, most open first. */
+export const ACCESS_ORDER: RoomAccess[] = ['public', 'read_only', 'private'];
const NO_GROUP = '__none__';
/** One write's progress, for a control that saves the moment it changes. */
@@ -85,7 +86,7 @@ export const AccessAndGroupFields = observer(function AccessAndGroupFields({
const [groupState, setGroupState] = useState<WriteState>({ phase: 'idle' });
const picksGroup = permissions.canWrite && administersWorkspace;
const groups = useQuery({
- queryKey: ['room-groups', workspaceId],
+ queryKey: ['remote-room-groups', workspaceId],
queryFn: () => rpc.workspaces.listRoomGroups(workspaceId),
enabled: picksGroup,
});
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 1412254d9..68c79ec98 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,6 @@
import { useQuery } from '@tanstack/react-query';
import { observer } from 'mobx-react-lite';
-import { useState } from 'react';
+import { useEffect, useRef, 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';
@@ -124,6 +124,16 @@ export const CreateRoomModal = observer(function CreateRoomModal({
const selectedBridge =
bridges.find((b) => b.id === where) ?? (consoleOffered ? null : (bridges[0] ?? null));
const nowhere = !consoleOffered && selectedBridge === null && !bridgesQuery.isLoading;
+ // A channel, and above all a typed id, belongs to the app it was chosen for:
+ // when the app the room would go to changes, however it changed, the choice
+ // starts again from a new public channel. Picking the app already shown keeps it.
+ const resolvedBridgeId = selectedBridge?.id ?? null;
+ const channelBridgeId = useRef(resolvedBridgeId);
+ useEffect(() => {
+ if (channelBridgeId.current === resolvedBridgeId) return;
+ channelBridgeId.current = resolvedBridgeId;
+ setOptions((now) => ({ ...now, channel: DEFAULT_ROOM_OPTIONS.channel }));
+ }, [resolvedBridgeId]);
const managedProviders = new Map(
(managedQuery.data ?? []).map((managed) => [managed.agentId, managed.definition.provider])
@@ -208,7 +218,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
serverId,
workspaceId: workspaceId as string,
bridgeId,
- bridgeType: selectedBridge?.type,
+ bridgeType: selectedBridge?.type ?? null,
name,
description,
instructions,
@@ -420,10 +430,6 @@ export const CreateRoomModal = observer(function CreateRoomModal({
onChange={(next) => {
setWhere(next);
setError(null);
- // A channel, and above all a typed id, belongs to the app it was
- // chosen for: another app starts again from a new public channel.
- if (next !== where)
- setOptions((now) => ({ ...now, channel: DEFAULT_ROOM_OPTIONS.channel }));
// A bridged room starts with agents only.
if (next !== SWITCH_CONSOLE)
changePicks(shownPicked.filter((each) => each.kind === 'agent'));
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx
index 81cad988f..6334b45d8 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx
@@ -1,6 +1,9 @@
import { useQuery } from '@tanstack/react-query';
import { useState } from 'react';
-import { ACCESS_LABELS } from '@renderer/features/switch-rooms/room-settings-sections';
+import {
+ ACCESS_LABELS,
+ ACCESS_ORDER,
+} from '@renderer/features/switch-rooms/room-settings-sections';
import { failureText } from '@renderer/lib/errors/describe-failure';
import { rpc } from '@renderer/lib/ipc';
import { DisclosureRow } from '@renderer/lib/ui/disclosure-row';
@@ -15,17 +18,10 @@ import {
} from '@renderer/lib/ui/select';
import { cn } from '@renderer/utils/utils';
import type { RemoteBridge, RoomAccess } from '@shared/core/switch-servers/switch-servers';
-import { type ChannelChoice, channelChoiceCards, channelIdProblem } from './room-channel-choices';
+import { channelChoiceCards, channelChoiceOf, channelIdProblem } from './room-channel-choices';
import type { RoomCreateOptions } from './room-create-request';
const NO_GROUP = '__none__';
-const ACCESS_ORDER: RoomAccess[] = ['public', 'read_only', 'private'];
-
-/** The channel choice a set of options holds. */
-function channelChoiceOf(options: RoomCreateOptions): ChannelChoice {
- if (options.channel.kind === 'existing') return 'existing';
- return options.channel.private ? 'private' : 'public';
-}
/**
* Where a room on a messaging app lives: a new public channel (the default),
@@ -136,11 +132,18 @@ export function CreateRoomOptions({
}) {
const [open, setOpen] = useState(false);
const groups = useQuery({
- queryKey: ['room-groups', workspaceId],
+ // The key every view reads the groups under, so they go stale and refresh together.
+ queryKey: ['remote-room-groups', workspaceId],
queryFn: () => rpc.workspaces.listRoomGroups(workspaceId as string),
enabled: workspaceId !== null,
});
- const groupName = (groups.data ?? []).find((group) => group.id === value.groupId)?.name;
+ // The group is named once the list has it; until then (or if it could not be
+ // read) the room is still filed under it, so say so rather than "none".
+ const groupName =
+ value.groupId === null
+ ? null
+ : ((groups.data ?? []).find((group) => group.id === value.groupId)?.name ??
+ (groups.isError ? 'unknown (the groups could not be read)' : 'loading…'));
const access = value.access ?? 'public';
return (
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts
index 4016cb7a1..dfcd5120d 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts
@@ -85,12 +85,16 @@ describe('channelIdProblem', () => {
expect(channelIdProblem('teams', '19%3aabc%40thread.tacv2')).toMatch(/%3a/);
});
+ it('takes a Slack id with no digits as pasted, but not a channel’s name typed in lower case', () => {
+ expect(channelIdProblem('slack', 'CABCDEFGHJ')).toBeNull();
+ expect(channelIdProblem('slack', 'general')).toMatch(/starts with C or G/);
+ expect(channelIdProblem('slack', 'cabcdefghj')).toMatch(/starts with C or G/);
+ });
+
it('takes an id differing only in case or surrounding space as meant', () => {
expect(channelIdProblem('slack', ' c0123abcd ')).toBeNull();
expect(normalizedChannelId('slack', ' c0123abcd ')).toBe('C0123ABCD');
- expect(normalizedChannelId('mattermost', MATTERMOST_ID.toUpperCase())).toBe(
- MATTERMOST_ID
- );
+ expect(normalizedChannelId('mattermost', MATTERMOST_ID.toUpperCase())).toBe(MATTERMOST_ID);
// Teams ids are left as pasted, but for the space around them.
expect(normalizedChannelId('teams', ' 19:[email protected] ')).toBe('19:[email protected]');
});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts
index 47f78f643..a090306ee 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts
@@ -74,13 +74,15 @@ export function optionsForBridge(
): RoomCreateOptions {
if (bridge === null) return options;
const offered = new Set(channelChoiceCards(bridge).map((card) => card.value));
- const choice =
- options.channel.kind === 'existing'
- ? 'existing'
- : options.channel.private
- ? 'private'
- : 'public';
- return offered.has(choice) ? options : { ...options, channel: { kind: 'new', private: false } };
+ return offered.has(channelChoiceOf(options))
+ ? options
+ : { ...options, channel: { kind: 'new', private: false } };
+}
+
+/** The channel choice a set of options holds. */
+export function channelChoiceOf(options: RoomCreateOptions): ChannelChoice {
+ if (options.channel.kind === 'existing') return 'existing';
+ return options.channel.private ? 'private' : 'public';
}
/**
@@ -94,7 +96,12 @@ export function channelIdProblem(bridgeType: string, id: string): string | null
const value = normalizedChannelId(bridgeType, id);
if (value === '') return null;
const shape = CHANNEL_ID_SHAPE[bridgeType];
- return shape && !shape.pattern.test(value) ? shape.problem : null;
+ if (!shape) return null;
+ if (!shape.pattern.test(value)) return shape.problem;
+ // Slack ids usually carry digits but need not. One with none is taken only as
+ // pasted, in capitals: typed in lower case it is a channel's name ("general").
+ if (bridgeType === 'slack' && !/\d/.test(value) && /[a-z]/.test(id)) return shape.problem;
+ return null;
}
/**
@@ -111,8 +118,7 @@ export function normalizedChannelId(bridgeType: string, id: string): string {
const CHANNEL_ID_SHAPE: Record<string, { pattern: RegExp; problem: string }> = {
slack: {
- // Letters and digits, always some digits: so a channel's name (GENERAL) is not taken for one.
- pattern: /^[CG](?=[A-Z0-9]*\d)[A-Z0-9]{6,}$/,
+ pattern: /^[CG][A-Z0-9]{6,}$/,
problem:
'A Slack channel id starts with C or G, like C0123ABCD. It is at the bottom of the channel’s details.',
},
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 b7fc7624f..e25c6ecd3 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
@@ -18,6 +18,8 @@ const form = {
agentIds: ['a1'],
memberUserIds: ['u2'],
requestId: 'req',
+ bridgeType: null,
+ options: DEFAULT_ROOM_OPTIONS,
};
describe('roomCreateRequest', () => {
@@ -60,6 +62,7 @@ describe('roomCreateRequest', () => {
// A new public channel and the server's default access, as before.
channel: { kind: 'new', private: false },
groupId: null,
+ access: null,
},
});
});
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 3fafd7946..32b5a3a1f 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
@@ -27,8 +27,8 @@ export type RoomCreateRequest =
agentIds: string[];
channel: NewRoomChannel;
groupId: string | null;
- /** Absent leaves the server's default. */
- access?: RoomAccess;
+ /** Null leaves the server's default. */
+ access: RoomAccess | null;
};
};
@@ -51,8 +51,8 @@ export function roomCreateRequest(form: {
workspaceId: string;
/** Null for Switch Console. */
bridgeId: string | null;
- /** The chosen app's platform, so an existing channel's id is sent as it writes it. */
- bridgeType?: string;
+ /** The chosen app's platform, so an existing channel's id is sent as it writes it; null for Switch Console. */
+ bridgeType: string | null;
name: string;
description: string;
instructions: string;
@@ -61,7 +61,7 @@ export function roomCreateRequest(form: {
memberUserIds: string[];
requestId: string;
/** A bridged room's More options; a Switch Console room has none. */
- options?: RoomCreateOptions;
+ options: RoomCreateOptions;
}): RoomCreateRequest {
const name = form.name.trim();
const agentIds = [...new Set(form.agentIds)];
@@ -87,7 +87,7 @@ export function roomCreateRequest(form: {
instructions: form.instructions.trim() || undefined,
bridgeId: form.bridgeId,
agentIds,
- ...roomOptionsParams(form.options ?? DEFAULT_ROOM_OPTIONS, form.bridgeType ?? ''),
+ ...roomOptionsParams(form.options, form.bridgeType ?? ''),
},
};
}
@@ -103,7 +103,7 @@ function roomOptionsParams(options: RoomCreateOptions, bridgeType: string) {
return {
channel,
groupId: options.groupId,
- ...(options.access ? { access: options.access } : {}),
+ access: options.access,
};
}
diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
index accd2ea9e..0e44b4fa5 100644
--- a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
@@ -1204,12 +1204,12 @@ export type CreateRoomParams = {
/** Switch agent ids to add as members. May be empty — a room is valid with
* no agents, and members can be invited later. */
agentIds: string[];
- /** The bridged room's channel: a new one, public unless asked, or an existing one by its id. */
- channel?: NewRoomChannel;
- /** The group to file the room under; none when absent. */
- groupId?: string | null;
- /** Who may see and change the room; the server's default when absent. */
- access?: RoomAccess;
+ /** The bridged room's channel: a new one, or an existing one by its id. Null for a new public one. */
+ channel: NewRoomChannel | null;
+ /** The group to file the room under, or null for none. */
+ groupId: string | null;
+ /** Who may see and change the room, or null for the server's default. */
+ access: RoomAccess | null;
};
/** A bridged room's channel, as the New room dialog asks for it. */