Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
VPS settings: the add row takes optional limits, the alias change keeps its notice, the VPS link finds a field
milind-sonif8c130955c83
diff --git a/src/components/keys/KeysPage.dom.test.ts b/src/components/keys/KeysPage.dom.test.tsindex 1c7f50fc6e..3ada5101e0 100644--- a/src/components/keys/KeysPage.dom.test.ts+++ b/src/components/keys/KeysPage.dom.test.ts@@ -665,6 +665,44 @@ describe("Self-hosted VPS servers", () => {expect(field("production-vps CPU cores").value).toBe("8");});+ it("changes the default server's alias in place and says what the server answered", async () => {+ const { VpsConnection } = await import("./VpsServersPanel");+ setConfig(status({ sshAlias: "production-vps" }));+ fx.api.mockImplementation(async () => ({ ...status({ sshAlias: "new-vps" }), notice: "production-vps keeps its desktops" }));+ render(() => createElement(VpsConnection, { key: "vps" }));+ type(field("Self-hosted VPS SSH config alias"), "new-vps");+ await answered(() => button(rowFor("production-vps"), "Save").click());+ expect(lastBody()).toEqual({ vps: { sshAlias: "new-vps", memoryGb: 4, cpus: 2 } });+ expect(aliases()).toEqual(["new-vps"]);+ expect(rowFor("new-vps").querySelector("[role=status]")!.textContent).toContain("keeps its desktops");+ });++ it("adds a server with its own limits after the host refused the ones it would inherit", async () => {+ const { VpsConnection } = await import("./VpsServersPanel");+ setConfig(status({ sshAlias: "production-vps", memoryGb: 16 }));+ fx.api.mockRejectedValueOnce(new Error("spare has about 8 GB of memory. Choose 8 GB or less."));+ render(() => createElement(VpsConnection, { key: "vps" }));+ expect(field("Memory (GB)").placeholder).toBe("16");+ type(field("Server name"), "Spare");+ type(field("Server SSH config alias"), "spare");+ await answered(() => button(host, "Add").click());+ expect(lastBody()).toEqual({ vpsServers: [{ name: "Spare", sshAlias: "spare" }] });+ expect(host.querySelector("[data-vps-servers] [role=alert]")!.textContent).toContain("Choose 8 GB or less");+ fx.api.mockImplementation(echo({ sshAlias: "production-vps", memoryGb: 16 }));+ type(field("Memory (GB)"), "8");+ await answered(() => button(host, "Add").click());+ expect(lastBody()).toEqual({ vpsServers: [{ name: "Spare", sshAlias: "spare", memoryGb: 8 }] });+ expect(aliases()).toEqual(["production-vps", "spare"]);+ expect(field("Memory (GB)").value).toBe("");+ });++ it("focuses the default server's alias when a link asks for the VPS row", async () => {+ setConfig(status({ sshAlias: "production-vps" }));+ page();+ flushSync(() => { openKeySettings("vps"); });+ await vi.waitFor(() => expect(document.activeElement).toBe(field("Self-hosted VPS SSH config alias")));+ });+it("shows why a named server was refused and keeps what was typed", async () => {const { VpsConnection } = await import("./VpsServersPanel");fx.api.mockRejectedValue(new Error("vpsServers: each server needs its own SSH alias"));diff --git a/src/components/keys/VpsServerEditor.tsx b/src/components/keys/VpsServerEditor.tsxindex f5aa68e087..54f986a83b 100644--- a/src/components/keys/VpsServerEditor.tsx+++ b/src/components/keys/VpsServerEditor.tsx@@ -11,9 +11,8 @@ type VpsStatus = ConfigStatus["vps"];export type VpsNamedServer = NonNullable<VpsStatus["servers"]>[number];type Range = { min: number; max: number; fallback: number };-/** The server's limits for one desktop (server/container-limits.ts); empty is "not set". */-const MEMORY_GB: Range = { min: 2, max: 128, fallback: 4 };-const CPUS: Range = { min: 1, max: 64, fallback: 2 };+export const MEMORY_GB: Range = { min: 2, max: 128, fallback: 4 };+export const CPUS: Range = { min: 1, max: 64, fallback: 2 };const NO_SERVERS: VpsNamedServer[] = [];/** One VPS save at a time across every editor: each one sends a whole list, so two at once would undo each other. */@@ -43,14 +42,14 @@ export function useVpsSave() {}/** Empty is "not set"; anything else must be a whole number in range (null when it is not). */-function limitValue(text: string, range: Range): number | undefined | null {+export function limitValue(text: string, range: Range): number | undefined | null {if (text.trim() === "") return undefined;const n = Number(text);return Number.isInteger(n) && n >= range.min && n <= range.max ? n : null;}const asText = (n: number | undefined) => (n === undefined ? "" : String(n));-function LimitInput({ label, unit, value, onChange, range, placeholder, disabled, onEnter }: {+export function LimitInput({ label, unit, value, onChange, range, placeholder, disabled, onEnter }: {label: string; unit: string; value: string; onChange: (value: string) => void; range: Range; placeholder: number; disabled: boolean; onEnter: () => void;}) {return (@@ -151,6 +150,7 @@ export function VpsServerEditor({ alias, onRemoved }: { alias: string; onRemovedonChange={(e) => { setError(null); setName(e.target.value); }}onKeyDown={(e) => e.key === "Enter" && submit()}disabled={busy}+ data-key-input={isDefault ? "" : undefined}aria-label={isDefault ? t("keys.vps.aria") : t("keys.vps.servers.nameOf", { alias })}autoComplete="off"spellCheck={false}diff --git a/src/components/keys/VpsServersPanel.tsx b/src/components/keys/VpsServersPanel.tsxindex 86c52daa1f..f644292a7b 100644--- a/src/components/keys/VpsServersPanel.tsx+++ b/src/components/keys/VpsServersPanel.tsx@@ -4,7 +4,7 @@ import { useStoreSelector } from "@/state/store-select";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";import { KEY_FIELD } from "./KeyRow";-import { useVpsSave, useVpsSaving, VpsServerEditor, type VpsNamedServer } from "./VpsServerEditor";+import { CPUS, LimitInput, limitValue, MEMORY_GB, useVpsSave, useVpsSaving, VpsServerEditor, type VpsNamedServer } from "./VpsServerEditor";const NO_SERVERS: VpsNamedServer[] = [];/** Not an alias (an alias starts with a letter or digit), so it never matches a server row. */@@ -24,7 +24,7 @@ export function VpsConnection() {{t("keys.vps.descAfter")}</p><p className="text-[12px] leading-4 text-ink-secondary">{t("keys.vps.anyMachine")}</p>- {defaultAlias ? <VpsServerEditor key={defaultAlias} alias={defaultAlias} onRemoved={setNotice} /> : <AddDefault onNotice={setNotice} />}+ {defaultAlias ? <VpsServerEditor alias={defaultAlias} onRemoved={setNotice} /> : <AddDefault onNotice={setNotice} />}{notice && <div role="status" className="text-[12px] leading-4 text-ink-secondary">{notice}</div>}<VpsServers /><p className="text-[12px] leading-4 text-ink-secondary">{t("keys.vps.limitsHint")}</p>@@ -32,7 +32,7 @@ export function VpsConnection() {);}-/** No default server yet: its SSH alias, as before limits came in. */+/** The first server becomes the default: only its SSH alias is asked for. */function AddDefault({ onNotice }: { onNotice: (notice: string | null) => void }) {const save = useVpsSave();const saving = useVpsSaving();@@ -70,17 +70,24 @@ function AddDefault({ onNotice }: { onNotice: (notice: string | null) => void })/** Named servers a bot can be put on from its own settings. Saving the list never moves a bot. */function VpsServers() {const servers = useStoreSelector((s) => s.config?.vps?.servers ?? NO_SERVERS);+ const inherited = useStoreSelector((s) => ({ memoryGb: s.config?.vps?.memoryGb ?? MEMORY_GB.fallback, cpus: s.config?.vps?.cpus ?? CPUS.fallback }), (a, b) => a.memoryGb === b.memoryGb && a.cpus === b.cpus);const save = useVpsSave();const saving = useVpsSaving();const [name, setName] = useState("");const [alias, setAlias] = useState("");+ const [memory, setMemory] = useState("");+ const [cpus, setCpus] = useState("");const [error, setError] = useState<string | null>(null);+ const memoryGb = limitValue(memory, MEMORY_GB);+ const cpuCount = limitValue(cpus, CPUS);+ const canAdd = saving === null && Boolean(name.trim()) && Boolean(alias.trim()) && memoryGb !== null && cpuCount !== null;const add = () => {- if (saving !== null || !name.trim() || !alias.trim()) return;+ if (!canAdd) return;setError(null);- save({ vpsServers: [...servers, { name: name.trim(), sshAlias: alias.trim() }] }, "")- .then(() => { setName(""); setAlias(""); }, (e) => setError(e.message));+ const server = { name: name.trim(), sshAlias: alias.trim(), ...(memoryGb === undefined ? {} : { memoryGb }), ...(cpuCount === undefined ? {} : { cpus: cpuCount }) };+ save({ vpsServers: [...servers, server] }, "")+ .then(() => { setName(""); setAlias(""); setMemory(""); setCpus(""); }, (e) => setError(e.message));};return (@@ -112,7 +119,9 @@ function VpsServers() {spellCheck={false}className={cn(KEY_FIELD, "w-auto min-w-[min(100%,10rem)] flex-1 font-mono")}/>- <button type="button" onClick={add} disabled={saving !== null || !name.trim() || !alias.trim()} className="ui-button shrink-0">+ <LimitInput label={t("keys.vps.memory")} unit={t("keys.vps.unitGb")} value={memory} onChange={(next) => { setError(null); setMemory(next); }} range={MEMORY_GB} placeholder={inherited.memoryGb} disabled={saving !== null} onEnter={add} />+ <LimitInput label={t("keys.vps.cpus")} unit={t("keys.vps.unitCores")} value={cpus} onChange={(next) => { setError(null); setCpus(next); }} range={CPUS} placeholder={inherited.cpus} disabled={saving !== null} onEnter={add} />+ <button type="button" onClick={add} disabled={!canAdd} className="ui-button shrink-0">{saving === "" ? <Loader2 size={13} className="animate-spin" aria-hidden="true" /> : t("keys.vps.servers.add")}</button></div>diff --git a/src/locales/en.json b/src/locales/en.jsonindex 7f1655c95f..713f66640a 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -4310,6 +4310,8 @@"keys.vps.serverCpusAria": "{name} CPU cores","keys.vps.unitGb": "GB","keys.vps.unitCores": "cores",+ "keys.vps.memory": "Memory (GB)",+ "keys.vps.cpus": "CPU cores","keys.vps.limitsHint": "Memory and cores are the most each bot's desktop on a server may use. Left empty, a named server uses the default server's, and the default uses 4 GB and 2 cores. A running desktop takes a change the next time it starts. Saving checks that the machine has them.","usage.title": "Usage","planUsage.title": "Plan usage",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 10b7a07e51..ccb755c63d 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -4103,6 +4103,8 @@"keys.vps.serverCpusAria": "Núcleos de CPU de {name}","keys.vps.unitGb": "GB","keys.vps.unitCores": "núcleos",+ "keys.vps.memory": "Memória (GB)",+ "keys.vps.cpus": "Núcleos de CPU","keys.vps.limitsHint": "Memória e núcleos são o máximo que o desktop de cada bot em um servidor pode usar. Vazios, um servidor nomeado usa os do servidor padrão, e o padrão usa 4 GB e 2 núcleos. Um desktop em execução assume a mudança na próxima vez que iniciar. Ao salvar, verificamos se a máquina tem esses recursos.","usage.title": "Uso","planUsage.title": "Uso do plano",