Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Backups: keep rows mounted when a model changes; the default must be offered too
AdityaUmalea3e944e87a51
diff --git a/src/components/bot-panel/BackupAis.dom.test.ts b/src/components/bot-panel/BackupAis.dom.test.tsindex 44ec61b3ed..049f382508 100644--- a/src/components/bot-panel/BackupAis.dom.test.ts+++ b/src/components/bot-panel/BackupAis.dom.test.ts@@ -108,6 +108,13 @@ describe("a bot's backup AIs in Simple", () => {expect(onChange).toHaveBeenCalledWith([{ instanceId: "codex", model: "gpt-5.5-mini" }, { instanceId: "gemini", model: "gemini-3-pro" }]);});+ it("keeps the row (and so the focus in it) when its model changes", () => {+ render([{ instanceId: "codex", model: "gpt-5.5" }]);+ const row = host.querySelector("[data-backup]");+ render([{ instanceId: "codex", model: "gpt-5.5-mini" }]);+ expect(host.querySelector("[data-backup]"), "the same row, not a new one").toBe(row);+ });+it("removes one and keeps the rest in order", () => {render([{ instanceId: "codex", model: "gpt-5.5" }, { instanceId: "gemini", model: "gemini-3-pro" }]);const remove = host.querySelector('[data-backup="codex"] [data-panel-action=backup-remove]');diff --git a/src/components/bot-panel/BackupAis.tsx b/src/components/bot-panel/BackupAis.tsxindex c763d711da..da188e2d85 100644--- a/src/components/bot-panel/BackupAis.tsx+++ b/src/components/bot-panel/BackupAis.tsx@@ -238,7 +238,7 @@ export function BackupAis({ bot, onChange }: { bot: Bot; onChange: (fallback: Ba{chain.map((entry, index) => {const { instance, name, short } = describe(entry);return (- <li key={modelKey(entry.instanceId, entry.model)} data-backup={entry.instanceId} className="flex min-w-0 items-center gap-1.5">+ <li key={index} data-backup={entry.instanceId} className="flex min-w-0 items-center gap-1.5"><span className="w-3 shrink-0 text-[12px] tabular-nums text-ink-tertiary" aria-hidden="true">{index + 1}</span><BackupChooserbot={bot}diff --git a/src/components/bot-settings/ModelSection.test.ts b/src/components/bot-settings/ModelSection.test.tsindex a233e4c04b..a19fb885ff 100644--- a/src/components/bot-settings/ModelSection.test.ts+++ b/src/components/bot-settings/ModelSection.test.ts@@ -104,6 +104,18 @@ describe("a bot's backup models", () => {expect(onChange).toHaveBeenCalledWith([{ instanceId: "codex", model: "gpt-a" }]);});+ it("never saves a default the account cannot use now, and takes the next model it offers", () => {+ const blocked = engine("codex", "Codex", ["gpt-a", "gpt-b"]);+ blocked.models.options[0] = { ...blocked.models.options[0]!, orgBlocked: true } as never;+ instances.splice(1, 1, blocked);+ const onChange = vi.fn();+ control(FallbackChain({ bot: bot([]), onChange }), "Add a backup AI")!.props.onChange({ target: { value: "codex" } });+ expect(onChange).toHaveBeenCalledWith([{ instanceId: "codex", model: "gpt-b" }]);+ instances.splice(1, 1, engine("codex", "Codex", ["gpt-a", "gpt-b"], false));+ expect(renderToStaticMarkup(createElement(FallbackChain, { bot: bot([]), onChange: vi.fn() })), "a signed-out account is not offered").not.toContain('<option value="codex">');+ instances.splice(1, 1, engine("codex", "Codex", ["gpt-a", "gpt-b"]));+ });+it("keeps showing a saved model the engine no longer lists", () => {const markup = renderToStaticMarkup(createElement(FallbackChain, { bot: bot([{ instanceId: "codex", model: "gpt-old" }]), onChange: vi.fn() }));expect(markup).toMatch(/aria-label="Model for Codex"[^>]*>.*<option value="gpt-old" selected="">gpt-old<\/option>/);diff --git a/src/components/bot-settings/ModelSection.tsx b/src/components/bot-settings/ModelSection.tsxindex 503d2862cd..13c65984e9 100644--- a/src/components/bot-settings/ModelSection.tsx+++ b/src/components/bot-settings/ModelSection.tsx@@ -80,7 +80,12 @@ export function FallbackChain({ bot, onChange }: { bot: Bot; onChange: (fallback|| chain.some((entry, at) => at !== except && entry.instanceId === instanceId && entry.model === model);const offeredBy = (instance: InstanceInfo | undefined) =>instance?.models.options.filter((model) => !model.orgBlocked && (instance.snapshot.authenticated !== false || model.custom)) ?? [];- const freeModel = (instance: InstanceInfo) => [instance.models.default, ...offeredBy(instance).map((model) => model.id)]+ // The default too must be one the account offers now: not blocked, and signed in unless it is a custom model.+ const defaultOffered = (instance: InstanceInfo) => {+ const listed = instance.models.options.find((model) => model.id === instance.models.default);+ return listed ? offeredBy(instance).includes(listed) : instance.snapshot.authenticated !== false;+ };+ const freeModel = (instance: InstanceInfo) => [...(defaultOffered(instance) ? [instance.models.default] : []), ...offeredBy(instance).map((model) => model.id)].find((model) => model.trim() && !taken(instance.instanceId, model));const available = state.instances.filter((instance) =>instance.snapshot.state === "available" && Boolean(instance.models.default.trim()) && freeModel(instance) !== undefined);@@ -107,7 +112,7 @@ export function FallbackChain({ bot, onChange }: { bot: Bot; onChange: (fallback{chain.length > 0 && (<ol className="mt-3 flex flex-col gap-1">{chain.map((entry, index) => (- <li key={`${entry.instanceId}\u0000${entry.model}`} className="flex items-center gap-2 rounded-lg bg-inset px-3 py-1.5 text-[13px]">+ <li key={index} className="flex items-center gap-2 rounded-lg bg-inset px-3 py-1.5 text-[13px]"><span className="w-4 shrink-0 tabular-nums text-ink-secondary">{index + 1}.</span><span className="min-w-0 flex-1 truncate text-ink">{nameOf(entry.instanceId)}</span><Select size="sm" className="max-w-[45%] shrink-0" value={entry.model}