Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Department Access tab: two-choice sharing, as the Share dialog

milind-sonif239ad5b88f6
diff --git a/scripts/verify-team-bot-access.ts b/scripts/verify-team-bot-access.ts
index 4144430a62..ed27ddeacb 100644
--- a/scripts/verify-team-bot-access.ts
+++ b/scripts/verify-team-bot-access.ts
@@ -305,7 +305,7 @@ try {
await page.until(`(() => { const item = [...document.querySelectorAll('[role=menuitem]')].find((entry) => entry.textContent.includes("Set for all bots")); item?.click(); return Boolean(item); })()`, "Set for all bots");
await page.until(`(() => { const tab = [...document.querySelectorAll('[data-testid=team-settings-dialog] [role=tab]')].find((entry) => entry.textContent.trim() === "Access"); tab?.click(); return Boolean(tab); })()`, "the Access tab");
const pick = (label: string, value: string) => page.evaluate(`(() => { const field = document.querySelector('[data-testid=team-settings-dialog] select[aria-label="${label}"]'); field.value = ${JSON.stringify(value)}; field.dispatchEvent(new Event("change", { bubbles: true })); return true; })()`);
- await pick("Everyone in Acme", "view");
+ await pick("Everyone in Acme", "chat");
await pick("A person", PEOPLE.eve.email);
await page.until("Boolean(document.querySelector('[data-testid=team-settings-rows]'))", "the preview");
} },
@@ -315,12 +315,12 @@ try {
await page.until(`(() => { const item = [...document.querySelectorAll('[role=menuitem]')].find((entry) => entry.textContent.includes("Set for all bots")); item?.click(); return Boolean(item); })()`, "Set for all bots");
await page.until(`(() => { const tab = [...document.querySelectorAll('[data-testid=team-settings-dialog] [role=tab]')].find((entry) => entry.textContent.trim() === "Access"); tab?.click(); return Boolean(tab); })()`, "the Access tab");
const pick = (label: string, value: string) => page.evaluate(`(() => { const field = document.querySelector('[data-testid=team-settings-dialog] select[aria-label="${label}"]'); field.value = ${JSON.stringify(value)}; field.dispatchEvent(new Event("change", { bubbles: true })); return true; })()`);
- await pick("Everyone in Acme", "view");
+ await pick("Everyone in Acme", "chat");
await pick("A person", PEOPLE.eve.email);
await page.until(`(() => { const apply = [...document.querySelectorAll('[data-testid=team-settings-dialog] button')].find((entry) => entry.textContent.startsWith("Apply to")); apply?.click(); return Boolean(apply); })()`, "Apply");
await page.until("Boolean(document.querySelector('[data-testid=team-settings-dialog] [role=status]')?.textContent.includes('applied'))", "the results");
const shared = ((await as("ada", "GET", "/api/bots")).bots as Array<{ id: string; access?: { everyone: string; people: Record<string, string> } }>).filter((bot) => bot.id === payroll.id || bot.id === helpdesk.id);
- if (shared.length !== 2 || !shared.every((bot) => bot.access?.everyone === "view" && bot.access.people[PEOPLE.eve.email] === "chat")) throw new Error(`department access not applied: ${JSON.stringify(shared)}`);
+ if (shared.length !== 2 || !shared.every((bot) => bot.access?.everyone === "chat" && bot.access.people[PEOPLE.eve.email] === "chat")) throw new Error(`department access not applied: ${JSON.stringify(shared)}`);
} },
];
let crowded = false;
diff --git a/src/components/TeamSettingsDialog.tsx b/src/components/TeamSettingsDialog.tsx
index 8ec918d322..9bbdf42156 100644
--- a/src/components/TeamSettingsDialog.tsx
+++ b/src/components/TeamSettingsDialog.tsx
@@ -21,9 +21,8 @@ import {
} from "@/lib/team-bulk-settings";
import { api, desktopApprovalBridge, persistBotUpdate, useStore } from "@/state/store";
import { useTeamPeople } from "@/state/team-people";
-import { BOT_ACCESS_LEVELS, GRANTED_LEVELS, type BotAccessLevel, type GrantedLevel } from "../../shared/bot-access";
import { EFFORT_LEVELS, type EffortLevel } from "../../shared/wire";
-import { levelLabel, saveAccess } from "./bot-access/access";
+import { saveAccess } from "./bot-access/access";
import { useTeamName } from "./bot-access/ShareBotButton";
import { approvalModeOptions } from "./ApprovalModeSelector";
import { LocalComputerAutoWarning } from "./LocalComputerAutoWarning";
@@ -33,6 +32,7 @@ import { Select } from "./Select";
type Tab = "approval" | "model" | "access";
const KEEP = "";
const ENGINE_DEFAULT = "default";
+const ADD = "chat";
const REMOVE = "remove";
export function TeamSettingsRows({ rows }: { rows: ReadonlyArray<TeamPlanRow | TeamResultRow> }) {
@@ -62,7 +62,7 @@ export function TeamSettingsDialog({ team, onClose }: { team: string; onClose: (
const [effort, setEffort] = useState<string>(KEEP);
const [everyone, setEveryone] = useState<string>(KEEP);
const [person, setPerson] = useState<string>(KEEP);
- const [personLevel, setPersonLevel] = useState<string>("chat");
+ const [personAction, setPersonAction] = useState<string>(ADD);
const teamName = useTeamName();
const teamPeople = useTeamPeople();
// Admins and owners always edit every bot, so only Users are offered.
@@ -83,8 +83,8 @@ export function TeamSettingsDialog({ team, onClose }: { team: string; onClose: (
: tab === "access" ? everyone === KEEP && person === KEEP ? null
: {
kind: "access",
- ...(everyone === KEEP ? {} : { everyone: everyone as BotAccessLevel }),
- ...(person === KEEP ? {} : { person: { email: person, level: personLevel === REMOVE ? null : personLevel as GrantedLevel } }),
+ ...(everyone === KEEP ? {} : { everyone: everyone === ADD ? "chat" : "none" }),
+ ...(person === KEEP ? {} : { person: { email: person, level: personAction === REMOVE ? null : "chat" } }),
}
: model === KEEP && effort === KEEP ? null
: {
@@ -176,10 +176,11 @@ export function TeamSettingsDialog({ team, onClose }: { team: string; onClose: (
</fieldset>
) : tab === "access" && teamName ? (
<fieldset disabled={running} className="flex flex-col gap-3">
- <label className="text-[13px] text-ink-secondary">{t("botAccess.everyone", { team: teamName })}
- <Select className="mt-1 w-full" aria-label={t("botAccess.everyone", { team: teamName })} value={everyone} onChange={(event) => setEveryone(event.target.value)}>
+ <label className="text-[13px] text-ink-secondary">{t("teamSettings.everyone", { team: teamName })}
+ <Select className="mt-1 w-full" aria-label={t("teamSettings.everyone", { team: teamName })} value={everyone} onChange={(event) => setEveryone(event.target.value)}>
<option value={KEEP}>{t("teamSettings.keepEveryone")}</option>
- {BOT_ACCESS_LEVELS.map((level) => <option key={level} value={level}>{levelLabel(level)}</option>)}
+ <option value={ADD}>{t("botAccess.everyoneUse", { team: teamName })}</option>
+ <option value="none">{t("botAccess.onlyAdded")}</option>
</Select>
</label>
<div className="flex gap-2">
@@ -189,9 +190,9 @@ export function TeamSettingsDialog({ team, onClose }: { team: string; onClose: (
{members.map((one) => <option key={one.email} value={one.email}>{one.name === one.email ? one.email : `${one.name} · ${one.email}`}</option>)}
</Select>
</label>
- <label className="w-[40%] text-[13px] text-ink-secondary">{t("teamSettings.personLevel")}
- <Select className="mt-1 w-full" aria-label={t("teamSettings.personLevel")} value={personLevel} disabled={person === KEEP} onChange={(event) => setPersonLevel(event.target.value)}>
- {GRANTED_LEVELS.map((level) => <option key={level} value={level}>{levelLabel(level)}</option>)}
+ <label className="w-[40%] text-[13px] text-ink-secondary">{t("teamSettings.personAction")}
+ <Select className="mt-1 w-full" aria-label={t("teamSettings.personAction")} value={personAction} disabled={person === KEEP} onChange={(event) => setPersonAction(event.target.value)}>
+ <option value={ADD}>{t("teamSettings.addPerson")}</option>
<option value={REMOVE}>{t("teamSettings.removePerson")}</option>
</Select>
</label>
diff --git a/src/lib/team-bulk-settings.test.ts b/src/lib/team-bulk-settings.test.ts
index 29ee2c3689..45b807872f 100644
--- a/src/lib/team-bulk-settings.test.ts
+++ b/src/lib/team-bulk-settings.test.ts
@@ -195,6 +195,13 @@ describe("who can use a department's bots", () => {
]);
});
+ it("never lowers someone who can already do more when adding them, and keeps the sharing's other fields", () => {
+ const payroll = shared("payroll", { everyone: "none", people: { [CARA]: "edit", [BOB]: "view" }, groups: { finance: "chat" } } as Bot["access"]);
+ const plan = planAccess(payroll, { kind: "access", everyone: "chat", person: { email: CARA, level: "chat" } });
+ expect(plan).toEqual({ bot: payroll, status: "apply", access: { everyone: "chat", people: { [CARA]: "edit", [BOB]: "view" }, groups: { finance: "chat" } } });
+ expect(planAccess(payroll, { kind: "access", person: { email: BOB, level: "chat" } })).toMatchObject({ access: { everyone: "none", people: { [CARA]: "edit", [BOB]: "chat" }, groups: { finance: "chat" } } });
+ });
+
it("skips someone's own MausBot and a bot this person can't share, and never lists a bot's owner", () => {
const own = shared("mine", { everyone: "none", people: {} }, { defaultBot: { person: BOB } } as Partial<Bot>);
const viewOnly = shared("atlas", { everyone: "none", people: {} }, { yourAccess: "chat" });
@@ -204,21 +211,21 @@ describe("who can use a department's bots", () => {
});
it("plans again from the bot's latest sharing, so a grant another admin removed after the preview stays removed", () => {
- const previewed = shared("payroll", { everyone: "none", people: { [CARA]: "chat" } });
- const latest = shared("payroll", { everyone: "none", people: {} });
- const change = { kind: "access" as const, everyone: "view" as const };
- expect(planTeamChange([previewed], instances, change)[0]).toMatchObject({ access: { everyone: "view", people: { [CARA]: "chat" } } });
- expect(planAccess(latest, change)).toEqual({ bot: latest, status: "apply", access: { everyone: "view", people: {} } });
+ const previewed = shared("payroll", { everyone: "chat", people: { [CARA]: "chat" } });
+ const latest = shared("payroll", { everyone: "chat", people: {} });
+ const change = { kind: "access" as const, everyone: "none" as const };
+ expect(planTeamChange([previewed], instances, change)[0]).toMatchObject({ access: { everyone: "none", people: { [CARA]: "chat" } } });
+ expect(planAccess(latest, change)).toEqual({ bot: latest, status: "apply", access: { everyone: "none", people: {} } });
});
it("saves each bot's sharing through its own request, one at a time, and never as a settings patch", async () => {
const payroll = shared("payroll", { everyone: "none", people: {} });
- const plan = planTeamChange([payroll], instances, { kind: "access", everyone: "view" });
+ const plan = planTeamChange([payroll], instances, { kind: "access", everyone: "chat" });
const persist = vi.fn(async () => undefined);
const share = vi.fn(async () => undefined);
expect(planNeedsLocalAutoConsent(plan)).toBe(false);
expect(await applyTeamPlan(plan, persist, { share })).toEqual([{ bot: payroll, status: "applied" }]);
- expect(share).toHaveBeenCalledWith(payroll, { everyone: "view", people: {} });
+ expect(share).toHaveBeenCalledWith(payroll, { everyone: "chat", people: {} });
expect(persist).not.toHaveBeenCalled();
expect(await applyTeamPlan(plan, persist, { share: async () => "unchanged" }), "already set by the time it was sent").toEqual([{ bot: payroll, status: "unchanged" }]);
});
diff --git a/src/lib/team-bulk-settings.ts b/src/lib/team-bulk-settings.ts
index 3cba8b67cc..5e3c703fff 100644
--- a/src/lib/team-bulk-settings.ts
+++ b/src/lib/team-bulk-settings.ts
@@ -3,7 +3,7 @@ import { t } from "@/lib/i18n";
import { threadApprovalModes, type Bot, type InstanceInfo } from "@/state/store";
import type { BotUpdatePatch } from "@/state/bot-patch-queue";
import { approvalModeFor, supportsApprovalMode, type ApprovalMode } from "../../shared/approval-mode";
-import { sameAccess, type BotAccess, type BotAccessLevel, type GrantedLevel } from "../../shared/bot-access";
+import { atLeast, sameAccess, type BotAccess, type BotAccessLevel, type GrantedLevel } from "../../shared/bot-access";
import { botOwner } from "../../shared/bot-owner";
import { accessOfBot, withPerson } from "@/components/bot-access/access";
import type { EffortLevel, ModelSelection } from "../../shared/wire";
@@ -75,8 +75,11 @@ export function planAccess(bot: Bot, change: Extract<TeamChange, { kind: "access
if (bot.defaultBot?.person) return { bot, status: "skip", reason: t("teamSettings.skip.ownMausBot") };
if (bot.yourAccess !== "edit") return { bot, status: "skip", reason: t("teamSettings.skip.cantShare") };
const before = accessOfBot(bot);
- let access: BotAccess = change.everyone ? { everyone: change.everyone, people: before.people } : before;
- if (change.person && change.person.email !== botOwner(bot)) access = withPerson(access, change.person.email, change.person.level);
+ let access: BotAccess = change.everyone ? { ...before, everyone: change.everyone } : before;
+ const person = change.person;
+ // Adding never lowers someone who can already do more.
+ const keep = !person || person.email === botOwner(bot) || (person.level && atLeast(before.people[person.email], person.level));
+ if (person && !keep) access = { ...access, ...withPerson(access, person.email, person.level) };
return sameAccess(before, access) ? { bot, status: "unchanged" } : { bot, status: "apply", access };
}
diff --git a/src/locales/en.json b/src/locales/en.json
index 25a22a93cf..7d621ff63b 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -1875,10 +1875,12 @@
"teamSettings.tab.access": "Access",
"teamSettings.keepEveryone": "Keep each bot's setting",
"teamSettings.person": "A person",
- "teamSettings.noPerson": "Don't change anyone's own level",
- "teamSettings.personLevel": "What they can do",
- "teamSettings.removePerson": "Remove their own level",
- "teamSettings.accessHint": "Admins can always edit every bot, and each bot's owner keeps editing it.",
+ "teamSettings.everyone": "Everyone in {team}",
+ "teamSettings.noPerson": "Don't add or remove anyone",
+ "teamSettings.personAction": "Add or remove",
+ "teamSettings.addPerson": "Add them",
+ "teamSettings.removePerson": "Remove them",
+ "teamSettings.accessHint": "Admins and whoever looks after each bot can always use and change it.",
"teamSettings.skip.ownMausBot": "it's someone's own MausBot",
"teamSettings.skip.cantShare": "you can't change who can use it",
"teamSettings.customPerBot": "Custom approval stays a per-bot setting in that bot's settings.",