Skip to content

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

Stop asking to use this computer when the bot already works on it (#4157)

Aditya Umale2893da37acab
diff --git a/server/host-lazy-claim.e2e.test.ts b/server/host-lazy-claim.e2e.test.ts
index cf0393741b..e4ab5287e8 100644
--- a/server/host-lazy-claim.e2e.test.ts
+++ b/server/host-lazy-claim.e2e.test.ts
@@ -394,4 +394,29 @@ describe("lazy host claim and pin on use (issue #1650)", () => {
writeFileSync(finishFile, "finish");
await idle(bot.id, task.threadId);
}, 60_000);
+
+ // Like the tests above, this needs the desktop driver fixture, which only macOS and Windows have here.
+ itAutoHost("never asks in a thread the app pinned to this computer once the bot works on this computer", async () => {
+ await start();
+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Works On Bot" });
+ const { task } = await apiOk("POST", `/api/bots/${bot.id}/tasks`, {});
+ await apiOk("PATCH", `/api/bots/${bot.id}`, { computer: "local" });
+ await stop();
+ // The pin an Auto turn left before the person set Works on to This computer, as bots.json keeps it.
+ const bots = JSON.parse(readFileSync(join(data, "bots.json"), "utf8")) as any[];
+ Object.assign(bots.find((one: any) => one.id === bot.id).tasks.find((one: any) => one.threadId === task.threadId),
+ { surface: "local", surfaceSource: "auto" });
+ writeFileSync(join(data, "bots.json"), JSON.stringify(bots, null, 2));
+ await start();
+ expect(savedTask(bot.id, task.threadId)).toMatchObject({ surface: "local", surfaceSource: "auto" });
+ resetTurn();
+ await apiOk("POST", `/api/bots/${bot.id}/messages`, { text: "Move the mouse slowly.", threadId: task.threadId });
+ await busy(bot.id, task.threadId);
+ expect(await gate(mountedComputer(await dumpFor(bot.id)))).toEqual({ held: false, helpOpen: false });
+ const cards = ((await apiOk("GET", `/api/threads/${task.threadId}/messages?limit=200`)).messages as any[])
+ .filter((message) => message.card?.tool === "use_your_computer");
+ expect(cards).toHaveLength(0);
+ writeFileSync(finishFile, "finish");
+ await idle(bot.id, task.threadId);
+ }, 60_000);
});
diff --git a/server/index.ts b/server/index.ts
index a9bc97d1bf..fcac530d48 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -506,7 +506,7 @@ import { keepTransient, lazyClaimRetryText, settledWithin, startAutoVmClaim, wit
import { CONTROL_ACT_WITHIN_MS, CONTROL_BUSY, CONTROL_HANDED_BACK, CONTROL_WAIT_MS, CONTROL_WAITED, controlRefusal, type ControlState } from "./control-client.ts";
import { computerFreeAfterText, computerParkedText, computerPersonAwayText, computerStoppedWaitingText, computerWaitingText, type ComputerHolder } from "./computer-wait.ts";
import { modelContextWindow } from "./model-context-window.ts";
-import { browserIsThePlace, chosenPin, cloudPlaceRefusal, computerSkippedNote, computerToolsRefusal, parseSurface, PlaceUnavailableError, placeUnavailable, resolveSurface, surfaceLabel, surfaceOfComputerKind, surfacePrompt, type ComputerWant, type PlaceSource, type Surface } from "./surface.ts";
+import { browserIsThePlace, chosenPin, cloudPlaceRefusal, computerSkippedNote, computerToolsRefusal, parseSurface, pinSource, PlaceUnavailableError, placeUnavailable, resolveSurface, surfaceLabel, surfaceOfComputerKind, surfacePrompt, type ComputerWant, type PlaceSource, type Surface } from "./surface.ts";
import { cloudRefusal, type PlaceRow } from "../shared/place-view.ts";
import {
PendingTurnCancellations,
@@ -8093,7 +8093,7 @@ async function beginTurn(
const namedPlace = teamComputer || wants === undefined || wants === "off" ? undefined : wants;
const placeSource: PlaceSource | undefined = !namedPlace ? undefined
: opts?.runOn === "cloud" ? "routine"
- : plan.pinned ? (dispatchTask?.surfaceSource === "auto" ? "auto-pin" : "pin")
+ : plan.pinned ? pinSource(plan.pinned, dispatchTask, bot.computer)
: "works-on";
if (wants === "cloud" && placeSource) {
const unsupported = cloudPlaceRefusal(cloudEngine(instance, bot.modelSelection.model), placeSource, bot.name)
diff --git a/server/surface.test.ts b/server/surface.test.ts
index 2bb0f96a0c..864523f965 100644
--- a/server/surface.test.ts
+++ b/server/surface.test.ts
@@ -7,6 +7,7 @@ import {
computerSkippedNote,
computerToolsRefusal,
parseSurface,
+ pinSource,
placeUnavailable,
resolveSurface,
surfaceOfComputerKind,
@@ -24,6 +25,17 @@ describe("browserIsThePlace", () => {
});
});
+describe("pinSource", () => {
+ it("counts a turn's own pin to the place Works on names as Works on, so This computer is not asked for again", () => {
+ expect(pinSource("local", { surfaceSource: "auto" }, "local")).toBe("works-on");
+ expect(pinSource("local", { surfaceSource: "auto" }, undefined)).toBe("auto-pin");
+ expect(pinSource("local", { surfaceSource: "auto" }, "vm")).toBe("auto-pin");
+ expect(pinSource("local", { surfaceSource: "user" }, "local")).toBe("pin");
+ expect(pinSource("local", {}, undefined)).toBe("pin");
+ expect(pinSource("local", undefined, "cloud")).toBe("pin");
+ });
+});
+
describe("chosenPin", () => {
// The browser's tools are loaded up front where the browser is the chosen place: decided on that alone, the turn that
// pinned the browser on its own hands the next turn the browser exactly as it was handed itself.
diff --git a/server/surface.ts b/server/surface.ts
index 781c0a18e4..f1fee0fcf7 100644
--- a/server/surface.ts
+++ b/server/surface.ts
@@ -92,6 +92,13 @@ export function chosenPin(task: { surface?: Surface; surfaceSource?: "user" | "a
return task?.surfaceSource === "auto" ? null : task?.surface;
}
+/** Where a turn's pinned place came from. A pin a turn made on its own to the place Works on already names is Works on:
+ * the person chose that place, so it is never asked for again (only a turn on Auto asks before using this computer). */
+export function pinSource(pinned: Surface, task: { surfaceSource?: "user" | "auto" } | undefined, destination: Destination): PlaceSource {
+ if (task?.surfaceSource !== "auto") return "pin";
+ return pinned === destination ? "works-on" : "auto-pin";
+}
+
export function cloudPlaceRefusal(engine: CloudEngine & { name: string }, source: PlaceSource, bot: string): PlaceUnavailableError | null {
if (canWorkOnCloud(engine)) return null;
return placeUnavailable("cloud", { state: "cc-cannot", params: { bot, model: engine.name }, source });