Skip to content

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

Backup picker: note when a backup is another sign-in to the main AI

AdityaUmale152f3c464ebc
diff --git a/server/limit-failover.ts b/server/limit-failover.ts
index 64b6bd72b0..191a274286 100644
--- a/server/limit-failover.ts
+++ b/server/limit-failover.ts
@@ -3,14 +3,13 @@ import { type ServerText } from "../shared/server-text.ts";
// its own engine once that limit has reset or it is signed in again.
import { readFileSync } from "node:fs";
+import { otherSignInOfSameSubscription } from "../shared/limit-backup.ts";
import { sameModelSelection } from "../shared/thread-model.ts";
import type { ModelSelection } from "../shared/wire.ts";
import { writeFileAtomic } from "./atomic.ts";
import type { InstanceConfig } from "./contracts.ts";
import { hostTimeZone } from "./turn-clock.ts";
-/** Engines a person signs in to with a subscription whose usage limit refuses turns. */
-const SUBSCRIPTION_DRIVERS = new Set(["claudeAgent", "codex", "grokAgent"]);
/** An engine instance with one of these keys bills each use instead of drawing on a subscription's limit. */
const PAY_PER_USE_KEYS = ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "OPENAI_API_KEY", "CODEX_API_KEY", "XAI_API_KEY"];
@@ -21,7 +20,7 @@ type Engine = { instanceId: string; driverKind: string };
* accounts closed. Another engine, or a pay-per-use key on the same one, is fine. */
export function limitBackupAllowed(from: Engine, to: Engine, toConfig?: Pick<InstanceConfig, "environment" | "access">): boolean {
if (to.instanceId === from.instanceId) return false;
- if (to.driverKind !== from.driverKind || !SUBSCRIPTION_DRIVERS.has(from.driverKind)) return true;
+ if (!otherSignInOfSameSubscription(from, to)) return true;
return billsEachUse(toConfig);
}
diff --git a/shared/limit-backup.ts b/shared/limit-backup.ts
new file mode 100644
index 0000000000..dfb3cf1c20
--- /dev/null
+++ b/shared/limit-backup.ts
@@ -0,0 +1,11 @@
+/** Engines a person signs in to with a subscription whose usage limit refuses turns. */
+const SUBSCRIPTION_DRIVERS: ReadonlySet<string> = new Set(["claudeAgent", "codex", "grokAgent"]);
+
+type Engine = { instanceId: string; driverKind: string };
+
+/** `other` is another sign-in to `main`'s subscription engine. At `main`'s usage limit it never takes over (rotating
+ * accounts to get past a provider's usage limit breaks its terms), unless it bills each use instead of drawing on a
+ * plan; it still takes over while `main` is signed out. */
+export function otherSignInOfSameSubscription(main: Engine, other: Engine): boolean {
+ return other.instanceId !== main.instanceId && other.driverKind === main.driverKind && SUBSCRIPTION_DRIVERS.has(main.driverKind);
+}
diff --git a/src/components/bot-panel/BackupAis.tsx b/src/components/bot-panel/BackupAis.tsx
index bbfba741da..9ad2ceb52c 100644
--- a/src/components/bot-panel/BackupAis.tsx
+++ b/src/components/bot-panel/BackupAis.tsx
@@ -3,7 +3,7 @@ import { createPortal } from "react-dom";
import { ChevronDown, LifeBuoy, Plus } from "lucide-react";
import { cn } from "@/lib/cn";
-import { configuredModelInstances } from "@/lib/engine-rail";
+import { backupNote, configuredModelInstances } from "@/lib/engine-rail";
import { t } from "@/lib/i18n";
import type { Typeahead } from "@/lib/menu-keys";
import { pickerPlacement, type PickerPlacement } from "@/lib/picker-placement";
@@ -118,8 +118,11 @@ function BackupChooser({ bot, current, exclude, onPick, label, title, buttonRef,
instances: state.instances, listed, selection: current ?? NO_SELECTION,
bot: { name: bot.name, selection: bot.modelSelection }, query, expanded, probing: NOTHING_PROBED, loading, refreshing,
});
- const groups = built.groups.map((group) => group.instance.instanceId === bot.modelSelection.instanceId
- ? { ...group, note: t("botPanel.backups.sameAccount") } : group);
+ const main = state.instances.find((instance) => instance.instanceId === bot.modelSelection.instanceId);
+ const groups = built.groups.map((group) => {
+ const note = backupNote(main, group.instance);
+ return note ? { ...group, note } : group;
+ });
return { ...built, groups, ...(current ? {} : { current: null }) };
};
diff --git a/src/components/bot-settings/ModelSection.tsx b/src/components/bot-settings/ModelSection.tsx
index 28e1b8dcb8..8b17c45b1d 100644
--- a/src/components/bot-settings/ModelSection.tsx
+++ b/src/components/bot-settings/ModelSection.tsx
@@ -7,6 +7,7 @@ import { ProposalStatus } from "./ProposalStatus";
import { ThreadModelsLine } from "../ThreadModelsLine";
import { t } from "@/lib/i18n";
import { Select } from "../Select";
+import { backupNote } from "@/lib/engine-rail";
export function ModelSection({ bot }: { bot: Bot }) {
const { state, dispatch } = useStore();
@@ -90,6 +91,11 @@ export function FallbackChain({ bot, onChange }: { bot: Bot; onChange: (fallback
const available = state.instances.filter((instance) =>
instance.snapshot.state === "available" && Boolean(instance.models.default.trim()) && freeModel(instance) !== undefined);
const nameOf = (instanceId: string) => state.instances.find((instance) => instance.instanceId === instanceId)?.displayName ?? instanceId;
+ const main = state.instances.find((instance) => instance.instanceId === bot.modelSelection.instanceId);
+ const backupLabel = (instance: InstanceInfo) => {
+ const note = backupNote(main, instance);
+ return note ? `${instance.displayName} · ${note}` : instance.displayName;
+ };
const modelsOf = (entry: NonNullable<Bot["fallback"]>[number], index: number) => {
const offered = offeredBy(state.instances.find((candidate) => candidate.instanceId === entry.instanceId))
.filter((model) => !taken(entry.instanceId, model.id, index));
@@ -143,8 +149,7 @@ export function FallbackChain({ bot, onChange }: { bot: Bot; onChange: (fallback
<option value="">{available.length === 0 ? t("model.fallback.none") : t("model.fallback.addOption")}</option>
{available.map((instance) => (
<option key={instance.instanceId} value={instance.instanceId}>
- {instance.instanceId === bot.modelSelection.instanceId
- ? `${instance.displayName} · ${t("botPanel.backups.sameAccount")}` : instance.displayName}
+ {backupLabel(instance)}
</option>
))}
</Select>
diff --git a/src/lib/engine-rail.test.ts b/src/lib/engine-rail.test.ts
index 2737914f03..22bb94cbb2 100644
--- a/src/lib/engine-rail.test.ts
+++ b/src/lib/engine-rail.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import type { InstanceInfo } from "@/state/store";
-import { configuredModelInstances, isClaudeAccount, modelsAwaitEngine, signInFamily, splitEngineRail } from "./engine-rail";
+import { backupNote, configuredModelInstances, isClaudeAccount, modelsAwaitEngine, signInFamily, splitEngineRail } from "./engine-rail";
describe("splitEngineRail", () => {
it("groups sign-in plans, pasted provider keys and Local engines", () => {
@@ -176,3 +176,26 @@ describe("signInFamily", () => {
expect(signInFamily({ driverKind: "codex" })).toBe("openai");
});
});
+
+describe("backupNote", () => {
+ const engine = (instanceId: string, driverKind: string, overrides: Partial<InstanceInfo> = {}): InstanceInfo => ({
+ instanceId, driverKind, displayName: instanceId, snapshot: { state: "available" },
+ models: { default: "m", options: [{ id: "m", label: "M" }] }, ...overrides,
+ });
+ const main = engine("codex", "codex");
+
+ it("says another sign-in to the main subscription AI is used only while the main one is signed out", () => {
+ expect(backupNote(main, engine("codex-sub1", "codex"))).toBe(
+ "Another sign-in to the main AI: used only while the main one is signed out, never at its usage limit (provider terms).");
+ expect(backupNote(engine("claude", "claudeAgent"), engine("claude-2", "claudeAgent"))).toMatch(/^Another sign-in/);
+ });
+
+ it("keeps the same-account note and says nothing for other AIs or pay-per-use keys", () => {
+ expect(backupNote(main, main)).toBe("Same account as the main AI: it shares the usage limit.");
+ expect(backupNote(main, engine("claude", "claudeAgent"))).toBeUndefined();
+ expect(backupNote(main, engine("codex-key", "codex", { access: "api" }))).toBeUndefined();
+ expect(backupNote(main, engine("codex-env", "codex", { snapshot: { state: "available", account: { method: "api-key" } } }))).toBeUndefined();
+ expect(backupNote(engine("ollama", "openaiChat"), engine("ollama-2", "openaiChat"))).toBeUndefined();
+ expect(backupNote(undefined, engine("codex-sub1", "codex"))).toBeUndefined();
+ });
+});
diff --git a/src/lib/engine-rail.ts b/src/lib/engine-rail.ts
index 4f6ca3aaa2..529306f607 100644
--- a/src/lib/engine-rail.ts
+++ b/src/lib/engine-rail.ts
@@ -1,4 +1,6 @@
import type { InstanceInfo } from "@/state/store";
+import { otherSignInOfSameSubscription } from "../../shared/limit-backup";
+import { t } from "@/lib/i18n";
export { engineDisplayName } from "@/lib/engine-name";
@@ -51,3 +53,14 @@ export function splitEngineRail<T>(instances: readonly T[]): {
}
return { subscription, api, custom };
}
+
+/** What a person should know about `backup` as a backup for the main AI `main`, if anything. Another subscription
+ * sign-in to the main AI takes over only while the main one is signed out, never at its usage limit (the server's
+ * limitBackupAllowed rule); a pay-per-use key on it still does. */
+export function backupNote(main: InstanceInfo | undefined, backup: InstanceInfo): string | undefined {
+ if (!main) return undefined;
+ if (backup.instanceId === main.instanceId) return t("botPanel.backups.sameAccount");
+ const billsEachUse = backup.access === "api" || backup.snapshot.account?.method === "api-key";
+ if (otherSignInOfSameSubscription(main, backup) && !billsEachUse) return t("botPanel.backups.otherSignIn");
+ return undefined;
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index a310f7f335..ebd3baab4c 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -4492,6 +4492,7 @@
"botPanel.backups.remove": "Remove {model} from backups",
"botPanel.backups.choose": "Choose a backup AI",
"botPanel.backups.sameAccount": "Same account as the main AI: it shares the usage limit.",
+ "botPanel.backups.otherSignIn": "Another sign-in to the main AI: used only while the main one is signed out, never at its usage limit (provider terms).",
"botPanel.appsNoneYet": "None yet",
"botPanel.apps.intro": "Switch on the apps {name} may use. Everything else stays off.",
"botPanel.apps.connectAnother": "Connect another app",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 3d0ebf4da6..de4a4a6291 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -7897,6 +7897,7 @@
"botPanel.backups.remove": "Remover {model} das reservas",
"botPanel.backups.choose": "Escolher uma IA reserva",
"botPanel.backups.sameAccount": "Usa a mesma conta da IA principal e compartilha o limite de uso.",
+ "botPanel.backups.otherSignIn": "Outra conta da IA principal: usada só enquanto a principal estiver desconectada, nunca no limite de uso (termos do provedor).",
"botPanel.appsNoneYet": "Nenhum ainda",
"botPanel.apps.intro": "Ligue os apps que {name} pode usar. Todo o resto fica desligado.",
"botPanel.apps.connectAnother": "Conectar outro app",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index 6c7a711aab..6a9bd09341 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -4241,6 +4241,7 @@
"botPanel.backups.remove": "從備用中移除 {model}",
"botPanel.backups.choose": "選擇備用 AI",
"botPanel.backups.sameAccount": "與主要 AI 使用同一個帳號:共用用量上限。",
+ "botPanel.backups.otherSignIn": "主要 AI 的另一個登入帳號:只在主要帳號登出時使用,達到用量上限時不會使用(服務條款)。",
"botPanel.appsNoneYet": "目前還沒有",
"botPanel.apps.intro": "開啟 {name} 可以使用的應用程式。其他一律保持關閉。",
"botPanel.apps.connectAnother": "連接其他應用程式",