Skip to content

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

feat(providers): hide a provider you don't use (#4159)

Azad Jagtapf4fe7cb0666a
diff --git a/server/claude-accounts.ts b/server/claude-accounts.ts
index 57edb5c5b0..f07e888a2d 100644
--- a/server/claude-accounts.ts
+++ b/server/claude-accounts.ts
@@ -17,6 +17,7 @@ export const instanceSettingsSchema = z.object({
displayName: displayName.optional(),
configDir: configDir.optional(),
tools: z.boolean().optional(),
+ hidden: z.boolean().optional(),
/** null goes back to the server's default wait. */
replyWaitMinutes: z.number().int().min(1).max(60).nullable().optional(),
}).strict().refine((value) => Object.keys(value).length > 0, "No settings supplied");
diff --git a/server/config.ts b/server/config.ts
index dcec95a04c..bb91671eab 100644
--- a/server/config.ts
+++ b/server/config.ts
@@ -278,7 +278,7 @@ const instanceConfigSchema = z.object({
.refine((icon) => providerIconError(icon) === null, { message: "Invalid provider icon" }),
]).optional(),
environment: z.record(z.string(), z.string()).optional(),
- enabled: z.boolean().optional(),
+ enabled: z.boolean().optional(), hidden: z.boolean().optional(),
access: z.enum(["subscription", "custom", "api"]).optional(),
config: z.json().optional(),
});
diff --git a/server/contracts.ts b/server/contracts.ts
index cac56bdce2..849f414563 100644
--- a/server/contracts.ts
+++ b/server/contracts.ts
@@ -98,6 +98,8 @@ export interface InstanceConfig {
icon?: ProviderIcon;
environment?: Record<string, string>;
enabled?: boolean;
+ /** Left out of every model list, picker and automatic choice; the engine itself (its CLI and sign-in) is untouched. */
+ hidden?: boolean;
/** Picker group over the driver's default: an `openai-compat` instance on a provider's own key is "api". */
access?: EngineAccess;
config?: unknown;
diff --git a/server/default-model-selection.test.ts b/server/default-model-selection.test.ts
index 8f24d34026..89c9ef724d 100644
--- a/server/default-model-selection.test.ts
+++ b/server/default-model-selection.test.ts
@@ -355,3 +355,12 @@ describe("new bot effort default", () => {
expect(withNewBotEffort(selection, "high", undefined)).toEqual(selection);
});
});
+
+describe("a hidden provider", () => {
+ it("drops out of every selectable list, and an unhidden one comes back", () => {
+ const instances = [{ instanceId: "claude" }, { instanceId: "hermes" }] as unknown as SelectableInstance[];
+ expect(withInstanceConfig(instances, { hermes: { driver: "fake", hidden: true } }).map((instance) => instance.instanceId)).toEqual(["claude"]);
+ expect(withInstanceConfig(instances, { hermes: { driver: "fake" } }).map((instance) => instance.instanceId)).toEqual(["claude", "hermes"]);
+ });
+});
+
diff --git a/server/default-model-selection.ts b/server/default-model-selection.ts
index 7148f90b8b..3341642786 100644
--- a/server/default-model-selection.ts
+++ b/server/default-model-selection.ts
@@ -28,8 +28,9 @@ const best = (instances: readonly SelectableInstance[], context: DefaultSelectio
};
/** The saved config's enabled switch and picker group win over what the driver reports. */
+/** Every list a person or the server chooses a model from passes here, so a hidden provider drops out of all of them. */
export function withInstanceConfig<T extends SelectableInstance>(instances: readonly T[], configs: InstanceConfigMap): T[] {
- return instances.map((instance) => ({
+ return instances.filter((instance) => configs[instance.instanceId]?.hidden !== true).map((instance) => ({
...instance,
enabled: configs[instance.instanceId]?.enabled ?? instance.enabled,
...(configs[instance.instanceId]?.access ? { access: configs[instance.instanceId].access } : {}),
diff --git a/server/routes/instances.test.ts b/server/routes/instances.test.ts
index abe7b27761..f31b9cc6d4 100644
--- a/server/routes/instances.test.ts
+++ b/server/routes/instances.test.ts
@@ -205,3 +205,29 @@ describe("a server's reply wait", () => {
});
});
+describe("hiding a provider", () => {
+ it("hides a built-in provider, lists it apart, refuses while a bot uses it, and unhides", async () => {
+ const persisted: Array<Record<string, { driver: string; hidden?: boolean }>> = [];
+ const cfg = { instances: { a: { driver: "fake" }, hermes: { driver: "fake", displayName: "Hermes" } } };
+ const bots = [{ id: "pen", modelSelection: { instanceId: "a", model: "m" } }];
+ const { call, base } = await serve({
+ cfg: cfg as unknown as AppConfig,
+ store: { bots, tasks: () => [] } as never,
+ persistProviderInstance: async (_id: string, instances: typeof persisted[number]) => {
+ persisted.push(structuredClone(instances));
+ (cfg as { instances: unknown }).instances = instances;
+ },
+ });
+ const status = async (id: string, body: unknown) => (await fetch(`${base}/api/instances/${id}`, {
+ method: "PATCH", headers: { "content-type": "application/json" }, body: JSON.stringify(body),
+ })).status;
+ expect(await status("a", { hidden: true })).toBe(409);
+ await call("PATCH", "/api/instances/hermes", { hidden: true });
+ expect(persisted.at(-1)!.hermes).toMatchObject({ driver: "fake", hidden: true });
+ expect((await call("GET", "/api/instances/hidden")).instances).toEqual([{ instanceId: "hermes", driverKind: "fake", displayName: "Hermes" }]);
+ await call("PATCH", "/api/instances/hermes", { hidden: false });
+ expect(persisted.at(-1)!.hermes).not.toHaveProperty("hidden");
+ expect((await call("GET", "/api/instances/hidden")).instances).toEqual([]);
+ });
+});
+
diff --git a/server/routes/instances.ts b/server/routes/instances.ts
index 6c0824251e..8dc54c2038 100644
--- a/server/routes/instances.ts
+++ b/server/routes/instances.ts
@@ -54,6 +54,10 @@ export function createInstanceRoutes(deps: InstanceRouteDeps): RouteHandler {
botForThread, activeGroupTurnForBot,
} = deps;
const describeInstances = async () => hostedModels ? deps.describeInstances() : withEndpointUrls(await deps.describeInstances(), cfg.instances ?? {});
+ /** Bots, their backups and threads, the new-bot default, or a turn running on it: a provider in use can't go away. */
+ const providerInUse = (instanceId: string): boolean => cfg.defaultModelSelection?.instanceId === instanceId || store.bots.some((bot) =>
+ bot.modelSelection.instanceId === instanceId || bot.fallback?.some(candidate => candidate.instanceId === instanceId) || store.tasks(bot.id).some((task) => task.modelSelection?.instanceId === instanceId)) ||
+ busyProviderSelections().some((selection) => selection.instanceId === instanceId);
const busyProviderSelections = () => store.bots.flatMap((bot) => {
const busyTasks = store.tasks(bot.id).filter((task) => threadBusy(bot.id, task.threadId));
const selections = busyTasks.map((task) => botForThread(bot.id, task.threadId)!.modelSelection);
@@ -80,6 +84,10 @@ export function createInstanceRoutes(deps: InstanceRouteDeps): RouteHandler {
// One updater per executable: Claude instances can share an install, and two self-updates would race its files.
const claudeUpdatesInFlight = new Set<string>();
return async ({ req, res, url, path, method, auth, json, readBody }) => {
+ if (method === "GET" && path === "/api/instances/hidden") {
+ const hidden = Object.entries(persistableInstanceConfigs(cfg)).filter(([, entry]) => entry.hidden === true);
+ return json(res, 200, { instances: hidden.map(([instanceId, entry]) => ({ instanceId, driverKind: entry.driver, displayName: entry.displayName ?? BUILT_IN_DRIVERS.find((driver) => driver.driverKind === entry.driver)?.metadata.displayName ?? instanceId })) });
+ }
if (method === "GET" && path === "/api/instances") {
// Rescan PATH: Windows never pushes PATH changes into a live process, so a CLI installed since launch stays invisible.
resetPathCache();
@@ -324,6 +332,13 @@ export function createInstanceRoutes(deps: InstanceRouteDeps): RouteHandler {
if ((body.configDir !== undefined && entry.driver !== "claudeAgent") || (body.displayName !== undefined && !["claudeAgent", "codex"].includes(entry.driver))) {
return json(res, 400, { error: "Account settings are available for Claude and ChatGPT accounts only." });
}
+ if (body.hidden === true && providerInUse(instanceId)) {
+ return json(res, 409, { error: "Choose another model for the bots and default model using this provider before hiding it." });
+ }
+ if (body.hidden !== undefined) {
+ if (body.hidden) entry.hidden = true;
+ else delete entry.hidden;
+ }
if (body.tools !== undefined) {
if (!["openai-compat", "grok", "minimax", "mistral", "cerebras", "groq", "greenference", "meta"].includes(entry.driver)) {
return json(res, 400, { error: "The tools setting is available for OpenAI-compatible, Grok API, MiniMax API, Mistral API, Cerebras API, Groq API, Greenference API and Meta API instances only." });
@@ -365,9 +380,7 @@ export function createInstanceRoutes(deps: InstanceRouteDeps): RouteHandler {
if (!addedChatgpt && !addedAntigravity && !isAddedEndpoint(instanceId, instances[instanceId]) && (instances[instanceId].driver !== "claudeAgent" || instanceId === "claude")) {
return json(res, 400, { error: "Only added Claude, ChatGPT, and Antigravity accounts and OpenAI-compatible endpoints can be removed here." });
}
- if (cfg.defaultModelSelection?.instanceId === instanceId || store.bots.some((bot) =>
- bot.modelSelection.instanceId === instanceId || bot.fallback?.some(candidate => candidate.instanceId === instanceId) || store.tasks(bot.id).some((task) => task.modelSelection?.instanceId === instanceId)) ||
- busyProviderSelections().some((selection) => selection.instanceId === instanceId)) {
+ if (providerInUse(instanceId)) {
return json(res, 409, { error: "Choose another account for the bots and default model using this account before removing it." });
}
// OpenMausBot keeps a ChatGPT account's sign-in in its own data folder: removing the account clears it.
diff --git a/src/components/EnginesSettings.hidden.test.ts b/src/components/EnginesSettings.hidden.test.ts
new file mode 100644
index 0000000000..7776d9f32b
--- /dev/null
+++ b/src/components/EnginesSettings.hidden.test.ts
@@ -0,0 +1,53 @@
+// @vitest-environment happy-dom
+import { createElement } from "react";
+import { flushSync } from "react-dom";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+const fixture = vi.hoisted(() => ({ hidden: [] as Array<{ instanceId: string; displayName: string }>, calls: [] as Array<{ path: string; body?: unknown }>, refresh: vi.fn() }));
+vi.mock("@/state/store", async (original) => ({
+ ...await original<typeof import("@/state/store")>(),
+ useStore: () => ({ state: { instances: [] }, refreshInstances: fixture.refresh }),
+ api: async (path: string, init?: RequestInit) => {
+ fixture.calls.push({ path, ...(init?.body ? { body: JSON.parse(String(init.body)) } : {}) });
+ if (path === "/api/instances/hidden") return { instances: fixture.hidden };
+ fixture.hidden = [];
+ return { instances: [] };
+ },
+}));
+
+const { HiddenEngines } = await import("./EnginesSettings");
+
+let root: Root;
+let host: HTMLElement;
+const settle = () => new Promise((done) => setTimeout(done, 0));
+beforeEach(() => {
+ fixture.calls = [];
+ fixture.refresh.mockReset();
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+});
+afterEach(() => { flushSync(() => root.unmount()); host.remove(); });
+
+describe("hidden providers in Settings", () => {
+ it("shows nothing while no provider is hidden", async () => {
+ fixture.hidden = [];
+ flushSync(() => root.render(createElement(HiddenEngines)));
+ await settle();
+ expect(host.querySelector("[data-hidden-engines]")).toBeNull();
+ });
+
+ it("lists hidden providers, folded, and unhides one with a click", async () => {
+ fixture.hidden = [{ instanceId: "hermes", displayName: "Hermes" }, { instanceId: "pi", displayName: "pi" }];
+ flushSync(() => root.render(createElement(HiddenEngines)));
+ await settle();
+ const list = host.querySelector("[data-hidden-engines]")!;
+ expect(list.querySelector("summary")!.textContent).toBe("Hidden (2)");
+ expect(list.textContent).toContain("Hermes");
+ flushSync(() => host.querySelector<HTMLButtonElement>('[data-unhide-engine="hermes"]')!.click());
+ await settle();
+ expect(fixture.calls).toContainEqual({ path: "/api/instances/hermes", body: { hidden: false } });
+ expect(fixture.refresh).toHaveBeenCalled();
+ });
+});
diff --git a/src/components/EnginesSettings.tsx b/src/components/EnginesSettings.tsx
index 1456a6527a..5648fcea7f 100644
--- a/src/components/EnginesSettings.tsx
+++ b/src/components/EnginesSettings.tsx
@@ -213,6 +213,17 @@ function EngineAdvanced({ instance }: { instance: InstanceInfo }) {
.finally(() => setSwitching(false));
};
+ /** Out of every model list until Unhide; the CLI and its sign-in stay as they are. Refused while something uses it. */
+ const hide = () => {
+ if (switching || updating) return;
+ setSwitching(true);
+ setError(null);
+ api(`/api/instances/${encodeURIComponent(instance.instanceId)}`, { method: "PATCH", body: JSON.stringify({ hidden: true }) })
+ .then(() => Promise.resolve(refreshInstances()).catch(() => {}))
+ .catch((e) => setError(e.message))
+ .finally(() => setSwitching(false));
+ };
+
const updateClaude = () => {
if (switching || updating) return;
setUpdating(true);
@@ -269,6 +280,16 @@ function EngineAdvanced({ instance }: { instance: InstanceInfo }) {
{switching ? t("engines.resetting") : t("engines.reset")}
</button>
)}
+ <button
+ type="button"
+ data-hide-engine={instance.instanceId}
+ onClick={hide}
+ disabled={switching || updating}
+ title={t("engines.hideHint")}
+ className="shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50"
+ >
+ {t("engines.hide")}
+ </button>
<button
onClick={() => setOpen((v) => !v)}
disabled={updating}
@@ -439,6 +460,49 @@ function SimpleEngines({ rows, isReady, renderEngine, more }: {
);
}
+/** Providers someone hid: listed apart, folded, each one click from coming back. */
+export function HiddenEngines() {
+ const { state, refreshInstances } = useStore();
+ const [hidden, setHidden] = useState<Array<{ instanceId: string; displayName: string }>>([]);
+ const [busy, setBusy] = useState<string | null>(null);
+ const [error, setError] = useState<string | null>(null);
+ useEffect(() => {
+ let alive = true;
+ // An older server has no such route: nothing is hidden there.
+ api<{ instances?: Array<{ instanceId: string; displayName: string }> } | undefined>("/api/instances/hidden")
+ .then((result) => { if (alive) setHidden(Array.isArray(result?.instances) ? result.instances : []); })
+ .catch(() => {});
+ return () => { alive = false; };
+ }, [state.instances]);
+ if (hidden.length === 0) return null;
+ const unhide = (instanceId: string) => {
+ setBusy(instanceId);
+ setError(null);
+ api(`/api/instances/${encodeURIComponent(instanceId)}`, { method: "PATCH", body: JSON.stringify({ hidden: false }) })
+ .then(() => Promise.resolve(refreshInstances()).catch(() => {}))
+ .catch((e) => setError(e.message))
+ .finally(() => setBusy(null));
+ };
+ return (
+ <details data-hidden-engines className="px-4">
+ <summary className="cursor-pointer text-[13px] font-medium text-ink-secondary hover:text-ink">{t("engines.hiddenTitle", { count: String(hidden.length) })}</summary>
+ <p className="mt-2 text-[12px] text-ink-secondary">{t("engines.hiddenHint")}</p>
+ <div className="mt-2 flex flex-col gap-1.5">
+ {hidden.map((entry) => (
+ <div key={entry.instanceId} className="flex items-center justify-between gap-3 rounded-lg border border-hairline/40 bg-inset px-3 py-2">
+ <span className="min-w-0 truncate text-[13px] text-ink">{entry.displayName}</span>
+ <button type="button" data-unhide-engine={entry.instanceId} disabled={busy !== null} onClick={() => unhide(entry.instanceId)}
+ className="shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50">
+ {busy === entry.instanceId ? t("engines.unhiding") : t("engines.unhide")}
+ </button>
+ </div>
+ ))}
+ </div>
+ {error && <div role="alert" className="mt-1 text-[12px] text-danger">{error}</div>}
+ </details>
+ );
+}
+
export function EnginesSettings({ simple = false, more }: { simple?: boolean; more?: { id: string; open: boolean; onToggle: () => void } }) {
const { state } = useStore();
// Leaving Settings ends the "now uses the copy OpenMausBot installed" lines.
@@ -475,6 +539,7 @@ export function EnginesSettings({ simple = false, more }: { simple?: boolean; mo
<RefreshEngines />
</div>
<EngineSections instances={rows} isReady={isReady} renderEngine={renderEngine} />
+ <HiddenEngines />
<CacheKeepWarmSettings />
</div>
);
diff --git a/src/locales/en.json b/src/locales/en.json
index 56ce0025c5..f7dc6421cb 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -4177,6 +4177,12 @@
"engines.reset": "Reset",
"engines.resetting": "Resetting…",
"engines.setCli": "Set CLI…",
+ "engines.hide": "Hide",
+ "engines.hideHint": "Leave this provider out of every model list. Its app and sign-in stay as they are, and you can unhide it here.",
+ "engines.hiddenTitle": "Hidden ({count})",
+ "engines.hiddenHint": "Left out of every model list. Their apps and sign-ins are unchanged.",
+ "engines.unhide": "Unhide",
+ "engines.unhiding": "Unhiding…",
"engines.claudeUpdated": "Claude updated to {version}",
"engines.account.signInHint": "Run this exact command in a terminal on the computer running {app}, finish Claude CLI sign-in, then click Check account. If you are viewing {app} remotely, run it there, not on this device.",
"engines.account.powershell": "Use PowerShell for this command.",