Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Room page: answer Petr's review
Simon Flack0d8d610f841c
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.tsindex d1eb3d727..9a07235dc 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@@ -3324,9 +3324,8 @@ function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {isConsoleChat: r.is_console_chat ?? false,archived: r.archived,createdAt: r.created_at,- ...(r.write_visibility !== undefined- ? { writeVisibility: visibilityOf(r.write_visibility) }- : {}),+ // The same reading as a room's detail, so the list and the room page offer the same changes.+ writeVisibility: visibilityOf(r.write_visibility),...(r.can_write !== undefined && r.can_manage !== undefined? {serverPermissions: {@@ -5111,6 +5110,7 @@ type ResourceJson = {scope?: 'global' | 'room';created_by_agent_name?: string | null;can_remove?: boolean;+ content?: string;};function mapResource(kind: RoomResourceKind, r: ResourceJson): RoomResource {@@ -5128,6 +5128,7 @@ function mapResource(kind: RoomResourceKind, r: ResourceJson): RoomResource {createdByAgentName: r.created_by_agent_name ?? null,packageIds: r.packages ?? [],...(r.can_remove !== undefined ? { canRemove: r.can_remove } : {}),+ ...(kind === 'documents' && typeof r.content === 'string' ? { content: r.content } : {}),};}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.tsindex 2f65a38ba..b774e389e 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@@ -1022,7 +1022,6 @@ export const workspacesController = createRPCController({listArchivedRooms: (params: { workspaceId: string }): Promise<RemoteRoomSummary[]> =>withWorkspaceSession(params.workspaceId, (server) => fetchArchivedRooms(server)),- /** The messaging-app usernames Switch knows on one bridge, for inviting people to a room. *//** What is attached to a room, of one kind. */listRoomResources: (params: {workspaceId: string;@@ -1090,6 +1089,7 @@ export const workspacesController = createRPCController({removeLinkedRoom(server, params.roomId, params.targetRoomId)),+ /** The messaging-app usernames Switch knows on one bridge, for inviting people to a room. */listBridgeUserNames: (params: { workspaceId: string; bridgeId: string }): Promise<string[]> =>withWorkspaceSession(params.workspaceId, (server) =>fetchBridgeUserNames(server, params.bridgeId)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.tsxindex 2520a8110..c968405b4 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@@ -1,4 +1,4 @@-import { useQuery, useQueryClient } from '@tanstack/react-query';+import { useQueryClient } from '@tanstack/react-query';import { Archive, FileText, Loader2, Lock, RefreshCw } from 'lucide-react';import { observer } from 'mobx-react-lite';import { useState } from 'react';@@ -22,7 +22,7 @@ import { type ChatSummary } from '@shared/core/chats/chats';import type { RemoteRoomDetail } from '@shared/core/switch-servers/switch-servers';import { channelOnDeleteSummary } from './room-delete-wording';import { roomTitle } from './room-labels';-import { roomDetailKey } from './room-participants';+import { roomDetailKey, useRoomDetail } from './room-participants';import {AccessAndGroupFields,ArchiveRoomSection,@@ -31,13 +31,9 @@ import {} from './room-settings-sections';/** One room read from its server; `workspaceId` is null until the room list has loaded. */-function useRoomDetail(roomId: string) {+function useRoomInWorkspace(roomId: string) {const workspaceId = switchRoomsStore.roomWorkspaceId(roomId);- const query = useQuery({- queryKey: roomDetailKey(workspaceId ?? '', roomId),- queryFn: () => rpc.workspaces.getRoomDetail({ workspaceId: workspaceId as string, roomId }),- enabled: workspaceId !== null && !opensAsConsoleChat(roomId),- });+ const query = useRoomDetail(workspaceId, roomId, !opensAsConsoleChat(roomId));return { workspaceId, query };}@@ -54,17 +50,17 @@ const ChatConfiguration = observer(function ChatConfiguration({chat: ChatSummary;}) {const workspaceId = switchRoomsStore.roomWorkspaceId(chat.roomId) ?? workspacesStore.activeId;- const detail = useQuery({- queryKey: roomDetailKey(workspaceId ?? '', chat.roomId),- queryFn: () =>- rpc.workspaces.getRoomDetail({ workspaceId: workspaceId as string, roomId: chat.roomId }),- enabled: workspaceId !== null && chat.canManage,- });+ const detail = useRoomDetail(workspaceId, chat.roomId, chat.canManage);return (<div className="h-full overflow-y-auto"><div className="mx-auto flex w-full max-w-[880px] flex-col gap-8 px-10 py-8">{workspaceId !== null && detail.data && (- <GeneralSection key={chat.roomId} workspaceId={workspaceId} room={detail.data} />+ <GeneralSection+ key={chat.roomId}+ workspaceId={workspaceId}+ room={detail.data}+ readOnly={false}+ />)}{detail.isError && (<p className="text-xs text-foreground-muted">@@ -121,7 +117,7 @@ export const RoomConfigurationPanel = observer(function RoomConfigurationPanel({}: {roomId: string;}) {- const { workspaceId, query } = useRoomDetail(roomId);+ const { workspaceId, query } = useRoomInWorkspace(roomId);const chat = chatsStore.chat(roomId);if (chat && chatsStore.serverId && isConsoleGroupChatSummary(chat)) {@@ -306,12 +302,12 @@ type SaveState = { phase: 'idle' | 'saving' | 'saved' } | { phase: 'failed'; mesfunction GeneralSection({workspaceId,room,- readOnly = false,+ readOnly,}: {workspaceId: string;room: RemoteRoomDetail;/** For someone who may read the room but not change it: the fields show, and do not take edits. */- readOnly?: boolean;+ readOnly: boolean;}) {const queryClient = useQueryClient();const savedName = room.name;diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-participants.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-participants.tsxindex 0223e2aa6..1566994e0 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-participants.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-participants.tsx@@ -1,6 +1,8 @@+import { useQuery } from '@tanstack/react-query';import { agentsStore } from '@renderer/features/locations/stores/agents-store';import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';import { AgentAvatar } from '@renderer/lib/components/agent-avatar';+import { rpc } from '@renderer/lib/ipc';import { cn } from '@renderer/utils/utils';import { agentInitials } from '@shared/core/agents/agent-avatar';import {@@ -20,6 +22,19 @@ export function roomDetailKey(workspaceId: string, roomId: string) {return ['remote-room-detail', workspaceId, roomId] as const;}+/**+ * One room's detail from its server, under {@link roomDetailKey}, so every+ * panel reading the room sees what a save writes back. Off until the room's+ * workspace is known, and while `enabled` is false.+ */+export function useRoomDetail(workspaceId: string | null, roomId: string, enabled: boolean) {+ return useQuery({+ queryKey: roomDetailKey(workspaceId ?? '', roomId),+ queryFn: () => rpc.workspaces.getRoomDetail({ workspaceId: workspaceId as string, roomId }),+ enabled: workspaceId !== null && enabled,+ });+}+/** A person's initials disc: people have no picture in Switch. */export function PersonMark({ name, size }: { name: string; size: 'sm' | 'md' }) {return (diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsxindex 9898d0aa7..8e709aa54 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx@@ -20,7 +20,7 @@ import {} from '@renderer/lib/ui/dialog';import { Input } from '@renderer/lib/ui/input';import type { RoomResource, RoomResourceKind } from '@shared/core/switch-servers/switch-servers';-import { roomDetailKey } from './room-participants';+import { useRoomDetail } from './room-participants';import { attachableResources, resourcesByOrigin } from './room-resources';const KIND_LABEL: Record<RoomResourceKind, { title: string; noun: string; none: string }> = {@@ -55,11 +55,7 @@ export const RoomResourcesPanel = observer(function RoomResourcesPanel({const chat = chatsStore.chat(roomId);const workspaceId =switchRoomsStore.roomWorkspaceId(roomId) ?? (chat ? workspacesStore.activeId : null);- const detail = useQuery({- queryKey: roomDetailKey(workspaceId ?? '', roomId),- queryFn: () => rpc.workspaces.getRoomDetail({ workspaceId: workspaceId as string, roomId }),- enabled: workspaceId !== null,- });+ const detail = useRoomDetail(workspaceId, roomId, true);if (workspaceId === null) {return <Centered>This room’s workspace is still loading.</Centered>;}@@ -192,7 +188,8 @@ const ResourceSection = observer(function ResourceSection({<ResourceRowkey={resource.id}resource={resource}- via={resource.packageIds.map((id) => packageNames.get(id) ?? 'a package')}+ // The server lists every package holding it; only those attached here brought it.+ via={resource.packageIds.flatMap((id) => packageNames.get(id) ?? [])}onOpen={resource.urls[0]? () => void openExternalUrl(resource.urls[0]!, 'Could not open the link')@@ -460,9 +457,21 @@ function DocumentDialog({document: RoomResource;onClose: () => void;}) {+ // The room's listing already carries the content; an older server's may not.const content = useQuery({queryKey: ['room-document', workspaceId, roomId, document.id],queryFn: () => rpc.workspaces.getRoomDocument({ workspaceId, roomId, documentId: document.id }),+ enabled: document.content === undefined,+ ...(document.content !== undefined+ ? {+ initialData: {+ id: document.id,+ name: document.name,+ description: document.description,+ content: document.content,+ },+ }+ : {}),});return (<Dialog open onOpenChange={(open) => !open && onClose()}>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.tsxindex f597d4bd4..9bd11655b 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@@ -27,11 +27,7 @@ import {visibilityForAccess,} from '@shared/core/switch-servers/switch-servers';import { useArchiveRoomConfirm } from './archive-room-confirm';--/** The query key the room page reads one room under; shared with `room-configuration-panel`. */-function detailKey(workspaceId: string, roomId: string) {- return ['remote-room-detail', workspaceId, roomId] as const;-}+import { roomDetailKey } from './room-participants';/*** The room's read and write access as people read them. Write access is who@@ -94,7 +90,7 @@ export const AccessAndGroupFields = observer(function AccessAndGroupFields({) {setState({ phase: 'saving' });try {- queryClient.setQueryData(detailKey(workspaceId, room.id), await action());+ queryClient.setQueryData(roomDetailKey(workspaceId, room.id), await action());setState({ phase: 'saved' });void refreshSidebarRoomState(true);} catch (cause) {@@ -215,7 +211,7 @@ export const RolesSection = observer(function RolesSection({const [error, setError] = useState<string | null>(null);function storeRoles(roles: RemoteRoomRole[]) {- queryClient.setQueryData<RemoteRoomDetail>(detailKey(workspaceId, room.id), (current) =>+ queryClient.setQueryData<RemoteRoomDetail>(roomDetailKey(workspaceId, room.id), (current) =>current ? { ...current, roles } : current);}@@ -426,6 +422,8 @@ function ConfirmIconButton({size="xs"className="border-red-500/40 text-red-500 hover:bg-red-500/10 hover:text-red-500"disabled={busy}+ // Focus moves here as the trash button goes, so clicking anywhere else disarms it.+ autoFocusonBlur={() => !busy && setArmed(false)}onClick={async () => {setBusy(true);@@ -517,7 +515,7 @@ export const ArchiveRoomSection = observer(function ArchiveRoomSection({roomId: room.id,archived: !room.archived,});- queryClient.setQueryData(detailKey(workspaceId, room.id), updated);+ queryClient.setQueryData(roomDetailKey(workspaceId, room.id), updated);await switchRoomsStore.refreshRoomState();void refreshSidebarRoomState(true);void queryClient.invalidateQueries({ queryKey: ['archived-rooms', workspaceId] });diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-side-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-side-panel.tsxindex b03f478ea..fb6f46da8 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-side-panel.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-side-panel.tsx@@ -38,7 +38,13 @@ import type { RemoteRoomDetail } from '@shared/core/switch-servers/switch-serverimport { AddAgentPanel, AddPeoplePanel, ChatAddParticipantPanel } from './room-add-participants';import { roomAgentPresence } from './room-agent-presence';import { roomInviteability } from './room-membership';-import { AgentMark, agentNameFor, PersonMark, roomDetailKey } from './room-participants';+import {+ AgentMark,+ agentNameFor,+ PersonMark,+ roomDetailKey,+ useRoomDetail,+} from './room-participants';const TONE_CLASS = {live: 'bg-foreground-success',@@ -92,11 +98,7 @@ export const RoomSidePanel = observer(function RoomSidePanel({ roomId }: { roomIconst [adding, setAdding] = useState<'agents' | 'people' | null>(null);const [error, setError] = useState<string | null>(null);// Anyone taking part may read the room, so this answers for a chat's members too.- const detail = useQuery({- queryKey: roomDetailKey(workspaceId ?? '', roomId),- queryFn: () => rpc.workspaces.getRoomDetail({ workspaceId: workspaceId as string, roomId }),- enabled: workspaceId !== null,- });+ const detail = useRoomDetail(workspaceId, roomId, true);const membersKey = chat && serverId ? chatMembersQueryKey(serverId, chat) : ['no-chat-members'];const members = useQuery({queryKey: membersKey,@@ -105,6 +107,8 @@ export const RoomSidePanel = observer(function RoomSidePanel({ roomId }: { roomI});const room = detail.data ?? null;+ // A room that could not be read is not an empty one: say so, rather than "no agents yet".+ const unreadable = !consoleChat && detail.isError;const agentIds = chat ? chat.agents.map((agent) => agent.id) : (room?.agentIds ?? []);const chatNames = new Map((chat?.agents ?? []).map((agent) => [agent.id, chatAgentLabel(agent)]));const people = consoleChat@@ -197,7 +201,9 @@ export const RoomSidePanel = observer(function RoomSidePanel({ roomId }: { roomIonAdd={controls.addAgents}addLabel={consoleChat ? 'Add participants' : 'Add agents'}>- {agentIds.length === 0 ? (+ {unreadable ? (+ <Note>{failureText(detail.error, 'Could not read who is in this room.')}</Note>+ ) : agentIds.length === 0 ? (<Note>No agents in this room yet.</Note>) : (agentIds.map((agentId) => (@@ -223,7 +229,7 @@ export const RoomSidePanel = observer(function RoomSidePanel({ roomId }: { roomIonAdd={controls.addPeople}addLabel="Add people">- {people.length === 0 ? (+ {unreadable ? null : people.length === 0 ? (<Note>{consoleChat ? 'Nobody else is here yet.' : 'Nobody has been seen here yet.'}</Note>) : (people.map((person) => (@@ -314,7 +320,7 @@ const AgentRow = observer(function AgentRow({serverId: string | null;name: string | null;status: string | undefined;- /** The room's roles; the one this agent holds is shown beside its status. */+ /** The room's roles; those this agent holds are shown beside its status. */roles: RemoteRoomDetail['roles'];controls: RosterControls;act: (action: () => Promise<void>, fallback: string) => Promise<void>;@@ -326,10 +332,9 @@ const AgentRow = observer(function AgentRow({const own = (managed.data ?? []).find((agent) => agent.agentId === agentId) ?? null;const [busy, setBusy] = useState(false);const label = name ?? agentNameFor(agentId, workspaceId, remoteById);- // Roles name their holders by agent name, which is how the server reports them.- const role = roles.find((each) => each.heldBy.includes(label));+ const held = rolesHeldBy(roles, remoteById.get(agentId)?.name ?? null);const presence = roomAgentPresence(status);- const detail = [status === undefined ? null : presence.label, role?.name ?? null]+ const detail = [status === undefined ? null : presence.label, ...held].filter(Boolean).join(' · ');@@ -514,3 +519,13 @@ function Fold({const Note = ({ children }: { children: ReactNode }) => (<p className="px-2 py-1 text-xs text-foreground-muted">{children}</p>);++/**+ * The roles an agent holds. The server names a role's holders by the agent's+ * server-side name, so that is what is matched, never the name this install+ * shows (a local rename, or a chat's label); null holds nothing.+ */+export function rolesHeldBy(roles: RemoteRoomDetail['roles'], serverName: string | null): string[] {+ if (serverName === null) return [];+ return roles.filter((role) => role.heldBy.includes(serverName)).map((role) => role.name);+}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsxindex 5746860fc..3e9b4e22f 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx@@ -134,6 +134,32 @@ describe('the Resources tab', () => {expect(text).toContain('escalate to');});+ it('names only a package attached to this room as what brought an item in', async () => {+ listRoomResources.mockImplementation(async ({ kind }: { kind: keyof typeof RESOURCES }) =>+ kind === 'references'+ ? [{ ...RESOURCES.references[0], packageIds: ['pkg-elsewhere'] }]+ : RESOURCES[kind]+ );+ const el = await renderPanel();+ expect(el.textContent).toContain('Repo');+ expect(el.textContent).not.toContain('via');+ });++ it('opens a document from what the room listed, without fetching it again', async () => {+ listRoomResources.mockImplementation(async ({ kind }: { kind: keyof typeof RESOURCES }) =>+ kind === 'documents'+ ? [{ ...RESOURCES.documents[0], content: 'Read **this** first.' }]+ : RESOURCES[kind]+ );+ const el = await renderPanel();+ const open = [...el.querySelectorAll('button')].find((b) => b.textContent?.includes('Guide'))!;+ await act(async () => open.click());+ for (let i = 0; i < 4; i++) await act(async () => await Promise.resolve());+ expect(document.querySelector('[data-slot="dialog-content"]')?.textContent).toContain(+ 'Read **this** first.'+ );+ });+it('offers attaching, detaching, deleting and linking to someone who may change the room', async () => {const el = await renderPanel();expect(el.textContent).toContain('Attach reference');diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsxindex 07e832925..a064252a1 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx@@ -188,6 +188,31 @@ describe('room settings for someone who may write to the room', () => {expect(el.querySelector('[aria-label="Add people"]')).not.toBeNull();});+ it('shows every role an agent holds, matched on its name on the server', async () => {+ getRoomDetail.mockResolvedValue({+ ...ROOM,+ roles: [+ { name: 'reviewer', instructions: '', exclusive: false, heldBy: ['reviewer-bot'] },+ { name: 'lead', instructions: '', exclusive: true, heldBy: ['reviewer-bot'] },+ { name: 'scribe', instructions: '', exclusive: false, heldBy: ['someone-else'] },+ ],+ });+ const el = await renderPanel('side');+ await act(async () => await new Promise((resolve) => setTimeout(resolve, 0)));+ const text = el.textContent ?? '';+ expect(text).toContain('reviewer');+ expect(text).toContain('lead');+ expect(text).not.toContain('scribe');+ });++ it('says the room could not be read, rather than that it is empty', async () => {+ getRoomDetail.mockRejectedValue(new Error('Switch gateway returned 500'));+ const el = await renderPanel('side');+ expect(el.textContent).not.toContain('No agents in this room yet.');+ expect(el.textContent).not.toContain('Nobody has been seen here yet.');+ expect(el.querySelector('[aria-label="Add agents"]')).toBeNull();+ });+it('turns an agent’s join notification on from its menu in the side column', async () => {const el = await renderPanel('side');await click(el.querySelector<HTMLElement>('[aria-label="reviewer-bot in this room"]')!);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.tsindex bb6f1ddee..321d4786c 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@@ -1360,6 +1360,8 @@ export type RoomResource = {packageIds: string[];/** Whether the viewer may delete this room-scoped document, when the server says. */canRemove?: boolean;+ /** A document's content, when the listing carried it (a room's documents do). */+ content?: string;};/** A document read in full, through the room it is attached to. */