Skip to content

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

feat(desktop): "Reset saved keys" when the saved-keys store can't be read (#4894)

Bugfixer 24744c44d126c
diff --git a/electron/main.mjs b/electron/main.mjs
index 3430f8c505..66a509c35f 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -77,7 +77,7 @@ import {
withoutDesktopCompanionAccess,
} from "./desktop-companion-client.mjs";
import { isKnownSkin, skinChrome } from "./skin-overlay.cjs";
-import { readSecureCredentials } from "./secure-credentials.mjs";
+import { readSecureCredentials, resetUnreadableCredentials } from "./secure-credentials.mjs";
import { createControlPlaneClient } from "./control-plane-client.mjs";
import {
companionAccountCleanupPending,
@@ -2777,6 +2777,34 @@ async function saveWorkspaceCredential(name, value) {
);
}
+// This app's own page only: whether saved keys could not be read this launch, and the person's way out of that.
+ipcMain.handle("credential-store:unreadable", localOnly("credential-store:unreadable", () => credentialStoreUnavailable));
+ipcMain.handle("credential-store:reset", localOnly("credential-store:reset", (event) => resetUnreadableCredentials({
+ unreadable: credentialStoreUnavailable,
+ confirm: async () => {
+ const options = {
+ type: "warning",
+ buttons: [nativeT("native.dialog.resetSavedKeys.button"), nativeT("native.common.cancel")],
+ defaultId: 1,
+ cancelId: 1,
+ message: nativeT("native.dialog.resetSavedKeys.title"),
+ detail: nativeT("native.dialog.resetSavedKeys.detail", { app: app.name }),
+ };
+ const parent = BrowserWindow.fromWebContents(event.sender);
+ const { response } = parent ? await dialog.showMessageBox(parent, options) : await dialog.showMessageBox(options);
+ return response === 0;
+ },
+ exists: () => fs.existsSync(CREDENTIALS_FILE),
+ moveAside: () => fs.renameSync(CREDENTIALS_FILE, `${CREDENTIALS_FILE}.unreadable-${Date.now()}`),
+ failed: async (error) => {
+ slog(`saved keys reset failed: ${error?.message ?? error}`);
+ await dialog.showMessageBox({ type: "error", message: nativeT("native.dialog.resetSavedKeys.failed"), detail: error?.message ?? String(error) });
+ },
+ restart: () => {
+ slog("saved keys reset by the person: unreadable credential store moved aside, restarting");
+ relaunchAfterDesktopRemoteChange();
+ },
+})));
ipcMain.handle("credential:set", localOnly("credential:set", (_event, name, value) =>
saveWorkspaceCredential(name, value),
));
diff --git a/electron/preload.cjs b/electron/preload.cjs
index da01c30ac1..16151581df 100644
--- a/electron/preload.cjs
+++ b/electron/preload.cjs
@@ -418,6 +418,11 @@ const bridge = {
? ipcRenderer.invoke("open-at-login:set", on === true) : Promise.reject(new Error("Turn on the switch to open OpenMausBot at login.")),
},
setCredential: (name, value) => ipcRenderer.invoke("credential:set", name, value),
+ // Saved keys this launch could not read, and "Reset saved keys" (main asks the person first, then restarts).
+ credentialStore: {
+ unreadable: () => ipcRenderer.invoke("credential-store:unreadable"),
+ reset: () => ipcRenderer.invoke("credential-store:reset"),
+ },
updater: {
check: () => ipcRenderer.invoke("update:check"),
diff --git a/electron/secure-credentials.mjs b/electron/secure-credentials.mjs
index 9fba6757be..faa4549ac2 100644
--- a/electron/secure-credentials.mjs
+++ b/electron/secure-credentials.mjs
@@ -39,3 +39,18 @@ export async function readSecureCredentials({
}
return { status: "unavailable", credentials: {}, error: lastError };
}
+
+/** "Reset saved keys" for a store that cannot be read: after the person confirms, the file is moved aside (kept, not
+ * deleted) and the app restarts with an empty store it can write again. A store that was read is never touched. */
+export async function resetUnreadableCredentials({ unreadable, confirm, exists, moveAside, failed, restart }) {
+ if (!unreadable) return "readable";
+ if (!(await confirm())) return "cancelled";
+ try {
+ if (exists()) moveAside();
+ } catch (error) {
+ await failed(error);
+ return "failed";
+ }
+ restart();
+ return "reset";
+}
diff --git a/electron/secure-credentials.test.mjs b/electron/secure-credentials.test.mjs
index b85fd187eb..9663b86d9b 100644
--- a/electron/secure-credentials.test.mjs
+++ b/electron/secure-credentials.test.mjs
@@ -1,6 +1,6 @@
import { describe, expect, it, vi } from "vitest";
-import { readSecureCredentials } from "./secure-credentials.mjs";
+import { readSecureCredentials, resetUnreadableCredentials } from "./secure-credentials.mjs";
const transient = () =>
new Error("safeStorage.decryptStringAsync is temporarily unavailable. Please try again.");
@@ -66,3 +66,52 @@ describe("readSecureCredentials", () => {
expect(decrypt).toHaveBeenCalledTimes(1);
});
});
+
+describe("resetUnreadableCredentials", () => {
+ const resetDeps = (over = {}) => ({
+ unreadable: true,
+ confirm: vi.fn(async () => true),
+ exists: () => true,
+ moveAside: vi.fn(),
+ failed: vi.fn(async () => {}),
+ restart: vi.fn(),
+ ...over,
+ });
+
+ it("moves the unreadable file aside and restarts once the person confirms", async () => {
+ const d = resetDeps();
+ await expect(resetUnreadableCredentials(d)).resolves.toBe("reset");
+ expect(d.moveAside).toHaveBeenCalledTimes(1);
+ expect(d.restart).toHaveBeenCalledTimes(1);
+ });
+
+ it("never touches a store that was read, and does not even ask", async () => {
+ const d = resetDeps({ unreadable: false });
+ await expect(resetUnreadableCredentials(d)).resolves.toBe("readable");
+ expect(d.confirm).not.toHaveBeenCalled();
+ expect(d.moveAside).not.toHaveBeenCalled();
+ expect(d.restart).not.toHaveBeenCalled();
+ });
+
+ it("changes nothing when the person cancels", async () => {
+ const d = resetDeps({ confirm: vi.fn(async () => false) });
+ await expect(resetUnreadableCredentials(d)).resolves.toBe("cancelled");
+ expect(d.moveAside).not.toHaveBeenCalled();
+ expect(d.restart).not.toHaveBeenCalled();
+ });
+
+ it("tells the person and does not restart when the file cannot be moved aside", async () => {
+ const busy = new Error("EBUSY: resource busy or locked");
+ const d = resetDeps({ moveAside: vi.fn(() => { throw busy; }) });
+ await expect(resetUnreadableCredentials(d)).resolves.toBe("failed");
+ expect(d.failed).toHaveBeenCalledWith(busy);
+ expect(d.restart).not.toHaveBeenCalled();
+ });
+
+ it("still restarts when the file is already gone", async () => {
+ const d = resetDeps({ exists: () => false });
+ await expect(resetUnreadableCredentials(d)).resolves.toBe("reset");
+ expect(d.moveAside).not.toHaveBeenCalled();
+ expect(d.restart).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/src/components/PluginsPanel.tsx b/src/components/PluginsPanel.tsx
index ea8cb9c6e1..fcc9bfa3fb 100644
--- a/src/components/PluginsPanel.tsx
+++ b/src/components/PluginsPanel.tsx
@@ -38,6 +38,7 @@ import { mergeCompleteConnectorStatus, mergeCurrentConnectorStatus, onlyLatestCo
import { openBotSettings } from "./bot-panel/panel-link";
import { openKeySettings } from "./keys/key-focus";
import { lacksAdminScope } from "@/lib/admin-scope";
+import { SavedKeysReset } from "./SavedKeysReset";
import { ServiceIcon, type ToolkitCard } from "./ServiceIcon"; import { AppsSection } from "./AppsSection";
export { ServiceIcon, type ToolkitCard } from "./ServiceIcon";
@@ -588,6 +589,7 @@ export function PluginsPanel() {
<TriangleAlert size={14} className="mt-px shrink-0" />
<span>
{t("connectors.stale")}
+ <SavedKeysReset />
</span>
</div>
)}
diff --git a/src/components/SavedKeysReset.tsx b/src/components/SavedKeysReset.tsx
new file mode 100644
index 0000000000..37a081245f
--- /dev/null
+++ b/src/components/SavedKeysReset.tsx
@@ -0,0 +1,25 @@
+import { useEffect, useState } from "react";
+
+import { t } from "@/lib/i18n";
+import { savedKeysUnreadable } from "@/lib/saved-keys-reset";
+
+/** "Reset saved keys", shown only when this app's desktop could not read its saved keys this launch. The desktop asks
+ * the person before it moves the unreadable file aside and restarts. */
+export function SavedKeysReset() {
+ const [unreadable, setUnreadable] = useState(false);
+ useEffect(() => {
+ let live = true;
+ void savedKeysUnreadable().then((answer) => { if (live) setUnreadable(answer); });
+ return () => { live = false; };
+ }, []);
+ if (!unreadable) return null;
+ return (
+ <button
+ type="button"
+ onClick={() => void window.ogb?.credentialStore?.reset()}
+ className="ms-2 font-medium underline underline-offset-2 hover:opacity-80"
+ >
+ {t("connectors.resetSavedKeys")}
+ </button>
+ );
+}
diff --git a/src/lib/saved-keys-reset.test.ts b/src/lib/saved-keys-reset.test.ts
new file mode 100644
index 0000000000..dfa0064eae
--- /dev/null
+++ b/src/lib/saved-keys-reset.test.ts
@@ -0,0 +1,19 @@
+import { describe, expect, it } from "vitest";
+
+import { savedKeysUnreadable } from "./saved-keys-reset";
+
+const bridge = (unreadable: () => Promise<boolean>, remoteActive = false) =>
+ ({ credentialStore: { unreadable, reset: async () => "cancelled" as const }, remoteClient: { active: remoteActive } }) as unknown as Window["ogb"];
+
+describe("savedKeysUnreadable", () => {
+ it("is true only when this app's desktop says its saved keys could not be read", async () => {
+ await expect(savedKeysUnreadable(bridge(async () => true))).resolves.toBe(true);
+ await expect(savedKeysUnreadable(bridge(async () => false))).resolves.toBe(false);
+ });
+
+ it("is false in a browser, on a client of another computer, and when the desktop cannot answer", async () => {
+ await expect(savedKeysUnreadable({} as Window["ogb"])).resolves.toBe(false);
+ await expect(savedKeysUnreadable(bridge(async () => true, true))).resolves.toBe(false);
+ await expect(savedKeysUnreadable(bridge(async () => { throw new Error("no handler"); }))).resolves.toBe(false);
+ });
+});
diff --git a/src/lib/saved-keys-reset.ts b/src/lib/saved-keys-reset.ts
new file mode 100644
index 0000000000..3dbd8bf65a
--- /dev/null
+++ b/src/lib/saved-keys-reset.ts
@@ -0,0 +1,10 @@
+/** Whether this app's desktop shell could not read its saved keys this launch. False on a page without that shell, on a
+ * desktop that is a client of another computer (the notice there is about that computer's keys), or on any error. */
+export async function savedKeysUnreadable(bridge: Window["ogb"] = window.ogb): Promise<boolean> {
+ if (!bridge?.credentialStore || bridge.remoteClient?.active === true) return false;
+ try {
+ return (await bridge.credentialStore.unreadable()) === true;
+ } catch {
+ return false;
+ }
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index ad8c14b8a3..09038a4db2 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -5614,6 +5614,7 @@
"connectors.tab.apps": "Connected apps",
"connectors.tab.mcp": "MCP servers",
"connectors.stale": "Showing what was connected last time. The credential store couldn't be opened just now, so these couldn't be re-checked. Your apps are still connected. Restarting {app} usually clears this.",
+ "connectors.resetSavedKeys": "Reset saved keys",
"connectors.viewAria": "Connected apps view",
"connectors.tab.marketplace": "Marketplace",
"connectors.tab.connected": "Connected",
@@ -9114,6 +9115,10 @@
"native.dialog.connect.title": "Connect to {host}?",
"native.dialog.connect.withCode": "The pairing code in the link is used once, then this app stays signed in to that server.",
"native.dialog.connect.noCode": "The link has no pairing code; the server will ask for one.",
+ "native.dialog.resetSavedKeys.title": "Reset saved keys?",
+ "native.dialog.resetSavedKeys.detail": "{app} can't read its saved keys here, so it can't use them or save new ones. Resetting puts the unreadable file aside and restarts {app}. Then enter your keys again and reconnect your apps.",
+ "native.dialog.resetSavedKeys.button": "Reset and restart",
+ "native.dialog.resetSavedKeys.failed": "Couldn't reset saved keys",
"native.connect.empty": "Enter the server's address or paste its link.",
"native.connect.codeOnly": "That's a pairing code. Also enter the server's address, like {example}.",
"native.connect.emailCode": "That's a sign-in code from an email. Pairing needs a 12-character code like 7KQ2-M9XD-H4TP.",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index e668f43975..b7f55605ed 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -5347,6 +5347,7 @@
"connectors.tab.apps": "Apps conectados",
"connectors.tab.mcp": "Servidores MCP",
"connectors.stale": "Mostrando as conexões da última vez. Não foi possível abrir o armazenamento de credenciais agora para verificá-las novamente. Seus apps continuam conectados. Reiniciar o app {app} costuma resolver.",
+ "connectors.resetSavedKeys": "Redefinir chaves salvas",
"connectors.viewAria": "Visualização dos apps conectados",
"connectors.tab.marketplace": "Marketplace",
"connectors.tab.connected": "Conectados",
@@ -9086,6 +9087,10 @@
"native.dialog.connect.title": "Conectar a {host}?",
"native.dialog.connect.withCode": "O app usa o código de pareamento do link uma vez e depois continua conectado a esse servidor.",
"native.dialog.connect.noCode": "O link não tem código de pareamento; o servidor vai pedir um.",
+ "native.dialog.resetSavedKeys.title": "Redefinir as chaves salvas?",
+ "native.dialog.resetSavedKeys.detail": "O {app} não consegue ler as chaves salvas aqui, então não pode usá-las nem salvar novas. Redefinir deixa de lado o arquivo ilegível e reinicia o {app}. Depois, digite suas chaves de novo e reconecte seus apps.",
+ "native.dialog.resetSavedKeys.button": "Redefinir e reiniciar",
+ "native.dialog.resetSavedKeys.failed": "Não foi possível redefinir as chaves salvas",
"native.connect.empty": "Digite o endereço do servidor ou cole o link dele.",
"native.connect.codeOnly": "Isso é um código de pareamento. Digite também o endereço do servidor, por exemplo {example}.",
"native.connect.emailCode": "Isso é um código de login de um e-mail. O pareamento precisa de um código de 12 caracteres como 7KQ2-M9XD-H4TP.",
diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.json
index 019cb00b63..c93248702d 100644
--- a/src/locales/source-hashes.json
+++ b/src/locales/source-hashes.json
@@ -33567,7 +33567,12 @@
"mascot.body.jalebi": "2e200e92c49eb6d51ca76db4516d1fe7a39430862e5b8ebb5fa30071dc5ccc63",
"mascot.body.katli": "28670af54fcc50cd51c5983623672ed0d63c3355b5be96ef666812b0da6b6bf5",
"mascot.body.karanji": "dc2ff0fdc7d7ce51f05cd1dd8d6f0f8ff444c82da36304373561c9cf246c32a4",
- "skins.tagline.diwali": "92af77174824ccd4267be3745deb99c28cd2ddd21e761e2afcd438bded98405c"
+ "skins.tagline.diwali": "92af77174824ccd4267be3745deb99c28cd2ddd21e761e2afcd438bded98405c",
+ "native.dialog.resetSavedKeys.title": "09a032a1b21411b300becf306038111d2975ab78b24c441565a726eff5d684b4",
+ "native.dialog.resetSavedKeys.detail": "9f72b7452bdcd91042c9679f05a5b6f2f6e3e7fdc7980c42a488fa3b01d6b3b0",
+ "native.dialog.resetSavedKeys.button": "32910a15265787f53a3554f97da5787c04a7ada90822edcc7776a471b8ee3d8a",
+ "native.dialog.resetSavedKeys.failed": "e663cbf1d28235aee568f1cd2b3c837697c355d0de071f557053f0c61bba2a54",
+ "connectors.resetSavedKeys": "764411710357197d3d55fbf646d0ea6249c4236cbc635e0b4212b8d92cf5dea6"
},
"zh": {
"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",
diff --git a/src/types/ogb.d.ts b/src/types/ogb.d.ts
index 2a64afa7f5..61ca2a4060 100644
--- a/src/types/ogb.d.ts
+++ b/src/types/ogb.d.ts
@@ -445,6 +445,10 @@ const __APP_VERSION__: string;
openLogsFolder?(): Promise<{ folder: string; opened: boolean; error?: string }>;
/** This app's own login item, which opens the window. `available`: false in a build that cannot add one. */
openAtLogin?: { state(): Promise<{ available: boolean; on: boolean }>; set(on: boolean): Promise<{ available: boolean; on: boolean }> };
+ /** Saved keys this launch could not read (this app's own page only). `reset` asks the person, moves the unreadable
+ * file aside and restarts; it resolves "cancelled" when they say no,
+ * "failed" (after telling them) when the file could not be moved, and "readable" (doing nothing) when the keys could be read. */
+ credentialStore?: { unreadable(): Promise<boolean>; reset(): Promise<"reset" | "cancelled" | "failed" | "readable"> };
/** Save a provider credential through Electron's OS-backed store. */
setCredential?(
name: "composioApiKey" | "xaiApiKey" | "boxToken" | "opencodeGoApiKey" | "ttsKey" | "fishAudioKey" | "geminiTtsKey" | "jevApiKey" | "openrouterDeciderKey" | "workersAiToken" | "openaiImageApiKey" | "customImageApiKey" | "openaiLiveKey" | "tregApiKey" | "postizApiKey" | "geminiImageApiKey",