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): name a bridged room after its linked channel from Configuration

raullopez-sandbox585466f36629
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 19caf4111..44234748c 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
@@ -2938,6 +2938,7 @@ type RoomDetailJson = RoomSummaryJson & {
/** Absent from a server that predates it; kept absent rather than read as
* "no channel", so the delete dialog can say it does not know. */
channel_on_delete?: ChannelRetirement | null;
+ linked_channel_name?: string | null;
};
function mapRoomDetail(r: RoomDetailJson): RemoteRoomDetail {
@@ -2947,9 +2948,26 @@ function mapRoomDetail(r: RoomDetailJson): RemoteRoomDetail {
agentIds: r.agent_ids ?? [],
connectedUserNames: r.connected_user_names ?? [],
channelOnDelete: r.channel_on_delete,
+ linkedChannelName: r.linked_channel_name ?? null,
};
}
+/**
+ * Name a room after the channel it is linked to (`POST /rooms/{id}/sync-name`),
+ * so it follows the channel's renames from then on. The room's owner or an
+ * admin only; refused while Switch has not seen the channel's name.
+ */
+export async function syncRoomName(
+ server: SwitchServer,
+ roomId: string
+): Promise<RemoteRoomDetail> {
+ const res = await gatewayFetch(server, `/rooms/${encodeURIComponent(roomId)}/sync-name`, {
+ authenticated: true,
+ method: 'POST',
+ });
+ return mapRoomDetail((await res.json()) as RoomDetailJson);
+}
+
/** One room in full (`GET /rooms/{id}`) — what its configuration page reads. */
export async function fetchRoomDetail(
server: SwitchServer,
diff --git a/console/apps/switch-console-desktop/src/main/core/workspaces/controller.ts b/console/apps/switch-console-desktop/src/main/core/workspaces/controller.ts
index c605d06d5..1dc9012c0 100644
--- a/console/apps/switch-console-desktop/src/main/core/workspaces/controller.ts
+++ b/console/apps/switch-console-desktop/src/main/core/workspaces/controller.ts
@@ -75,6 +75,7 @@ import {
updateAgentDisplayName,
renameAgent,
updateAgentIcon,
+ syncRoomName,
updateRoom,
updateTemplate,
} from '@main/core/switch-servers/gateway-client';
@@ -145,6 +146,7 @@ import type {
TeamsTeamsResult,
UpdateBridgeParams,
UpdateBridgeResult,
+ SyncRoomNameParams,
UpdateRoomParams,
} from '@shared/core/switch-servers/switch-servers';
import type { UiEntryPoint } from '@shared/core/telemetry/reporting';
@@ -888,6 +890,12 @@ export const workspacesController = createRPCController({
* write access to the room needs the gateway's refusal, not a saved-looking
* field holding a value the server never took.
*/
+ /** Name a room after its linked channel. Refusals propagate in the gateway's own words. */
+ syncRoomName: (params: SyncRoomNameParams): Promise<RemoteRoomDetail> =>
+ withReachableWorkspaceSession(params.workspaceId, (server) =>
+ syncRoomName(server, params.roomId)
+ ),
+
updateRoom: (params: UpdateRoomParams): Promise<RemoteRoomDetail> =>
withReachableWorkspaceSession(params.workspaceId, (server) =>
updateRoom(server, params.roomId, {
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 8693d3768..3cdf2a5fb 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
@@ -670,6 +670,11 @@ function GeneralSection({ workspaceId, room }: { workspaceId: string; room: Remo
}}
/>
</Field>
+ <LinkedChannelName
+ workspaceId={workspaceId}
+ room={room}
+ onSynced={(updated) => setName(updated.name)}
+ />
<Field
label="Description"
@@ -715,6 +720,66 @@ function GeneralSection({ workspaceId, room }: { workspaceId: string; room: Remo
);
}
+/**
+ * The channel a bridged room is linked to, when it is called something else
+ * there, with a way for someone who manages the room to name it after the
+ * channel, which it then follows when the channel is renamed.
+ */
+const LinkedChannelName = observer(function LinkedChannelName({
+ workspaceId,
+ room,
+ onSynced,
+}: {
+ workspaceId: string;
+ room: RemoteRoomDetail;
+ onSynced: (updated: RemoteRoomDetail) => void;
+}) {
+ const queryClient = useQueryClient();
+ const [syncing, setSyncing] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const channel = room.linkedChannelName;
+ if (!channel || channel === room.name || `#${channel}` === room.name) return null;
+ const canSync = switchRoomsStore.canDeleteRoom(workspaceId, room);
+
+ async function sync() {
+ setSyncing(true);
+ setError(null);
+ try {
+ const updated = await rpc.workspaces.syncRoomName({ workspaceId, roomId: room.id });
+ queryClient.setQueryData(roomDetailKey(workspaceId, room.id), updated);
+ onSynced(updated);
+ void refreshSidebarRoomState(true);
+ void chatsStore.refreshSummaries();
+ } catch (cause) {
+ setError(failureText(cause, 'Could not name the room after its channel.'));
+ } finally {
+ setSyncing(false);
+ }
+ }
+
+ return (
+ <div className="-mt-2 flex flex-wrap items-center gap-2 text-xs text-foreground-muted">
+ <span>Linked channel: #{channel}</span>
+ {canSync && (
+ <Button
+ type="button"
+ size="xs"
+ variant="outline"
+ disabled={syncing}
+ onClick={() => void sync()}
+ >
+ {syncing ? 'Renaming…' : 'Use channel name'}
+ </Button>
+ )}
+ {error && (
+ <span role="alert" className="text-destructive">
+ {error}
+ </span>
+ )}
+ </div>
+ );
+});
+
/** Says where the edits stand, so an unsaved change is never silent. */
function SaveStatus({ state, dirty }: { state: SaveState; dirty: boolean }) {
if (state.phase === 'failed') {
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-configuration-save.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-configuration-save.test.tsx
index e851986e0..b638d31a1 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-configuration-save.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-configuration-save.test.tsx
@@ -15,6 +15,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
const updateRoom = vi.hoisted(() => vi.fn());
const getRoomDetail = vi.hoisted(() => vi.fn());
+const syncRoomName = vi.hoisted(() => vi.fn());
+const manages = vi.hoisted(() => ({ value: false }));
vi.hoisted(() => {
window.electronAPI ??= {
@@ -30,6 +32,7 @@ vi.mock('@renderer/lib/ipc', () => ({
workspaces: {
updateRoom,
getRoomDetail,
+ syncRoomName,
listAgents: vi.fn(() => Promise.resolve([])),
},
agents: { getAgents: vi.fn(() => Promise.resolve([])) },
@@ -40,7 +43,7 @@ vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
switchRoomsStore: {
roomWorkspaceId: () => 'ws-1',
roomServerId: () => 'server-1',
- canDeleteRoom: () => false,
+ canDeleteRoom: () => manages.value,
},
}));
@@ -75,6 +78,8 @@ beforeEach(() => {
);
getRoomDetail.mockReset();
getRoomDetail.mockResolvedValue(ROOM);
+ syncRoomName.mockReset();
+ manages.value = false;
});
afterEach(async () => {
@@ -219,4 +224,61 @@ describe('a room’s description and instructions', () => {
await type(el.querySelector<HTMLInputElement>('input[aria-label="Name"]')!, ' ');
expect(saveButton(el).disabled).toBe(true);
});
+ describe('a bridged room named apart from its channel', () => {
+ const BRIDGED = {
+ ...ROOM,
+ name: 'qa-overnight-adopted',
+ bridgeType: 'discord',
+ bridgeDisplayName: 'Discord',
+ linkedChannelName: 'qa-adopted-renamed',
+ };
+ const useButton = (el: HTMLElement) =>
+ [...el.querySelectorAll('button')].find((b) => b.textContent === 'Use channel name');
+
+ it('offers someone who manages it the channel’s name, and reads the new name everywhere', async () => {
+ manages.value = true;
+ getRoomDetail.mockResolvedValue(BRIDGED);
+ syncRoomName.mockResolvedValue({ ...BRIDGED, name: 'qa-adopted-renamed' });
+ const refreshSummaries = vi.spyOn(chatsStore, 'refreshSummaries').mockResolvedValue();
+ const el = await renderPanel();
+ expect(el.textContent).toContain('Linked channel: #qa-adopted-renamed');
+
+ await act(async () => useButton(el)!.click());
+ for (let i = 0; i < 5; i++) await act(async () => await Promise.resolve());
+
+ expect(syncRoomName).toHaveBeenCalledWith({ workspaceId: 'ws-1', roomId: 'room-1' });
+ expect(el.querySelector<HTMLInputElement>('input[aria-label="Name"]')!.value).toBe(
+ 'qa-adopted-renamed'
+ );
+ expect(refreshSidebarRoomState).toHaveBeenCalledWith(true);
+ expect(refreshSummaries).toHaveBeenCalled();
+ expect(el.textContent).not.toContain('Linked channel');
+ });
+
+ it('says the server’s refusal where the action is', async () => {
+ manages.value = true;
+ getRoomDetail.mockResolvedValue(BRIDGED);
+ syncRoomName.mockRejectedValue(
+ new Error('Switch has not seen the name of a channel linked to this room.')
+ );
+ const el = await renderPanel();
+ await act(async () => useButton(el)!.click());
+ for (let i = 0; i < 5; i++) await act(async () => await Promise.resolve());
+ expect(el.querySelector('[role="alert"]')?.textContent).toContain('has not seen the name');
+ });
+
+ it('shows the channel’s name, without the action, to someone who does not manage it', async () => {
+ getRoomDetail.mockResolvedValue(BRIDGED);
+ const el = await renderPanel();
+ expect(el.textContent).toContain('Linked channel: #qa-adopted-renamed');
+ expect(useButton(el)).toBeUndefined();
+ });
+
+ it('says nothing when the room is already called what its channel is', async () => {
+ manages.value = true;
+ getRoomDetail.mockResolvedValue({ ...BRIDGED, name: 'qa-adopted-renamed' });
+ const el = await renderPanel();
+ expect(el.textContent).not.toContain('Linked channel');
+ });
+ });
});
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 c7e812704..caef488ac 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
@@ -360,6 +360,8 @@ export type RemoteRoomDetail = RemoteRoomSummary & {
* Undefined from a server that predates the field, which says nothing about
* the channel either way. */
channelOnDelete?: ChannelRetirement | null;
+ /** The name of the platform channel the room is linked to, as Switch last saw it; null when it has not. */
+ linkedChannelName: string | null;
};
/** What deleting a room does to its platform channel when asked to retire it
@@ -378,6 +380,9 @@ export type RetireOutcome = {
/** The room fields Switch Console can change. Anything omitted is left alone;
* an empty string clears the field rather than leaving it. */
+/** Name a room after the channel it is linked to. */
+export type SyncRoomNameParams = { workspaceId: string; roomId: string };
+
export type UpdateRoomParams = {
workspaceId: string;
roomId: string;