Skip to content

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

Follow the room's can_write and can_manage on the auto-route toggle

agent-runner353791716b5dd84
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-auto-route-section.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-auto-route-section.tsx
index d9b09ea1c..aacf4d73e 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-auto-route-section.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-auto-route-section.tsx
@@ -25,14 +25,17 @@ const NO_TRIAGE = '';
*
* Shows what the server says: the switch and picker move only once the
* server has answered, and a refusal leaves them as they were with the
- * reason beside them. Only the room's owner and the workspace's admins may
- * change it, so for anyone else both are shown but held.
+ * reason beside them. Anyone who may write to the room may turn it on or
+ * off; naming the triage agent takes the room's owner or a workspace admin.
+ * Both come from the server (`can_write`, `can_manage`), and whatever the
+ * viewer may not change is shown but held, with the reason.
*/
export function RoomAutoRouteSection({
workspaceId,
room,
autoRoute,
agents,
+ canWrite,
canManage,
detailKey,
}: {
@@ -41,7 +44,9 @@ export function RoomAutoRouteSection({
autoRoute: RoomAutoRoute;
/** The room's agents, for the triage picker. */
agents: { id: string; name: string }[];
- /** Whether the signed-in account may change it: the room's owner or a workspace admin. */
+ /** Whether the signed-in account may write to the room, and so turn auto-route on or off. */
+ canWrite: boolean;
+ /** Whether the signed-in account manages the room, and so may name its triage agent. */
canManage: boolean;
/** The query the room's detail is read under, written back from each answer. */
detailKey: readonly unknown[];
@@ -73,7 +78,7 @@ export function RoomAutoRouteSection({
}
// Unavailable, it can still be turned off, so a room isn't stuck "on".
- const canFlip = canManage && pending === null && (autoRoute.available || autoRoute.on);
+ const canFlip = canWrite && pending === null && (autoRoute.available || autoRoute.on);
const triage = autoRoute.fallbackAgent;
// A triage agent that has left the room is still listed, so the setting stays visible.
const triageChoices =
@@ -105,6 +110,12 @@ export function RoomAutoRouteSection({
/>
</div>
+ {!canWrite && (
+ <p className="text-xs text-foreground-muted" role="note">
+ Turning auto-route on or off needs write access to this room.
+ </p>
+ )}
+
{!autoRoute.available && (
<p className="text-xs text-foreground-warning" role="note">
{autoRoute.on ? 'On, but unavailable: ' : 'Unavailable: '}
@@ -146,8 +157,8 @@ export function RoomAutoRouteSection({
</div>
{!canManage && (
- <p className="text-xs text-foreground-muted">
- Only the room’s owner or a workspace admin can change these.
+ <p className="text-xs text-foreground-muted" role="note">
+ Only the room’s owner or a workspace admin can change this.
</p>
)}
{pending !== null && <span className="text-xs text-foreground-muted">Saving…</span>}
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 680815163..ee025dd1a 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
@@ -202,6 +202,7 @@ export const RoomConfigurationPanel = observer(function RoomConfigurationPanel({
workspaceId={workspaceId}
room={room}
autoRoute={room.autoRoute}
+ canWrite={permissions.canWrite}
canManage={permissions.canManage}
/>
)}
@@ -527,11 +528,13 @@ const AutoRouteSection = observer(function AutoRouteSection({
workspaceId,
room,
autoRoute,
+ canWrite,
canManage,
}: {
workspaceId: string;
room: RemoteRoomDetail;
autoRoute: NonNullable<RemoteRoomDetail['autoRoute']>;
+ canWrite: boolean;
canManage: boolean;
}) {
const remoteAgents = useWorkspaceAgents(workspaceId);
@@ -546,6 +549,7 @@ const AutoRouteSection = observer(function AutoRouteSection({
room={room}
autoRoute={autoRoute}
agents={agents}
+ canWrite={canWrite}
canManage={canManage}
detailKey={roomDetailKey(workspaceId, room.id)}
/>
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-auto-route.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-auto-route.test.tsx
index 97999f07b..255d3b3cd 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-auto-route.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-auto-route.test.tsx
@@ -40,13 +40,6 @@ vi.mock('@renderer/lib/ipc', () => ({
},
}));
-const access = vi.hoisted(() => ({ administers: true }));
-
-vi.mock('@renderer/features/switch-servers/workspace-admin', () => ({
- administersWorkspaceInScope: () => access.administers,
- operatesServer: () => false,
-}));
-
vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
switchRoomsStore: {
roomWorkspaceId: () => 'ws-1',
@@ -56,7 +49,6 @@ vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
}));
import { RoomConfigurationPanel } from '@renderer/features/switch-rooms/room-configuration-panel';
-import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
const NO_BACKEND =
@@ -70,10 +62,16 @@ const OFF: RoomAutoRoute = {
fallbackAgentName: null,
};
-function room(autoRoute: RoomAutoRoute | undefined, ownerId: string | null = null) {
+/** What the server says the signed-in account may do in the room. */
+type Access = { canWrite: boolean; canManage: boolean };
+
+const MANAGER: Access = { canWrite: true, canManage: true };
+
+function room(autoRoute: RoomAutoRoute | undefined, access: Access) {
return {
id: 'room-1',
- ownerId,
+ ownerId: 'user-owner',
+ ...access,
name: 'ops',
description: '',
instructions: null,
@@ -90,7 +88,6 @@ let container: HTMLDivElement | null = null;
let root: Root | null = null;
beforeEach(() => {
- access.administers = true;
vi.spyOn(workspacesStore, 'serverIdFor').mockReturnValue('server-1');
getRoomDetail.mockReset();
setRoomAutoRoute.mockReset();
@@ -105,9 +102,9 @@ afterEach(async () => {
async function render(
autoRoute: RoomAutoRoute | undefined,
- ownerId: string | null = null
+ access: Access = MANAGER
): Promise<HTMLElement> {
- getRoomDetail.mockResolvedValue(room(autoRoute, ownerId));
+ getRoomDetail.mockResolvedValue(room(autoRoute, access));
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
@@ -191,14 +188,14 @@ it('turns auto-route off', async () => {
});
it('leaves the switch as it was when the server refuses, with the reason', async () => {
- setRoomAutoRoute.mockRejectedValue(new Error('Only a room admin can change auto-route.'));
+ setRoomAutoRoute.mockRejectedValue(new Error('Not authorized to write this resource'));
const el = await render(OFF);
await vi.waitFor(() => expect(toggle(el)).toBeTruthy());
await act(async () => toggle(el).click());
await vi.waitFor(() => expect(el.textContent).toContain('Not changed —'));
- expect(el.textContent).toContain('Only a room admin can change auto-route.');
+ expect(el.textContent).toContain('Not authorized to write this resource');
expect(checked(el)).toBe(false);
});
@@ -272,25 +269,52 @@ it('names a triage agent by the name the server gives, even one that has left th
);
});
-it('holds the switch and picker for someone who neither owns the room nor administers the workspace', async () => {
- access.administers = false;
- const el = await render({ ...OFF, on: true });
+function picker(el: HTMLElement): HTMLElement {
+ return el.querySelector<HTMLElement>('[aria-label="Triage agent"]')!;
+}
+
+function pickerHeld(el: HTMLElement): boolean {
+ const p = picker(el);
+ return p.hasAttribute('data-disabled') || p.hasAttribute('disabled');
+}
+
+it('lets someone who may write to the room turn it on, but not name the triage agent', async () => {
+ setRoomAutoRoute.mockResolvedValue({ ...OFF, on: true });
+ const el = await render(OFF, { canWrite: true, canManage: false });
+ await vi.waitFor(() => expect(toggle(el)).toBeTruthy());
+
+ expect(disabled(el)).toBe(false);
+ expect(pickerHeld(el)).toBe(true);
+ expect(el.textContent).toContain('Only the room’s owner or a workspace admin can change this.');
+ expect(el.textContent).not.toContain('needs write access');
+
+ await act(async () => toggle(el).click());
+
+ expect(setRoomAutoRoute).toHaveBeenCalledWith({
+ workspaceId: 'ws-1',
+ roomId: 'room-1',
+ on: true,
+ });
+ await vi.waitFor(() => expect(checked(el)).toBe(true));
+});
+
+it('holds the switch and picker for a read-only viewer, with the reason', async () => {
+ const el = await render({ ...OFF, on: true }, { canWrite: false, canManage: false });
await vi.waitFor(() => expect(toggle(el)).toBeTruthy());
expect(checked(el)).toBe(true);
expect(disabled(el)).toBe(true);
- const picker = el.querySelector<HTMLElement>('[aria-label="Triage agent"]')!;
- expect(picker.hasAttribute('data-disabled') || picker.hasAttribute('disabled')).toBe(true);
- expect(el.textContent).toContain('Only the room’s owner or a workspace admin can change these.');
+ expect(pickerHeld(el)).toBe(true);
+ expect(el.textContent).toContain('Turning auto-route on or off needs write access to this room.');
+ expect(el.textContent).toContain('Only the room’s owner or a workspace admin can change this.');
});
-it('lets the room’s owner change it without administering the workspace', async () => {
- access.administers = false;
- vi.spyOn(switchServersStore, 'statusFor').mockReturnValue({
- user: { id: 'user-owner' },
- } as never);
- const el = await render(OFF, 'user-owner');
+it('offers both to the room’s owner or a workspace admin', async () => {
+ const el = await render(OFF, MANAGER);
await vi.waitFor(() => expect(toggle(el)).toBeTruthy());
expect(disabled(el)).toBe(false);
+ expect(pickerHeld(el)).toBe(false);
+ expect(el.textContent).not.toContain('Only the room’s owner');
+ expect(el.textContent).not.toContain('needs write access');
});
diff --git a/gateway/src/pages/rooms/RoomAutoRouteSection.test.tsx b/gateway/src/pages/rooms/RoomAutoRouteSection.test.tsx
index 7d7d9aad3..c66256340 100644
--- a/gateway/src/pages/rooms/RoomAutoRouteSection.test.tsx
+++ b/gateway/src/pages/rooms/RoomAutoRouteSection.test.tsx
@@ -71,7 +71,7 @@ afterEach(() => {
describe("RoomAutoRouteSection", () => {
it("turns auto-route on, and shows on only once the server says so", async () => {
const calls = mockServer((body) => routed({ ...OFF, on: body.on as boolean }));
- render(<RoomAutoRouteSection room={room} autoRoute={OFF} canManage />);
+ render(<RoomAutoRouteSection room={room} autoRoute={OFF} canWrite canManage />);
expect(toggle().checked).toBe(false);
screen.getByText("Off");
@@ -86,7 +86,7 @@ describe("RoomAutoRouteSection", () => {
it("turns auto-route off", async () => {
const calls = mockServer((body) => routed({ ...OFF, on: body.on as boolean }));
- render(<RoomAutoRouteSection room={room} autoRoute={{ ...OFF, on: true }} canManage />);
+ render(<RoomAutoRouteSection room={room} autoRoute={{ ...OFF, on: true }} canWrite canManage />);
fireEvent.click(toggle());
@@ -96,13 +96,13 @@ describe("RoomAutoRouteSection", () => {
it("leaves the toggle as it was and says why when the server refuses", async () => {
mockServer(
- () => new Response(JSON.stringify({ detail: "Only a room admin can change this." }), { status: 403 }),
+ () => new Response(JSON.stringify({ detail: "Not authorized to write this resource" }), { status: 403 }),
);
- render(<RoomAutoRouteSection room={room} autoRoute={OFF} canManage />);
+ render(<RoomAutoRouteSection room={room} autoRoute={OFF} canWrite canManage />);
fireEvent.click(toggle());
- await screen.findByText("Only a room admin can change this.");
+ await screen.findByText("Not authorized to write this resource");
expect(toggle().checked).toBe(false);
});
@@ -112,6 +112,7 @@ describe("RoomAutoRouteSection", () => {
<RoomAutoRouteSection
room={room}
autoRoute={{ ...OFF, available: false, reason: NO_BACKEND }}
+ canWrite
canManage
/>,
);
@@ -126,6 +127,7 @@ describe("RoomAutoRouteSection", () => {
<RoomAutoRouteSection
room={room}
autoRoute={{ on: true, available: false, reason: NO_BACKEND, fallback_agent: null }}
+ canWrite
canManage
/>,
);
@@ -133,19 +135,52 @@ describe("RoomAutoRouteSection", () => {
expect(toggle().disabled).toBe(false);
});
- it("is read-only for someone who neither owns the room nor administers the workspace", () => {
+ it("lets someone who may write to the room turn it on, but not name the triage agent", async () => {
+ const calls = mockServer((body) => routed({ ...OFF, on: body.on as boolean }));
+ render(<RoomAutoRouteSection room={room} autoRoute={OFF} canWrite canManage={false} />);
+
+ const select = screen.getByRole("combobox", {
+ name: "Triage agent while auto-route is unavailable",
+ });
+ expect(select.getAttribute("aria-disabled")).toBe("true");
+ screen.getByText("Only the room's owner or a workspace admin can change this.");
+ expect(screen.queryByText(/needs write access/)).toBeNull();
+ expect(toggle().disabled).toBe(false);
+
+ fireEvent.click(toggle());
+
+ await waitFor(() => expect(toggle().checked).toBe(true));
+ expect(calls.find((c) => c.method === "PUT")?.body).toEqual({ on: true });
+ });
+
+ it("holds the toggle and the picker for a read-only viewer, with the reason", () => {
mockServer(() => routed(OFF));
- render(<RoomAutoRouteSection room={room} autoRoute={OFF} canManage={false} />);
+ render(
+ <RoomAutoRouteSection room={room} autoRoute={OFF} canWrite={false} canManage={false} />,
+ );
expect(toggle().disabled).toBe(true);
- expect(screen.getByText("Only the room's owner or a workspace admin can change auto-route.")).toBeTruthy();
+ screen.getByText("Turning auto-route on or off needs write access to this room.");
+ screen.getByText("Only the room's owner or a workspace admin can change this.");
+ });
+
+ it("offers both to the room's owner or a workspace admin", () => {
+ mockServer(() => routed(OFF));
+ render(<RoomAutoRouteSection room={room} autoRoute={OFF} canWrite canManage />);
+
+ expect(toggle().disabled).toBe(false);
+ const select = screen.getByRole("combobox", {
+ name: "Triage agent while auto-route is unavailable",
+ });
+ expect(select.getAttribute("aria-disabled")).toBeNull();
+ expect(screen.queryByText(/Only the room's owner/)).toBeNull();
});
it("offers the room's own agents as triage agent and saves the pick", async () => {
const calls = mockServer((body) =>
routed({ ...OFF, fallback_agent: body.fallback_agent as string | null }),
);
- render(<RoomAutoRouteSection room={room} autoRoute={OFF} canManage />);
+ render(<RoomAutoRouteSection room={room} autoRoute={OFF} canWrite canManage />);
const select = screen.getByRole("combobox", {
name: "Triage agent while auto-route is unavailable",
@@ -168,7 +203,7 @@ describe("RoomAutoRouteSection", () => {
it("clears the triage agent with None", async () => {
const calls = mockServer(() => routed(OFF));
render(
- <RoomAutoRouteSection room={room} autoRoute={{ ...OFF, fallback_agent: "a2" }} canManage />,
+ <RoomAutoRouteSection room={room} autoRoute={{ ...OFF, fallback_agent: "a2" }} canWrite canManage />,
);
const select = screen.getByRole("combobox", {
@@ -185,7 +220,7 @@ describe("RoomAutoRouteSection", () => {
it("still names a triage agent that has left the room", async () => {
mockServer(() => routed(OFF));
render(
- <RoomAutoRouteSection room={room} autoRoute={{ ...OFF, fallback_agent: "a3" }} canManage />,
+ <RoomAutoRouteSection room={room} autoRoute={{ ...OFF, fallback_agent: "a3" }} canWrite canManage />,
);
const select = screen.getByRole("combobox", {
@@ -200,6 +235,7 @@ describe("RoomAutoRouteSection", () => {
<RoomAutoRouteSection
room={room}
autoRoute={{ ...OFF, fallback_agent: "gone-id", fallback_agent_name: "old-triage" }}
+ canWrite
canManage
/>,
);
diff --git a/gateway/src/pages/rooms/RoomAutoRouteSection.tsx b/gateway/src/pages/rooms/RoomAutoRouteSection.tsx
index 712d71d58..6ebcbdeac 100644
--- a/gateway/src/pages/rooms/RoomAutoRouteSection.tsx
+++ b/gateway/src/pages/rooms/RoomAutoRouteSection.tsx
@@ -21,14 +21,19 @@ import { useAgents } from "../../data/hooks";
* gets undecided messages while the decision service is failing. Shows what
* the server says: the toggle never flips before the server has answered,
* and where auto-route cannot work here it says why, in the server's words.
+ * Anyone who may write to the room may turn it on or off (`can_write`);
+ * naming the triage agent takes the room's owner or a workspace admin
+ * (`can_manage`). What the viewer may not change is held, with the reason.
*/
export default function RoomAutoRouteSection({
room,
autoRoute,
+ canWrite,
canManage,
}: {
room: RoomDetail;
autoRoute: RoomAutoRoute;
+ canWrite: boolean;
canManage: boolean;
}) {
const { data: allAgents } = useAgents();
@@ -82,11 +87,16 @@ export default function RoomAutoRouteSection({
checked={state.on}
onChange={(e) => save({ on: e.target.checked })}
// Turning it off stays possible where it cannot work.
- disabled={!canManage || saving || (!state.available && !state.on)}
+ disabled={!canWrite || saving || (!state.available && !state.on)}
/>
}
label={state.on ? "On" : "Off"}
/>
+ {!canWrite && (
+ <Typography variant="caption" color="text.secondary">
+ Turning auto-route on or off needs write access to this room.
+ </Typography>
+ )}
<TextField
select
size="small"
@@ -98,7 +108,7 @@ export default function RoomAutoRouteSection({
helperText={
canManage
? "Gets the messages auto-route could not decide while the decision service is failing. Off by default."
- : "Only the room's owner or a workspace admin can change auto-route."
+ : "Only the room's owner or a workspace admin can change this."
}
>
<MenuItem value="">None</MenuItem>
diff --git a/gateway/src/pages/rooms/RoomDetailPage.tsx b/gateway/src/pages/rooms/RoomDetailPage.tsx
index e6383d9b4..4b1f823cd 100644
--- a/gateway/src/pages/rooms/RoomDetailPage.tsx
+++ b/gateway/src/pages/rooms/RoomDetailPage.tsx
@@ -133,8 +133,12 @@ export default function RoomDetailPage() {
<Divider />
{room.auto_route && (
<>
- {/* Auto-route is the room owner's and the workspace admins' to change. */}
- <RoomAutoRouteSection room={room} autoRoute={room.auto_route} canManage={canManage} />
+ <RoomAutoRouteSection
+ room={room}
+ autoRoute={room.auto_route}
+ canWrite={canWrite}
+ canManage={canManage}
+ />
<Divider />
</>
)}