Skip to content

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

fix(settings): let built-in ChatGPT account rows be hidden

AdityaUmale7d2e9328d534
diff --git a/src/components/EngineAccounts.tsx b/src/components/EngineAccounts.tsx
index 12b3c6c592..0af831ca95 100644
--- a/src/components/EngineAccounts.tsx
+++ b/src/components/EngineAccounts.tsx
@@ -36,11 +36,14 @@ const COPY: Record<AccountGroup, Record<"title" | "add" | "removeBody", LocaleKe
chatgpt: { title: "accounts.chatgpt", add: "accounts.addChatgpt", removeBody: "accounts.removeBodyChatgpt" },
};
-/** What an account's menu offers. Only accounts added here can be removed; each provider's first account stays. */
-export function accountActions(group: AccountGroup, instance: InstanceInfo): { signOut: boolean; remove: boolean } {
+/** What an account's menu offers. Only accounts added here can be removed; each provider's first account stays, and
+ * ChatGPT's built-in rows (Codex, ChatGPT plan) can be hidden instead. */
+export function accountActions(group: AccountGroup, instance: InstanceInfo): { signOut: boolean; remove: boolean; hide: boolean } {
+ const remove = group === "claude" ? instance.instanceId !== "claude" && instance.claudeAccount?.isDefault !== true : instance.instanceId.startsWith("chatgpt-");
return {
signOut: accountState(instance) === "signedIn" && instance.authentication?.signOut === true && instance.snapshot.account?.method !== "api-key",
- remove: group === "claude" ? instance.instanceId !== "claude" && instance.claudeAccount?.isDefault !== true : instance.instanceId.startsWith("chatgpt-"),
+ remove,
+ hide: group === "chatgpt" && !remove,
};
}
@@ -72,7 +75,7 @@ function AccountMenu({ group, instance, onRename }: { group: AccountGroup; insta
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const menuRef = useRef<HTMLDivElement>(null);
- const { signOut: canSignOut, remove: canRemove } = accountActions(group, instance);
+ const { signOut: canSignOut, remove: canRemove, hide: canHide } = accountActions(group, instance);
const usedBy = state.bots.filter((bot) => bot.modelSelection.instanceId === instance.instanceId).length;
useEffect(() => {
@@ -89,13 +92,15 @@ function AccountMenu({ group, instance, onRename }: { group: AccountGroup; insta
};
}, [open]);
- const run = async (action: "signOut" | "remove") => {
+ const run = async (action: "signOut" | "remove" | "hide") => {
setConfirm(null);
setBusy(true);
setError(null);
try {
const path = `/api/instances/${encodeURIComponent(instance.instanceId)}${action === "signOut" ? "/auth/sign-out" : ""}`;
- const { instances } = await api(path, action === "signOut" ? { method: "POST" } : { method: "DELETE" });
+ // Hide leaves the account out of every model list until Unhide (Settings → AI → More providers).
+ const init = action === "signOut" ? { method: "POST" } : action === "remove" ? { method: "DELETE" } : { method: "PATCH", body: JSON.stringify({ hidden: true }) };
+ const { instances } = await api(path, init);
// The response is the confirmed state: a second request could fail and leave a stale row.
if (Array.isArray(instances)) dispatch({ type: "instances", instances });
else await refreshInstances().catch(() => {});
@@ -123,7 +128,8 @@ function AccountMenu({ group, instance, onRename }: { group: AccountGroup; insta
<div role="menu" className={cn("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]", MENU_SHEET)}>
<button type="button" role="menuitem" className={cn(item, "text-ink")} onClick={() => { setOpen(false); onRename(); }}>{t("accounts.rename")}</button>
{canSignOut && <button type="button" role="menuitem" className={cn(item, "text-ink")} onClick={() => { setOpen(false); setConfirm("signOut"); }}>{t("accounts.signOut")}</button>}
- {canRemove && usedBy > 0 && <p className="px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary">{t("accounts.inUse", { count: String(usedBy) })}</p>}
+ {canHide && <button type="button" role="menuitem" disabled={usedBy > 0} title={t("engines.hideHint")} className={cn(item, "text-ink")} onClick={() => { setOpen(false); void run("hide"); }}>{t("engines.hide")}</button>}
+ {(canRemove || canHide) && usedBy > 0 && <p className="px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary">{t("accounts.inUse", { count: String(usedBy) })}</p>}
</div>
)}
{error && <p role="alert" className="absolute right-0 top-full z-30 mt-1 w-[260px] rounded-lg bg-card p-2 text-[12px] text-danger shadow-lg">{error}</p>}
diff --git a/src/components/EnginesSettings.hidden-providers.dom.test.ts b/src/components/EnginesSettings.hidden-providers.dom.test.ts
index a1b6f4922d..ec6631a893 100644
--- a/src/components/EnginesSettings.hidden-providers.dom.test.ts
+++ b/src/components/EnginesSettings.hidden-providers.dom.test.ts
@@ -227,3 +227,57 @@ describe("Settings → AI lists every provider the app knows", () => {
if (state === "hidden") expect(hidden.size).toBe(all.length);
});
});
+
+describe("Settings → AI → ChatGPT: the built-in account rows can be hidden", () => {
+ const codexAccount: InstanceInfo = { ...codex, authentication: { method: "device-code", signOut: true } };
+ const plan: InstanceInfo = {
+ instanceId: "chatgpt", driverKind: "codex", displayName: "ChatGPT plan", cliDefault: "codex",
+ snapshot: { state: "available", authenticated: false, chatgptPlan: true }, models: { default: "gpt", options: [] },
+ authentication: { method: "browser-pkce", signOut: true },
+ };
+ const added: InstanceInfo = { ...plan, instanceId: "chatgpt-work", displayName: "Work" };
+ const accounts = () => [...container.querySelectorAll("[data-account]")].map((row) => row.getAttribute("data-account"));
+ const menuItems = async (instanceId: string) => {
+ await click(container.querySelector(`[data-account="${instanceId}"] button[aria-haspopup="menu"]`));
+ return [...container.querySelectorAll('[role="menuitem"]')] as HTMLButtonElement[];
+ };
+ const openCard = async () => { await render(); await click(rowButton("codex")); };
+
+ beforeEach(() => {
+ server.all = [codexAccount, plan, added];
+ fixture.state = { ...fixture.state, instances: [...server.all] };
+ });
+
+ it("hides only the signed-out ChatGPT plan row, and Unhide brings it back to the card", async () => {
+ await openCard();
+ expect(accounts()).toEqual(["codex", "chatgpt", "chatgpt-work"]);
+ const hide = (await menuItems("chatgpt")).find((item) => item.textContent === "Hide");
+ await click(hide);
+ expect(server.calls).toContainEqual({ method: "PATCH", path: "/api/instances/chatgpt", body: { hidden: true } });
+ expect(accounts()).toEqual(["codex", "chatgpt-work"]);
+ expect(hiddenRows()).toEqual(["chatgpt"]);
+ await click(container.querySelector('[data-unhide-engine="chatgpt"]'));
+ expect(server.calls).toContainEqual({ method: "PATCH", path: "/api/instances/chatgpt", body: { hidden: false } });
+ expect(accounts()).toEqual(["codex", "chatgpt", "chatgpt-work"]);
+ expect(hiddenRows()).toEqual([]);
+ });
+
+ it("offers Hide on the Codex row too", async () => {
+ await openCard();
+ expect((await menuItems("codex")).map((item) => item.textContent)).toContain("Hide");
+ });
+
+ it("keeps Remove, not Hide, for an added account", async () => {
+ await openCard();
+ expect((await menuItems("chatgpt-work")).map((item) => item.textContent)).not.toContain("Hide");
+ expect(container.querySelector('[data-account="chatgpt-work"]')?.textContent).toContain("Remove");
+ });
+
+ it("won't hide an account a bot still uses", async () => {
+ fixture.state = { ...fixture.state, bots: [{ modelSelection: { instanceId: "chatgpt" } } as Bot] };
+ await openCard();
+ const hide = (await menuItems("chatgpt")).find((item) => item.textContent === "Hide");
+ expect(hide?.disabled).toBe(true);
+ expect(container.textContent).toContain(t("accounts.inUse", { count: "1" }));
+ });
+});
diff --git a/src/components/EnginesSettings.test.ts b/src/components/EnginesSettings.test.ts
index 296846eb4c..7fd495d390 100644
--- a/src/components/EnginesSettings.test.ts
+++ b/src/components/EnginesSettings.test.ts
@@ -63,9 +63,9 @@ describe("Settings → Engines → ChatGPT accounts", () => {
instanceId, driverKind: "codex", displayName: "Plan", snapshot: { state: "available", authenticated, chatgptPlan: true },
models: { default: "gpt", options: [] }, authentication: { method: "browser-pkce", signOut },
});
- expect(accountActions("chatgpt", account("chatgpt", true, true))).toEqual({ signOut: true, remove: false });
- expect(accountActions("chatgpt", account("chatgpt-work", true, false))).toEqual({ signOut: false, remove: true });
- expect(accountActions("chatgpt", account("chatgpt-work", false, true))).toEqual({ signOut: false, remove: true });
+ expect(accountActions("chatgpt", account("chatgpt", true, true))).toEqual({ signOut: true, remove: false, hide: true });
+ expect(accountActions("chatgpt", account("chatgpt-work", true, false))).toEqual({ signOut: false, remove: true, hide: false });
+ expect(accountActions("chatgpt", account("chatgpt-work", false, true))).toEqual({ signOut: false, remove: true, hide: false });
fixture.instances = [{ ...account("chatgpt-work", true, false), cliDefault: "codex" }];
fixture.bots = [];
expect(renderToStaticMarkup(createElement(EnginesSettings))).toContain(">Remove<");
@@ -417,9 +417,9 @@ describe("Settings → Engines → Claude accounts", () => {
});
it("keeps the default account and signs out only a signed-in account the server can sign out", () => {
- expect(accountActions("claude", claude("claude", "Personal", true))).toEqual({ signOut: true, remove: false });
- expect(accountActions("claude", claude("claude-work", "Work", false))).toEqual({ signOut: false, remove: true });
- expect(accountActions("claude", claude("claude-work", "Work", true, { authentication: { method: "paste-code", signOut: false } }))).toEqual({ signOut: false, remove: true });
+ expect(accountActions("claude", claude("claude", "Personal", true))).toEqual({ signOut: true, remove: false, hide: false });
+ expect(accountActions("claude", claude("claude-work", "Work", false))).toEqual({ signOut: false, remove: true, hide: false });
+ expect(accountActions("claude", claude("claude-work", "Work", true, { authentication: { method: "paste-code", signOut: false } }))).toEqual({ signOut: false, remove: true, hide: false });
expect(renderClaude(claude("claude-work", "Work", true))).toContain(">Remove<");
});