Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(#6300): keep the Local VM's tools while a runtime is installed
milind-soni70859e001df5
diff --git a/server/index.ts b/server/index.tsindex b16efb1f5e..7c2bdf8d20 100644--- a/server/index.ts+++ b/server/index.ts@@ -1811,8 +1811,7 @@ const MAX_COMMS_DEPTH = 1;const MAX_WORKSPACE_BOTS = 100;const phoneProxyPath = SPAWNED_PROXIES.phone;-const researchAvailability = createResearchAvailability({ credential: () => researchCredential(cfg.treg?.key) }); researchAvailability.available();-const localVmAvailability = createLocalVmAvailability(() => containerRuntimeStatus());+const researchAvailability = createResearchAvailability({ credential: () => researchCredential(cfg.treg?.key) }); researchAvailability.available(); const localVmAvailability = createLocalVmAvailability(() => containerRuntimeStatus());function agentsIntegration(botId: string,threadId: string,diff --git a/server/local-vm-availability.test.ts b/server/local-vm-availability.test.tsindex 015178177c..b63f2d0cc2 100644--- a/server/local-vm-availability.test.ts+++ b/server/local-vm-availability.test.ts@@ -12,10 +12,28 @@ describe("whether this server can give a bot a Local VM", () => {expect(availability.available()).toBe(false);});- it("says no when the runtime is installed but its daemon is down", async () => {- const availability = createLocalVmAvailability(async () => ({ available: ["docker"], daemonUp: false }));+ it("says yes when the runtime is installed but its daemon is down, since a turn starts it", async () => {+ const availability = createLocalVmAvailability(async () => ({ available: ["podman"], daemonUp: false }));+ await flush();+ expect(availability.available()).toBe(true);+ });++ it("reads it again at most once a minute while the answer is no, so a runtime installed later shows up", async () => {+ let clock = 0;+ let runtimes: string[] = [];+ let probes = 0;+ const availability = createLocalVmAvailability(async () => { probes += 1; return { available: runtimes }; }, () => clock);await flush();expect(availability.available()).toBe(false);+ runtimes = ["docker"];+ clock = 59_999;+ expect(availability.available()).toBe(false);+ expect(probes).toBe(1);+ clock = 60_000;+ availability.available();+ await flush();+ expect(probes).toBe(2);+ expect(availability.available()).toBe(true);});it("says yes when a runtime is installed and its daemon answers", async () => {diff --git a/server/local-vm-availability.ts b/server/local-vm-availability.tsindex 86f82b8640..cf050b9ae6 100644--- a/server/local-vm-availability.ts+++ b/server/local-vm-availability.ts@@ -1,18 +1,35 @@-// Whether this server can give a bot a Local VM: a supported container runtime is installed on the host-// and its daemon answers. The answer is read once and kept, so the tools a conversation is listed do-// not change from turn to turn.+// Whether this server can give a bot a Local VM: a supported container runtime is installed on the host. A runtime+// whose daemon is down still counts, since a turn that needs the VM starts a stopped Podman machine itself. The answer+// is kept, so the tools a conversation is listed do not change from turn to turn; while it is "no" it is read again at+// most once a minute, so a runtime installed later shows up without a restart.export interface LocalVmRuntimeStatus {available?: readonly string[];daemonUp?: boolean;}-export function createLocalVmAvailability(probe: () => Promise<LocalVmRuntimeStatus>) {+const RECHECK_MS = 60_000;++export function createLocalVmAvailability(probe: () => Promise<LocalVmRuntimeStatus>, now: () => number = Date.now) {let usable = true;- void probe()- .then((status) => {- const available = Array.isArray(status?.available) ? status.available : null;- if (available) usable = available.length > 0 && status.daemonUp === true;- })- .catch(() => {});- return { available: () => usable };+ let checkedAt = 0;+ let checking = false;+ const check = () => {+ if (checking) return;+ checking = true;+ checkedAt = now();+ void probe()+ .then((status) => {+ const available = Array.isArray(status?.available) ? status.available : null;+ if (available) usable = available.length > 0;+ })+ .catch(() => {})+ .finally(() => { checking = false; });+ };+ check();+ return {+ available: () => {+ if (!usable && now() - checkedAt >= RECHECK_MS) check();+ return usable;+ },+ };}