Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Settings on a server's own page: Choose what it can use, so its folders and terminal can be given there
AdityaUmale7eab53667ffe
diff --git a/electron/lend-own-server.node-test.mjs b/electron/lend-own-server.node-test.mjsindex 66d1c40226..292be422f8 100644--- a/electron/lend-own-server.node-test.mjs+++ b/electron/lend-own-server.node-test.mjs@@ -227,7 +227,7 @@ test("the menu-bar item keeps its Clouds' terminal switch only while a Cloud is});/** main's channels and popup, with this desktop's lending and native dialogs stood in for. */-function mainLending({ response = 1, own = true, flag = false, offer, refusal = "shared", screen = async () => ({ ready: true, lent: true, reason: null, fix: null }), now = () => 1_000 } = {}) {+function mainLending({ response = 1, own = true, flag = false, offer, refusal = "shared", openSettings = () => {}, screen = async () => ({ ready: true, lent: true, reason: null, fix: null }), now = () => 1_000 } = {}) {const handlers = new Map(), calls = { lent: [], declined: [], saved: [], revoked: [], boxes: [] };const win = { isDestroyed: () => false, webContents: { getURL: () => `${GARAGE}/` } };const info = { sessionId: randomUUID(), environmentId: randomUUID() };@@ -246,7 +246,7 @@ function mainLending({ response = 1, own = true, flag = false, offer, refusal =const lending = installServerLending({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, guard: (_channel, handler) => handler, sharing: () => controller,dialogs: { chooseFolder: async () => null, confirmServerAccess: async () => true }, validate: async folders => folders ?? [], dialog, window: () => win,saved: id => { if (id !== garage.id) throw new Error("unknown"); return garage; }, candidate: env => !env.cloud && !env.team && !env.home, flag: async () => flag,- environments: () => [garage, { id: "acme", name: "Acme", origin: "https://omb-t-acme.fly.dev", team: { id: "t" } }], active: () => garage,+ environments: () => [garage, { id: "acme", name: "Acme", origin: "https://omb-t-acme.fly.dev", team: { id: "t" } }], active: () => garage, openSettings,// This app's own page sends an empty event here; the server's own page sends { page: env }.local: event => !event?.page && !event?.other, page: event => event?.page ?? null, screen, allowScreen: async () => { calls.allowScreen = (calls.allowScreen ?? 0) + 1; }, now });return { handlers, calls, lending, win, info };@@ -356,6 +356,20 @@ test("the switch: one tap on this app's own page lends and stops at once; a servassert.deepEqual(notOwn.calls.lent, []);});+test("Choose what it can use on a server's own page opens This computer's Settings for that server only, once it is lent", async () => {+ const opened = [];+ const page = mainLending({ response: 0, openSettings: id => opened.push(id) });+ assert.equal(await page.handlers.get("lend:choose")({ page: garage }, "acme"), false, "nothing to choose before it is lent");+ assert.deepEqual(opened, []);+ await page.handlers.get("lend:set")({ page: garage }, null, true);+ assert.equal(await page.handlers.get("lend:choose")({ page: garage }, "acme"), true);+ assert.deepEqual(opened, ["garage"], "the page's own server, whatever id it sends");+ await assert.rejects(page.handlers.get("lend:choose")({ page: null, other: true }, "garage"), /main desktop window/);+ const notOwn = mainLending({ own: false, openSettings: id => opened.push(id) });+ assert.equal(await notOwn.handlers.get("lend:choose")({ page: garage }, null), false);+ assert.deepEqual(opened, ["garage"]);+});+test("a server that can't be lent to says why in one word; a Cloud or team never asks the server", async () => {for (const refusal of ["shared", "not-owner", "old", "team", "cloud", "unreachable"]) {const { handlers } = mainLending({ own: false, refusal });diff --git a/electron/preload.cjs b/electron/preload.cjsindex c0f316b2d4..0c09ede9c3 100644--- a/electron/preload.cjs+++ b/electron/preload.cjs@@ -739,6 +739,8 @@ const bridge = {? ipcRenderer.invoke("lend:set", isLocalPage ? id : null, on === true) : Promise.reject(new Error("Use the switch to change this.")),allowScreen: id => isLocalPage || navigator.userActivation?.isActive === true? ipcRenderer.invoke("lend:allow-screen", isLocalPage ? id : null) : Promise.reject(new Error("Use the button to allow this.")),+ choose: id => isLocalPage || navigator.userActivation?.isActive === true+ ? ipcRenderer.invoke("lend:choose", isLocalPage ? id : null) : Promise.reject(new Error("Use the button to choose this.")),wish: isLocalPage ? (address, on) => ipcRenderer.invoke("lend:wish", String(address ?? ""), on === true) : undefined,},confirm: message => ipcRenderer.invoke("dialog:confirm", message),diff --git a/electron/server-lending.mjs b/electron/server-lending.mjsindex 26d9170474..d4ef898851 100644--- a/electron/server-lending.mjs+++ b/electron/server-lending.mjs@@ -124,6 +124,14 @@ export function installServerLending({ ipcMain, guard, sharing, dialogs, validatawait sharing().lendOwn(env, firstGrant);return view(env);});+ /** Choose what it can use: This computer's Settings with that server's folders and terminal open, once it is lent. On a+ * server's own page it is about that server only, as the switch is. */+ ipcMain.handle("lend:choose", async (event, id) => {+ const { env } = target(event, id);+ if (!(await own(env)) || sharing().state(env.id).enabled !== true) return false;+ openSettings(env.id);+ return true;+ });/** macOS's Accessibility and Screen Recording, the one step the system itself asks for. */ipcMain.handle("lend:allow-screen", async (event, id) => {const { env } = target(event, id);diff --git a/src/components/settings/pages/AppPages.lend.dom.test.ts b/src/components/settings/pages/AppPages.lend.dom.test.tsindex ee5dd5b036..0c87100e1d 100644--- a/src/components/settings/pages/AppPages.lend.dom.test.ts+++ b/src/components/settings/pages/AppPages.lend.dom.test.ts@@ -51,3 +51,13 @@ it("on a server's own page in Simple mode, its lend switch sits under its row, aexpect(host.querySelector("[data-lend-switch]")?.textContent).toContain("Let hetzner-1’s bots use this computer");expect(host.querySelector("[data-settings-block=\"environments\"]"), "the inert environments group stays Advanced").toBeNull();});++it("on a server's own page, once lent, Choose what it can use opens This computer's Settings for that server's folders and terminal", async () => {+ const lendComputer = { state: vi.fn(async () => ({ name: "hetzner-1", lendable: true, on: true, connected: true, paused: false })), set: vi.fn(), allowScreen: vi.fn(), choose: vi.fn(async () => true) };+ Object.assign(window, { ogb: { workspaces: { add: vi.fn() }, lendComputer } });+ await mount();+ const choose = [...host.querySelectorAll("[data-lend-switch] button")].find(button => button.textContent === "Choose what it can use");+ expect(choose, "the server page's switch offers Choose once on").toBeTruthy();+ await act(async () => { (choose as HTMLButtonElement).click(); });+ expect(lendComputer.choose).toHaveBeenCalledWith(null);+});diff --git a/src/components/settings/pages/AppPages.tsx b/src/components/settings/pages/AppPages.tsxindex db2cb4b278..5f6dd984ed 100644--- a/src/components/settings/pages/AppPages.tsx+++ b/src/components/settings/pages/AppPages.tsx@@ -94,6 +94,8 @@ function PlacesFromHere() {const { place, ctx } = useSettingsShell();const others = useOtherPlaces("app");const workspaces = window.ogb?.workspaces;+ const lend = window.ogb?.lendComputer;+ const choose = lend?.choose;if (!workspaces) return null;return <><SettingsGroup label={t("settings.app.computers")} description={t("settings.app.computersLine")} block="your-computers">@@ -102,7 +104,7 @@ function PlacesFromHere() {<span className="text-[13px] leading-5 text-ink-secondary">{t("servers.current")}</span></SettingRow>{/* On a server's own page: the same switch its row has on This computer's page. */}- {window.ogb?.lendComputer && <LendComputerSwitch id={null} className="mx-4 mb-3 ms-[60px]" />}+ {lend && <LendComputerSwitch id={null} className="mx-4 mb-3 ms-[60px]" onChoose={choose && (() => void choose(null).catch(() => {}))} />}{others.map((other) => (<SettingRow key={other.key} title={other.name} leading={<PlaceBadge place={{ kind: other.kind === "computer" ? "computer" : "cloud", name: other.name, color: other.color }} size={24} />}subtitle={other.kind === "computer" ? t("servers.localHint") : undefined}>diff --git a/src/types/ogb.d.ts b/src/types/ogb.d.tsindex df649b7328..3fcc8216f1 100644--- a/src/types/ogb.d.ts+++ b/src/types/ogb.d.ts@@ -327,6 +327,8 @@ const __APP_VERSION__: string;set(id: string | null, on: boolean): Promise<DesktopLendView>;/** macOS: asks for Accessibility and Screen Recording, the one step the system itself requires. */allowScreen(id: string | null): Promise<DesktopLendView>;+ /** Opens This computer's Settings with that server's folders and terminal, once it is lent; false when it isn't. */+ choose?(id: string | null): Promise<boolean>;/** The add form's switch (this app's own page only): lend to the server about to be paired at `address` if it* turns out to be the person's own. */wish?(address: string, on: boolean): Promise<boolean>;