Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Plan each bot's access again just before saving it, and say what the person options change
Azad Jagtapf2ea6d1d7d11
diff --git a/src/components/TeamSettingsDialog.tsx b/src/components/TeamSettingsDialog.tsxindex 8cc78f746f..626ead33a4 100644--- a/src/components/TeamSettingsDialog.tsx+++ b/src/components/TeamSettingsDialog.tsx@@ -6,6 +6,7 @@ import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";import {applyTeamPlan,+ planAccess,planNeedsLocalAutoConsent,planTeamChange,TEAM_APPROVAL_MODES,@@ -73,6 +74,8 @@ export function TeamSettingsDialog({ team, onClose }: { team: string; onClose: (const dialog = useRef<HTMLDivElement>(null);const bots = useMemo(() => teamBots(state.bots, team), [state.bots, team]);+ const latestBots = useRef(state.bots);+ latestBots.current = state.bots;const models = useMemo(() => teamModelChoices(bots, state.instances), [bots, state.instances]);const efforts = useMemo(() => teamEffortChoices(bots, state.instances, EFFORT_LEVELS), [bots, state.instances]);const change: TeamChange | null = tab === "approval"@@ -107,7 +110,12 @@ export function TeamSettingsDialog({ team, onClose }: { team: string; onClose: (dispatch({ type: "botPatched", bot: saved });}, {acknowledgeLocalAuto, onProgress: setProgress,- share: async (bot, access) => dispatch({ type: "botPatched", bot: await saveAccess(bot.id, access) }),+ share: async (bot) => {+ const latest = latestBots.current.find((one) => one.id === bot.id) ?? bot;+ const row = change?.kind === "access" ? planAccess(latest, change) : null;+ if (row?.status === "skip") throw new Error(row.reason);+ if (row?.status === "apply" && "access" in row) dispatch({ type: "botPatched", bot: await saveAccess(bot.id, row.access) });+ },});setResults(outcome);setRunning(false);diff --git a/src/lib/team-bulk-settings.test.ts b/src/lib/team-bulk-settings.test.tsindex dced7e176c..ebfe3cd85a 100644--- a/src/lib/team-bulk-settings.test.ts+++ b/src/lib/team-bulk-settings.test.ts@@ -6,6 +6,7 @@ import { persistBotUpdate, type Bot, type InstanceInfo } from "@/state/store";import { EFFORT_LEVELS } from "../../shared/wire";import {applyTeamPlan,+ planAccess,planNeedsLocalAutoConsent,planTeamChange,TEAM_APPROVAL_MODES,@@ -194,6 +195,14 @@ describe("who can use a department's bots", () => {expect(plan.map((row) => row.status === "skip" ? row.reason : row.status)).toEqual(["it's someone's own MausBot", "you can't change who can use it", "unchanged"]);});+ 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: {} } });+ });+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" });diff --git a/src/lib/team-bulk-settings.ts b/src/lib/team-bulk-settings.tsindex a36ae98ff7..1a2b481a61 100644--- a/src/lib/team-bulk-settings.ts+++ b/src/lib/team-bulk-settings.ts@@ -69,7 +69,9 @@ export function teamEffortChoices(bots: readonly Bot[], instances: readonly Instreturn order.filter((level) => offered.has(level));}-function planAccess(bot: Bot, change: Extract<TeamChange, { kind: "access" }>): TeamPlanRow {+/** Sharing is saved whole, so each bot's row is planned again from its latest copy just before it is sent: a grant+ * another admin changed since the preview is kept as they left it. */+export function planAccess(bot: Bot, change: Extract<TeamChange, { kind: "access" }>): TeamPlanRow {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);diff --git a/src/locales/en.json b/src/locales/en.jsonindex 0cc7a559aa..f5109b18dd 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -1727,9 +1727,9 @@"teamSettings.tab.access": "Access","teamSettings.keepEveryone": "Keep each bot's setting","teamSettings.person": "A person",- "teamSettings.noPerson": "Nobody else",+ "teamSettings.noPerson": "Don't change anyone's own level","teamSettings.personLevel": "What they can do",- "teamSettings.removePerson": "Remove their access",+ "teamSettings.removePerson": "Remove their own level","teamSettings.accessHint": "Admins can always edit every bot, and each bot's owner keeps editing it.","teamSettings.skip.ownMausBot": "it's someone's own MausBot","teamSettings.skip.cantShare": "you can't change who can use it",