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
Library: count the rooms you cannot open, and take the server's word on detaching
Simon Flackd7a3c17323b8
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.test.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.test.tsindex 28aaa50e9..425fd8d04 100644--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.test.ts@@ -145,6 +145,31 @@ describe('reading the library', () => {expect(doc).toMatchObject({ id: 'doc-1', content: '# Style' });});+ it('keeps the count of rooms the owner cannot open, and leaves it unset when the server does not say', async () => {+ fetchMock.mockImplementation(async () =>+ jsonResponse([+ { ...REFERENCE, hidden_rooms_count: 2 },+ { ...REFERENCE, id: 'ref-2' },+ ])+ );+ const [counted, older] = await fetchLibraryItems(SERVER, 'references');+ expect(counted.hiddenRoomsCount).toBe(2);+ expect(older).not.toHaveProperty('hiddenRoomsCount');+ });++ it('keeps the server’s word on detaching from each room, when it gives one', async () => {+ fetchMock.mockImplementation(async () =>+ jsonResponse([+ { room_id: 'room-1', room_name: 'design', can_unlink: false },+ { room_id: 'room-2', room_name: 'support' },+ ])+ );+ expect(await fetchLibraryItemRooms(SERVER, 'references', 'ref-1')).toEqual([+ { roomId: 'room-1', roomName: 'design', canUnlink: false },+ { roomId: 'room-2', roomName: 'support' },+ ]);+ });+it('lists the rooms an item is in', async () => {fetchMock.mockImplementation(async () =>jsonResponse([{ room_id: 'room-1', room_name: 'design' }])diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.tsindex 9a54aacb5..c3b37485a 100644--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.ts+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/library-client.ts@@ -30,6 +30,7 @@ type LibraryItemJson = {value?: { urls?: unknown };content?: string;attached_rooms_count?: number;+ hidden_rooms_count?: number;packages?: string[];scope?: 'global' | 'room';created_at: string;@@ -57,6 +58,7 @@ export function mapLibraryItem(kind: LibraryKind, r: LibraryItemJson): LibraryIttypeLabel: kind === 'references' ? (r.type_display_name ?? r.type ?? null) : null,urls,attachedRoomsCount: r.attached_rooms_count ?? 0,+ ...(r.hidden_rooms_count !== undefined ? { hiddenRoomsCount: r.hidden_rooms_count } : {}),packageIds: r.packages ?? [],createdAt: r.created_at,};@@ -161,10 +163,13 @@ export async function fetchLibraryItemRooms(id: string): Promise<LibraryItemRoom[]> {const res = await gatewayFetch(server, `${itemPath(kind, id)}/rooms`, { authenticated: true });- return ((await res.json()) as { room_id: string; room_name: string }[]).map((r) => ({- roomId: r.room_id,- roomName: r.room_name,- }));+ return ((await res.json()) as { room_id: string; room_name: string; can_unlink?: boolean }[]).map(+ (r) => ({+ roomId: r.room_id,+ roomName: r.room_name,+ ...(r.can_unlink !== undefined ? { canUnlink: r.can_unlink } : {}),+ })+ );}/** The types a new reference may be given: Switch's own, then those people wrote. */diff --git a/console/apps/switch-console-desktop/src/renderer/features/library/library-item-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/library/library-item-view.tsxindex fccdf0383..a14318cb7 100644--- a/console/apps/switch-console-desktop/src/renderer/features/library/library-item-view.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/library/library-item-view.tsx@@ -51,6 +51,7 @@ import { changesOf, formOf, formProblem, type LibraryForm } from './library-formimport { LibraryItemFields } from './library-item-form';import {accessOf,+ hiddenRoomsText,KIND_TEXT,LIBRARY_ACCESS_OPTIONS,libraryPermissions,@@ -382,6 +383,8 @@ const RoomsSection = observer(function RoomsSection({});const readable = useReadableRoomsInWorkspace(workspaceId);const summaries = new Map(readable.map((room) => [room.id, room]));+ // Rooms it is in that you cannot open: counted for its owner and admins, never named.+ const hidden = item.hiddenRoomsCount ?? 0;const [picking, setPicking] = useState(false);const [busy, setBusy] = useState<string | null>(null);const [error, setError] = useState<string | null>(null);@@ -431,41 +434,50 @@ const RoomsSection = observer(function RoomsSection({</p>) : rooms.data.length === 0 ? (<p className="text-sm text-foreground-muted">- Not attached to any room you can see. Attach it and the agents there can use it.+ {hidden > 0+ ? `Only in ${hiddenRoomsText(hidden)}.`+ : 'Not attached to any room you can see. Attach it and the agents there can use it.'}</p>) : (- <List>- {rooms.data.map((room) => {- const summary = summaries.get(room.roomId);- const mayDetach =- summary !== undefined &&- switchRoomsStore.roomPermissions(workspaceId, summary).canUnlink;- return (- <div key={room.roomId} className="flex items-center gap-2 px-3.5 py-2.5">- <button- type="button"- className="flex min-w-0 flex-1 cursor-pointer items-center gap-3 text-left"- onClick={() => void openRoom(room.roomId)}- >- <DoorOpen className="size-4 shrink-0 text-foreground-muted" />- <span className="truncate text-sm text-foreground">{room.roomName}</span>- </button>- {mayDetach && (- <Button- variant="ghost"- size="icon-xs"- aria-label={`Detach from ${room.roomName}`}- title={`Detach from ${room.roomName}`}- disabled={busy === room.roomId}- onClick={() => void detach(room.roomId, room.roomName)}+ <>+ <List>+ {rooms.data.map((room) => {+ // The server says per room; an older one leaves it to the room's own rule.+ const summary = summaries.get(room.roomId);+ const mayDetach =+ room.canUnlink ??+ (summary !== undefined &&+ switchRoomsStore.roomPermissions(workspaceId, summary).canUnlink);+ return (+ <div key={room.roomId} className="flex items-center gap-2 px-3.5 py-2.5">+ <button+ type="button"+ className="flex min-w-0 flex-1 cursor-pointer items-center gap-3 text-left"+ onClick={() => void openRoom(room.roomId)}>- {busy === room.roomId ? <Loader2 className="animate-spin" /> : <X />}- </Button>- )}- </div>- );- })}- </List>+ <DoorOpen className="size-4 shrink-0 text-foreground-muted" />+ <span className="truncate text-sm text-foreground">{room.roomName}</span>+ </button>+ {mayDetach && (+ <Button+ variant="ghost"+ size="icon-xs"+ aria-label={`Detach from ${room.roomName}`}+ title={`Detach from ${room.roomName}`}+ disabled={busy === room.roomId}+ onClick={() => void detach(room.roomId, room.roomName)}+ >+ {busy === room.roomId ? <Loader2 className="animate-spin" /> : <X />}+ </Button>+ )}+ </div>+ );+ })}+ </List>+ {hidden > 0 && (+ <p className="text-xs text-foreground-muted">And {hiddenRoomsText(hidden)}.</p>+ )}+ </>)}{error !== null && <p className="text-xs text-destructive">{error}</p>}{picking && (diff --git a/console/apps/switch-console-desktop/src/renderer/features/library/library-modals.tsx b/console/apps/switch-console-desktop/src/renderer/features/library/library-modals.tsxindex 1e035e35e..0487da268 100644--- a/console/apps/switch-console-desktop/src/renderer/features/library/library-modals.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/library/library-modals.tsx@@ -17,7 +17,7 @@ import { ModalLayout } from '@renderer/lib/ui/modal-layout';import type { LibraryItem, LibraryKind } from '@shared/core/switch-servers/library';import { emptyForm, formProblem, inputOf, type LibraryForm } from './library-form';import { LibraryItemFields } from './library-item-form';-import { KIND_TEXT } from './library-model';+import { hiddenRoomsText, KIND_TEXT } from './library-model';import { invalidateLibrary, libraryRoomsKey, referenceTypesKey } from './library-queries';type NewProps = BaseModalProps<LibraryItem> & { workspaceId: string; kind: LibraryKind };@@ -103,7 +103,7 @@ export function NewLibraryItemModal({ workspaceId, kind, onSuccess, onClose }: Ntype DeleteProps = BaseModalProps<void> & {workspaceId: string;- item: Pick<LibraryItem, 'id' | 'kind' | 'name' | 'packageIds'>;+ item: Pick<LibraryItem, 'id' | 'kind' | 'name' | 'packageIds' | 'hiddenRoomsCount'>;};/**@@ -128,6 +128,8 @@ export function DeleteLibraryItemModal({ workspaceId, item, onSuccess, onClose }(id) => packages.data?.find((p) => p.id === id)?.name ?? 'a package you cannot see');const noun = KIND_TEXT[item.kind].noun;+ // Rooms it is in that you cannot open: the server counts them for its owner, never names them.+ const hidden = item.hiddenRoomsCount ?? 0;const remove = async () => {setDeleting(true);@@ -179,8 +181,13 @@ export function DeleteLibraryItemModal({ workspaceId, item, onSuccess, onClose }) : rooms.data.length > 0 ? (<WhatItLeavestitle="It is removed from these rooms:"- names={rooms.data.map((r) => r.roomName)}+ names={[+ ...rooms.data.map((r) => r.roomName),+ ...(hidden > 0 ? [`and ${hiddenRoomsText(hidden)}`] : []),+ ]}/>+ ) : hidden > 0 ? (+ <p className="text-sm text-foreground">It is removed from {hiddenRoomsText(hidden)}.</p>) : (<p className="text-sm text-foreground-muted">It is not attached to any room you can see.diff --git a/console/apps/switch-console-desktop/src/renderer/features/library/library-model.ts b/console/apps/switch-console-desktop/src/renderer/features/library/library-model.tsindex 1e9676cbe..821708b8d 100644--- a/console/apps/switch-console-desktop/src/renderer/features/library/library-model.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/library/library-model.ts@@ -142,6 +142,11 @@ export function ownerText(return item.ownerName ? `Owned by ${item.ownerName}` : null;}+/** The rooms a viewer cannot open, which the server counts but never names. */+export function hiddenRoomsText(count: number): string {+ return count === 1 ? '1 private room you can’t open' : `${count} private rooms you can’t open`;+}+export function roomsText(count: number): string {return count === 0 ? 'In no rooms' : count === 1 ? 'In 1 room' : `In ${count} rooms`;}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/library-view.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/library-view.test.tsxindex 11039e2df..8230fd809 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/library-view.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/library-view.test.tsx@@ -79,7 +79,9 @@ vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({}));import { libraryItemView } from '@renderer/features/library/library-item-view';+import { DeleteLibraryItemModal } from '@renderer/features/library/library-modals';import { libraryView } from '@renderer/features/library/library-view';+import { Dialog, DialogContent } from '@renderer/lib/ui/dialog';function item(over: Partial<LibraryItem>): LibraryItem {return {@@ -308,6 +310,34 @@ describe('an item’s page', () => {});});+ it('counts the rooms you cannot open without naming them', async () => {+ state.item = item({ hiddenRoomsCount: 2 });+ await render(libraryItemView.MainPanel);+ expect(container.querySelector('[aria-label="Rooms"]')?.textContent).toContain(+ 'And 2 private rooms you can’t open.'+ );+ });++ it('says so when every room it is in is one you cannot open', async () => {+ state.item = item({ hiddenRoomsCount: 1 });+ state.rooms = [];+ await render(libraryItemView.MainPanel);+ expect(container.querySelector('[aria-label="Rooms"]')?.textContent).toContain(+ 'Only in 1 private room you can’t open.'+ );+ });++ it('follows the server on who may detach from each room', async () => {+ state.item = item({});+ state.rooms = [+ { roomId: 'room-1', roomName: 'design', canUnlink: false },+ { roomId: 'room-2', roomName: 'support', canUnlink: true },+ ] as never;+ await render(libraryItemView.MainPanel);+ expect(container.querySelector('[aria-label="Detach from design"]')).toBeNull();+ expect(container.querySelector('[aria-label="Detach from support"]')).not.toBeNull();+ });+it('renders a document’s content as markdown', async () => {state.params = { serverId: 'srv', kind: 'documents', itemId: 'doc-1' };state.item = {@@ -321,3 +351,32 @@ describe('an item’s page', () => {expect(content.querySelector('strong')?.textContent).toBe('plain');});});++describe('deleting', () => {+ const renderDelete = (over: Partial<LibraryItem>) =>+ render(() => (+ <Dialog open>+ <DialogContent>+ <DeleteLibraryItemModal+ workspaceId="ws"+ item={item(over)}+ onSuccess={() => {}}+ onClose={() => {}}+ />+ </DialogContent>+ </Dialog>+ ));+ const dialogText = () => document.querySelector('[data-slot="dialog-content"]')?.textContent;++ it('names the rooms it leaves, and counts those you cannot open', async () => {+ await renderDelete({ hiddenRoomsCount: 2 });+ expect(dialogText()).toContain('design');+ expect(dialogText()).toContain('and 2 private rooms you can’t open');+ });++ it('counts the rooms you cannot open when they are all it is in', async () => {+ state.rooms = [];+ await renderDelete({ hiddenRoomsCount: 1 });+ expect(dialogText()).toContain('It is removed from 1 private room you can’t open.');+ });+});diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-servers/library.ts b/console/apps/switch-console-desktop/src/shared/core/switch-servers/library.tsindex a61531d30..f0ad92575 100644--- a/console/apps/switch-console-desktop/src/shared/core/switch-servers/library.ts+++ b/console/apps/switch-console-desktop/src/shared/core/switch-servers/library.ts@@ -30,6 +30,12 @@ export type LibraryItem = {/** A reference's links; empty for a document. */urls: string[];attachedRoomsCount: number;+ /**+ * Of those, the rooms the viewer may not open, which are never named to+ * them. Sent only to whoever may manage the item, by a server that counts+ * them; undefined from an older one.+ */+ hiddenRoomsCount?: number;/** The packages it is in, by id. */packageIds: string[];createdAt: string;@@ -74,4 +80,9 @@ export type LibraryDeleteResult = {};/** A room a library item is attached to. */-export type LibraryItemRoom = { roomId: string; roomName: string };+export type LibraryItemRoom = {+ roomId: string;+ roomName: string;+ /** Whether the viewer may detach the item from this room, when the server says. */+ canUnlink?: boolean;+};