Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(lending): say Computer sharing is off instead of "update the server"
AdityaUmale9da6c699e3c0
diff --git a/electron/computer-sharing.d.mts b/electron/computer-sharing.d.mtsindex 05ad085a39..6c0ee4de65 100644--- a/electron/computer-sharing.d.mts+++ b/electron/computer-sharing.d.mts@@ -161,7 +161,7 @@ export function createComputerSharing(options: {/** `env` is a server of the person's own, checked now: its identity, else null. */ownServer(env: Workspace): Promise<Identity | null>;/** Why `env` is not a server of the person's own, or null when it is. */- ownRefusal(env: Workspace): Promise<"team" | "cloud" | "not-owner" | "shared" | "old" | "unreachable" | null>;+ ownRefusal(env: Workspace): Promise<"team" | "cloud" | "not-owner" | "shared" | "old" | "off" | "unreachable" | null>;/** A server of the person's own whose pairing here was never asked about: its identity, for the popup; null once asked;* false when it is not a server of the person's own. */ownOffer(env: Workspace): Promise<Identity | null | false>;diff --git a/electron/computer-sharing.mjs b/electron/computer-sharing.mjsindex 7a08c4adb3..4c15165ac8 100644--- a/electron/computer-sharing.mjs+++ b/electron/computer-sharing.mjs@@ -447,7 +447,7 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, loconst ownIdentity = async env => {const described = await describe(env, false);if (!ownServerSession(described.auth)) throw Object.assign(new Error(t("native.lend.notOwnServer")), { problem: "not-own", why: ownServerRefusal(described.auth) ?? "not-owner" });- if (!described.supported) throw Object.assign(new Error(UPDATE_SERVER), { why: "old" });+ if (!described.supported) throw described.auth.lendingOff === true ? Object.assign(new Error(t("native.lend.sharingOff")), { why: "off" }) : Object.assign(new Error(UPDATE_SERVER), { why: "old" });takes(env, { ...described, link: false, chrome: false });return described.info;};@@ -865,7 +865,7 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, lo},/** Whether `env` is a server of the person's own, checked now: its identity, or null (not paired as its admin, a team* or Cloud, too old to take a lent computer, or not answering). */- ownServer: env => ownIdentity(env).catch(() => null), /** Why `env` is not a server of the person's own: ownServerRefusal's word, "old", or "unreachable". */ ownRefusal: env => ownIdentity(env).then(() => null, error => error?.why ?? "unreachable"),+ ownServer: env => ownIdentity(env).catch(() => null), /** Why `env` is not a server of the person's own: ownServerRefusal's word, "old", "off" (its owner turned Computer sharing off there) or "unreachable". */ ownRefusal: env => ownIdentity(env).then(() => null, error => error?.why ?? "unreachable"),/** A server of the person's own whose pairing here was never asked about: its identity, for the popup; null once the* person answered for this pairing (a grant they allowed carries over to a new pairing of that same server); false* when it is not a server of their own. */diff --git a/electron/lend-own-server.node-test.mjs b/electron/lend-own-server.node-test.mjsindex 292be422f8..ebb24c1d8a 100644--- a/electron/lend-own-server.node-test.mjs+++ b/electron/lend-own-server.node-test.mjs@@ -34,13 +34,13 @@ async function scratch(t) {/** A self-hosted server as this desktop's sign-in there sees it: `scopes`, whether nobody else signs in there (`own`, which* the server says only to its one owner, with what it takes from them), and whether it is a team's or a Cloud. Its public* description offers no lending, as before pairing. */-function selfHosted({ scopes = ["admin", "client"], own = true, extra = {}, mcp = true, caller = false } = {}) {+function selfHosted({ scopes = ["admin", "client"], own = true, lends = true, extra = {}, mcp = true, caller = false } = {}) {const json = (value, status = 200) => ({ ok: status < 400, status, headers: { get: () => null }, body: (async function* () { yield Buffer.from(JSON.stringify(value)); })() });const state = { environmentId: randomUUID(), sessionId: randomUUID(), scopes, own, extra, connects: [], disconnects: [], polls: 0 };state.fetch = async (url, init) => {const route = new URL(url).pathname;const owner = state.own && state.scopes.includes("admin");- if (route === "/api/auth/session") return json({ kind: "session", id: state.sessionId, scopes: state.scopes, ...(owner ? { own: true, lending: { sharedComputers: true, lendingDetails: true, fileEdits: true, ...(mcp ? { lentMcp: true } : {}), ...(mcp && caller ? { mcpCaller: true } : {}) } } : {}), ...state.extra });+ if (route === "/api/auth/session") return json({ kind: "session", id: state.sessionId, scopes: state.scopes, ...(owner ? { own: true, ...(lends ? { lending: { sharedComputers: true, lendingDetails: true, fileEdits: true, ...(mcp ? { lentMcp: true } : {}), ...(mcp && caller ? { mcpCaller: true } : {}) } } : {}) } : {}), ...state.extra });if (route === "/.well-known/openmausbot/environment") return json({ environmentId: state.environmentId, capabilities: { remoteSessions: true } });const body = init?.body ? JSON.parse(init.body) : {};if (route === "/api/shared-computers/connect") { state.connects.push(body); return json({ ok: true }); }@@ -96,6 +96,11 @@ test("ownRefusal asks the server itself: its own when it is, why not when it isnassert.equal(await narrow.sharing.ownRefusal(garage), "not-owner");const team = await desktop(t, selfHosted({ extra: { team: { id: "t", role: "admin" } } }));assert.equal(await team.sharing.ownRefusal(garage), "team");+ const off = await desktop(t, selfHosted({ lends: false, extra: { lendingOff: true } }));+ assert.equal(await off.sharing.ownRefusal(garage), "off", "its owner turned Computer sharing off there");+ await assert.rejects(off.sharing.lendOwn(garage, { computer: true }), /turned off/);+ const old = await desktop(t, selfHosted({ lends: false }));+ assert.equal(await old.sharing.ownRefusal(garage), "old", "a server from before lending says neither");});test("once the person allows it, a server of their own gets the apps on the screen and its MCP servers, with the maintainer flag off; no folder or terminal unless chosen", async t => {@@ -371,7 +376,7 @@ test("Choose what it can use on a server's own page opens This computer's Settin});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"]) {+ for (const refusal of ["shared", "not-owner", "old", "off", "team", "cloud", "unreachable"]) {const { handlers } = mainLending({ own: false, refusal });assert.deepEqual(await handlers.get("lend:state")({}, "garage"), { name: "Garage", lendable: false, why: refusal });}diff --git a/server/index.ts b/server/index.tsindex e8b24b6a66..03b8a017bc 100644--- a/server/index.ts+++ b/server/index.ts@@ -12558,7 +12558,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {...(auth.session.email ? { email: auth.session.email } : {}),...(auth.session.owner ? { owner: auth.session.owner } : {}),...(HOSTED_WORKSPACE ? { hosted: true } : {}),- ...(CLOUD_HOME ? { cloudHome: true } : {}), ...teamSignInFor(CLOUD_HOME, auth.session), ...(ownHome.owner(auth) ? { own: true, ...(ownerLends() ? { lending: OWNER_LENDING } : {}) } : {}), ...(teamHost.sessionInfo(auth.session) ? { team: teamHost.sessionInfo(auth.session), openedThreads: threadStarters.threadsOf(actorKey(auth), 2_000).filter((threadId) => !conversationShares.get(threadId)) } : {}),+ ...(CLOUD_HOME ? { cloudHome: true } : {}), ...teamSignInFor(CLOUD_HOME, auth.session), ...(ownHome.owner(auth) ? { own: true, ...(ownerLends() ? { lending: OWNER_LENDING } : { lendingOff: true }) } : {}), ...(teamHost.sessionInfo(auth.session) ? { team: teamHost.sessionInfo(auth.session), openedThreads: threadStarters.threadsOf(actorKey(auth), 2_000).filter((threadId) => !conversationShares.get(threadId)) } : {}),...(CLOUD_PERSONAL && !cloudOwnerSession(auth) ? { cloudGuest: true, openedThreads: threadStarters.threadsOf(actorKey(auth), 2_000) } : {}),...(reactorFor(auth).by !== "user" ? { reactor: reactorFor(auth).by } : {}),} satisfies SignedInSessionResponse,diff --git a/server/shared-computers.gate.test.ts b/server/shared-computers.gate.test.tsindex fb6ae1cff9..1ef6ad241c 100644--- a/server/shared-computers.gate.test.ts+++ b/server/shared-computers.gate.test.ts@@ -233,3 +233,15 @@ it("with it off, the bot-facing route hides behind the same unknown-endpoint ansexpect(used.status).toBe(404);expect(used.body).toEqual({ error: "unknown internal endpoint" });});++it("with it off, the owner's pairing hears that its owner turned lending off, and the desktop says so instead of asking for an update", async () => {+ const owner = await paired(["admin", "client"]);+ const session = (await api("GET", "/api/auth/session", undefined, bearer(owner.token))).body;+ expect(session).toMatchObject({ own: true, lendingOff: true });+ expect(session).not.toHaveProperty("lending");+ const { env, sharing } = desktop(owner.token);+ try {+ expect(await sharing.ownRefusal(env)).toBe("off");+ await expect(sharing.lendOwn(env, { computer: true })).rejects.toThrow(/turned off/);+ } finally { sharing.close(); }+});diff --git a/src/components/LendComputerSwitch.dom.test.ts b/src/components/LendComputerSwitch.dom.test.tsindex b6b7015d85..1159348ba1 100644--- a/src/components/LendComputerSwitch.dom.test.ts+++ b/src/components/LendComputerSwitch.dom.test.ts@@ -94,6 +94,7 @@ it("Screen panel on a server it can't be lent to: the reason in one line, no swiexpect(lendLine({ name: "My Cloud", lendable: false, why: "cloud" })).toBe("My Cloud uses this computer by its own Cloud rules, not this switch. Pause it from the MausBot icon’s menu.");expect(lendLine({ name: "box", lendable: false, why: "not-owner" })).toBe("Bots on box can’t use this computer: this app isn’t paired with it as its owner.");expect(lendLine({ name: "box", lendable: false, why: "old" })).toBe("Update box to let its bots use this computer.");+ expect(lendLine({ name: "box", lendable: false, why: "off" })).toBe("Computer sharing is turned off on box, so its bots can’t use this computer. Ask a bot there to turn Computer sharing back on.");expect(lendLine({ name: "box", lendable: false, why: "unreachable" })).toBe("Can’t reach box to check whether its bots can use this computer.");});diff --git a/src/lib/use-lend-computer.ts b/src/lib/use-lend-computer.tsindex a8572968f3..1fca017ecc 100644--- a/src/lib/use-lend-computer.ts+++ b/src/lib/use-lend-computer.ts@@ -20,6 +20,7 @@ export function lendLine(view: LendView, app = productName()): string {case "shared": return t("lend.why.shared", { name });case "not-owner": return t("lend.why.notOwner", { name });case "old": return t("lend.why.old", { name });+ case "off": return t("lend.why.off", { name });case "settings": return t("lend.why.settings", { name });default: return t("lend.why.unreachable", { name });}diff --git a/src/locales/de.json b/src/locales/de.jsonindex 8096d929eb..8a2c2c44d8 100644--- a/src/locales/de.json+++ b/src/locales/de.json@@ -4567,5 +4567,7 @@"githubSignIn.tokenPlaceholder": "github_pat_…","approval.status.teammateSkills": "Team-Skills geändert","approval.applied.skill.teammates": "{name} hat Skills im Team geändert: {title}",- "skills.request.reviewTeammates": "Prüfe jede Änderung, bevor du sie anwendest"+ "skills.request.reviewTeammates": "Prüfe jede Änderung, bevor du sie anwendest",+ "lend.why.off": "Computerfreigabe ist auf {name} ausgeschaltet, daher können seine Bots diesen Computer nicht nutzen. Bitte einen Bot dort, die Computerfreigabe wieder einzuschalten.",+ "native.lend.sharingOff": "Computerfreigabe ist dort ausgeschaltet, daher können seine Bots diesen Computer nicht nutzen. Bitte einen Bot dort, die Computerfreigabe wieder einzuschalten."}diff --git a/src/locales/en.json b/src/locales/en.jsonindex 0eceb2f2dc..8c64fb28ca 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -9331,6 +9331,7 @@"lend.why.shared": "Bots on {name} can’t use this computer: other people sign in to it too.","lend.why.notOwner": "Bots on {name} can’t use this computer: this app isn’t paired with it as its owner.","lend.why.old": "Update {name} to let its bots use this computer.",+ "lend.why.off": "Computer sharing is turned off on {name}, so its bots can’t use this computer. Ask a bot there to turn Computer sharing back on.","lend.why.unreachable": "Can’t reach {name} to check whether its bots can use this computer.","lend.why.settings": "Choose what {name}’s bots can use on this computer under Your computers in Settings → This app.","lend.browser": "Or, in the {app} app on a computer, connect to this server and turn on “Let its bots use this computer”.",@@ -10102,6 +10103,7 @@"native.lend.own.detail": "Its bots can then see and use the apps on your screen while this app is open. In Settings → This app → Your computers you can also let them use folders you choose and run commands in a terminal. Turn it off there any time, or pause it from the OpenMausBot icon's menu.","native.lend.own.allow": "Allow","native.lend.notOwnServer": "Only your own server can use this computer. Pair this app with it again as its owner.",+ "native.lend.sharingOff": "Computer sharing is turned off there, so its bots can’t use this computer. Ask a bot there to turn Computer sharing back on.","native.dialog.updateServers.title": "Could not update servers","native.dialog.updateServers.saveFailed": "Could not save server connections on this computer. Please try again.","native.dialog.switchEnv.title": "Could not switch environments",diff --git a/src/locales/it.json b/src/locales/it.jsonindex 0d290b0ae9..20902a0d50 100644--- a/src/locales/it.json+++ b/src/locales/it.json@@ -10073,6 +10073,7 @@"native.lend.own.detail": "I suoi bot possono quindi vedere e usare le app sullo schermo mentre questa app è aperta. In Impostazioni → Questa app → I tuoi computer puoi anche consentire loro di usare cartelle a tua scelta ed eseguire comandi in un terminale. Disattivalo lì in qualsiasi momento o mettilo in pausa dal menu dell'icona di OpenMausBot.","native.lend.own.allow": "Consentire","native.lend.notOwnServer": "Solo il tuo server può usare questo computer. Abbina questa applicazione con esso di nuovo come il suo proprietario.",+ "native.lend.sharingOff": "La condivisione del computer è disattivata lì, quindi i suoi bot non possono usare questo computer. Chiedi a un bot lì di riattivare la condivisione del computer.","native.dialog.updateServers.title": "Non è possibile aggiornare i server","native.dialog.updateServers.saveFailed": "Non è possibile salvare le connessioni server su questo computer. Per favore riprovate.","native.dialog.switchEnv.title": "Non poteva cambiare gli ambienti",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex ccc22fb8ca..14fa24d20b 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -9279,6 +9279,7 @@"lend.why.shared": "Os bots de {name} não podem usar este computador: outras pessoas também entram nele.","lend.why.notOwner": "Os bots de {name} não podem usar este computador: este app não está pareado com ele como dono.","lend.why.old": "Atualize {name} para deixar os bots dele usarem este computador.",+ "lend.why.off": "O compartilhamento do computador está desativado em {name}, então os bots dele não podem usar este computador. Peça a um bot de lá para reativar o compartilhamento do computador.","lend.why.unreachable": "Não foi possível falar com {name} para saber se os bots dele podem usar este computador.","lend.why.settings": "Escolha o que os bots de {name} podem usar neste computador em Seus computadores, em Configurações → Este app.","lend.browser": "Ou, no app {app} em um computador, conecte-se a este servidor e ative “Deixar os bots dele usarem este computador”.",@@ -10027,6 +10028,7 @@"native.lend.own.detail": "Os bots dele poderão ver e usar os apps da sua tela enquanto este app estiver aberto. Em Configurações → Este app → Seus computadores você também pode deixá-los usar as pastas que escolher e executar comandos em um terminal. Desligue isso lá quando quiser ou pause no menu do ícone do OpenMausBot.","native.lend.own.allow": "Permitir","native.lend.notOwnServer": "Só o seu próprio servidor pode usar este computador. Pareie este app com ele de novo como dono.",+ "native.lend.sharingOff": "O compartilhamento do computador está desativado lá, então os bots não podem usar este computador. Peça a um bot de lá para reativar o compartilhamento do computador.","native.dialog.updateServers.title": "Não foi possível atualizar os servidores","native.dialog.updateServers.saveFailed": "Não foi possível salvar as conexões com servidores neste computador. Tente novamente.","native.dialog.switchEnv.title": "Não foi possível trocar de ambiente",diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.jsonindex 5dfa1e0448..96b12938be 100644--- a/src/locales/zh-tw.json+++ b/src/locales/zh-tw.json@@ -8926,6 +8926,7 @@"native.lend.own.detail": "在這個 App 開著時,它的機器人就能看到並使用你螢幕上的 App。你也可以在「設定 → 這個應用程式 → 你的電腦」中讓它們使用你選的資料夾,並在終端機執行指令。你隨時可以在那裡關閉,或從 OpenMausBot 圖示的選單中暫停。","native.lend.own.allow": "允許","native.lend.notOwnServer": "只有你自己的伺服器能使用這台電腦。請以擁有者身分再次將這個 App 與它配對。",+ "native.lend.sharingOff": "那裡的電腦共享已關閉,所以它的機器人不能使用這台電腦。請讓那裡的機器人重新開啟電腦共享。","native.dialog.updateServers.title": "無法更新伺服器","native.dialog.updateServers.saveFailed": "無法在這台電腦上儲存伺服器連線。請再試一次。","native.dialog.switchEnv.title": "無法切換環境",diff --git a/src/locales/zh.json b/src/locales/zh.jsonindex d7f8f2e1bc..713631a226 100644--- a/src/locales/zh.json+++ b/src/locales/zh.json@@ -9238,6 +9238,7 @@"lend.why.shared": "{name} 的机器人无法使用这台电脑:其他人也会登录它。","lend.why.notOwner": "{name} 的机器人无法使用这台电脑:这个应用没有以所有者身份与它配对。","lend.why.old": "请更新 {name},让它的机器人可以使用这台电脑。",+ "lend.why.off": "{name} 上的电脑共享已关闭,所以它的机器人不能使用这台电脑。请让那里的机器人重新打开电脑共享。","lend.why.unreachable": "无法联系 {name} 来确认它的机器人能否使用这台电脑。","lend.why.settings": "在「设置 → 本应用」的「你的电脑」下,选择 {name} 的机器人可以使用这台电脑上的什么。","lend.browser": "或者在电脑上的 {app} 应用中连接到这台服务器,并开启「让它的机器人使用这台电脑」。",@@ -9999,6 +10000,7 @@"native.lend.own.detail": "开启后,只要本应用打开,它的机器人就能看到并使用你屏幕上的应用。在「设置 → 本应用 → 你的电脑」中,你还可以让它们使用你选择的文件夹并在终端中运行命令。随时可以在那里关闭,或从 OpenMausBot 图标的菜单暂停。","native.lend.own.allow": "允许","native.lend.notOwnServer": "只有你自己的服务器可以使用这台电脑。请以所有者身份重新配对这个应用。",+ "native.lend.sharingOff": "那里的电脑共享已关闭,所以它的机器人不能使用这台电脑。请让那里的机器人重新打开电脑共享。","native.dialog.updateServers.title": "无法更新 Server","native.dialog.updateServers.saveFailed": "无法保存这台电脑上的 Server 连接。请重试。","native.dialog.switchEnv.title": "无法切换环境",diff --git a/src/types/ogb.d.ts b/src/types/ogb.d.tsindex 50c9a5721c..c2e79cf979 100644--- a/src/types/ogb.d.ts+++ b/src/types/ogb.d.ts@@ -29,7 +29,7 @@ const __APP_VERSION__: string;* from being lent there. `screen`: why its apps and screen don't work yet while it is on (screen-status.mjs). */type DesktopLendView =| { name: string; lendable: true; on: boolean; connected: boolean; paused: boolean; screen?: "starting" | "permissions" | "blocked" | "off" | "not-running" | "unsupported" }- | { name: string; lendable: false; why: "team" | "cloud" | "not-owner" | "shared" | "old" | "unreachable" | "settings" };+ | { name: string; lendable: false; why: "team" | "cloud" | "not-owner" | "shared" | "old" | "off" | "unreachable" | "settings" };type DesktopCapabilities = {host: {