Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(desktop): Reset saved keys: wait for the answer, show without the stale notice, don't move the file while quitting
Bugfixer 244a855275cfa
diff --git a/electron/main.mjs b/electron/main.mjsindex 66a509c35f..e724d0aaee 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -2794,6 +2794,7 @@ ipcMain.handle("credential-store:reset", localOnly("credential-store:reset", (evconst { response } = parent ? await dialog.showMessageBox(parent, options) : await dialog.showMessageBox(options);return response === 0;},+ quitting: () => desktopShutdownStarted,exists: () => fs.existsSync(CREDENTIALS_FILE),moveAside: () => fs.renameSync(CREDENTIALS_FILE, `${CREDENTIALS_FILE}.unreadable-${Date.now()}`),failed: async (error) => {diff --git a/electron/secure-credentials.mjs b/electron/secure-credentials.mjsindex faa4549ac2..0f346acd43 100644--- a/electron/secure-credentials.mjs+++ b/electron/secure-credentials.mjs@@ -41,10 +41,12 @@ export async function readSecureCredentials({}/** "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 }) {+ * deleted) and the app restarts with an empty store it can write again. A store that was read is never touched, and+ * nothing moves once the app has begun to quit while the person was deciding, since no restart would follow. */+export async function resetUnreadableCredentials({ unreadable, confirm, quitting, exists, moveAside, failed, restart }) {if (!unreadable) return "readable";if (!(await confirm())) return "cancelled";+ if (quitting()) return "quitting";try {if (exists()) moveAside();} catch (error) {diff --git a/electron/secure-credentials.test.mjs b/electron/secure-credentials.test.mjsindex 9663b86d9b..ec4490c250 100644--- a/electron/secure-credentials.test.mjs+++ b/electron/secure-credentials.test.mjs@@ -71,6 +71,7 @@ describe("resetUnreadableCredentials", () => {const resetDeps = (over = {}) => ({unreadable: true,confirm: vi.fn(async () => true),+ quitting: () => false,exists: () => true,moveAside: vi.fn(),failed: vi.fn(async () => {}),@@ -93,6 +94,13 @@ describe("resetUnreadableCredentials", () => {expect(d.restart).not.toHaveBeenCalled();});+ it("moves nothing when the app began to quit while the person was deciding", async () => {+ const d = resetDeps({ quitting: () => true });+ await expect(resetUnreadableCredentials(d)).resolves.toBe("quitting");+ 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");diff --git a/src/components/PluginsPanel.tsx b/src/components/PluginsPanel.tsxindex fcc9bfa3fb..024750e271 100644--- a/src/components/PluginsPanel.tsx+++ b/src/components/PluginsPanel.tsx@@ -584,7 +584,7 @@ export function PluginsPanel() {</header><div className="min-h-0 flex-1 overflow-y-auto px-5 pb-7 sm:px-7">- {stale && (+ {stale ? (<div className="mb-3 flex items-start gap-2 rounded-xl bg-warning/10 px-3 py-2 text-[13px] text-warning"><TriangleAlert size={14} className="mt-px shrink-0" /><span>@@ -592,6 +592,8 @@ export function PluginsPanel() {<SavedKeysReset /></span></div>+ ) : (+ <SavedKeysReset notice />)}{setupNotice && filter !== "mcp" && (<divdiff --git a/src/components/SavedKeysReset.test.ts b/src/components/SavedKeysReset.test.tsnew file mode 100644index 0000000000..bbaff17f9a--- /dev/null+++ b/src/components/SavedKeysReset.test.ts@@ -0,0 +1,50 @@+// @vitest-environment happy-dom+import { act, createElement } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++import { SavedKeysReset } from "./SavedKeysReset";++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++let host: HTMLDivElement;+let root: Root;+let answer: () => void;+const reset = vi.fn(() => new Promise<void>((resolve) => { answer = resolve; }));++beforeEach(() => {+ reset.mockClear();+ (window as unknown as { ogb: unknown }).ogb = { credentialStore: { unreadable: async () => true, reset } };+ host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+});+afterEach(() => {+ act(() => root.unmount());+ host.remove();+ delete (window as unknown as { ogb?: unknown }).ogb;+});++const show = async (notice?: boolean) => {+ await act(async () => { root.render(createElement(SavedKeysReset, notice ? { notice } : {})); });+ return host.querySelector("button") as HTMLButtonElement;+};++describe("Reset saved keys", () => {+ it("asks the desktop once, however often it is clicked while the question is open", async () => {+ const button = await show();+ await act(async () => { button.click(); button.click(); });+ expect(reset).toHaveBeenCalledTimes(1);+ expect(button.disabled).toBe(true);+ await act(async () => { answer(); });+ expect(button.disabled).toBe(false);+ await act(async () => { button.click(); });+ expect(reset).toHaveBeenCalledTimes(2);+ });++ it("comes with its own warning line when there is no other notice to sit in", async () => {+ const button = await show(true);+ expect(button).not.toBeNull();+ expect(host.querySelector(".bg-warning\\/10")?.textContent).toContain("couldn't be read");+ });+});diff --git a/src/components/SavedKeysReset.tsx b/src/components/SavedKeysReset.tsxindex 37a081245f..c434a89d5b 100644--- a/src/components/SavedKeysReset.tsx+++ b/src/components/SavedKeysReset.tsx@@ -1,25 +1,52 @@-import { useEffect, useState } from "react";+import { TriangleAlert } from "lucide-react";+import { useEffect, useRef, 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() {+ * the person before it moves the unreadable file aside and restarts; the button waits for that answer, so a second+ * click cannot open a second question. With `notice`, it comes in its own warning line, for a page with no other+ * warning to sit in. */+export function SavedKeysReset({ notice = false }: { notice?: boolean }) {const [unreadable, setUnreadable] = useState(false);+ const [pending, setPending] = useState(false);+ const asking = useRef(false);useEffect(() => {let live = true;void savedKeysUnreadable().then((answer) => { if (live) setUnreadable(answer); });return () => { live = false; };}, []);if (!unreadable) return null;- return (+ const reset = () => {+ if (asking.current) return;+ asking.current = true;+ setPending(true);+ void Promise.resolve(window.ogb?.credentialStore?.reset())+ .catch(() => {})+ .finally(() => {+ asking.current = false;+ setPending(false);+ });+ };+ const button = (<buttontype="button"- onClick={() => void window.ogb?.credentialStore?.reset()}- className="ms-2 font-medium underline underline-offset-2 hover:opacity-80"+ onClick={reset}+ disabled={pending}+ className="ms-2 font-medium underline underline-offset-2 hover:opacity-80 disabled:opacity-60">{t("connectors.resetSavedKeys")}</button>);+ if (!notice) return button;+ return (+ <div className="mb-3 flex items-start gap-2 rounded-xl bg-warning/10 px-3 py-2 text-[13px] text-warning">+ <TriangleAlert size={14} className="mt-px shrink-0" />+ <span>+ {t("connectors.savedKeysUnreadable")}+ {button}+ </span>+ </div>+ );}diff --git a/src/locales/en.json b/src/locales/en.jsonindex 09038a4db2..526edc9f3a 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -5615,6 +5615,7 @@"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.savedKeysUnreadable": "The keys saved on this computer couldn't be read.","connectors.viewAria": "Connected apps view","connectors.tab.marketplace": "Marketplace","connectors.tab.connected": "Connected",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex b7f55605ed..3da92c2e01 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -5348,6 +5348,7 @@"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.savedKeysUnreadable": "Não foi possível ler as chaves salvas neste computador.","connectors.viewAria": "Visualização dos apps conectados","connectors.tab.marketplace": "Marketplace","connectors.tab.connected": "Conectados",diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.jsonindex c93248702d..0fe59e8ac4 100644--- a/src/locales/source-hashes.json+++ b/src/locales/source-hashes.json@@ -33572,7 +33572,8 @@"native.dialog.resetSavedKeys.detail": "9f72b7452bdcd91042c9679f05a5b6f2f6e3e7fdc7980c42a488fa3b01d6b3b0","native.dialog.resetSavedKeys.button": "32910a15265787f53a3554f97da5787c04a7ada90822edcc7776a471b8ee3d8a","native.dialog.resetSavedKeys.failed": "e663cbf1d28235aee568f1cd2b3c837697c355d0de071f557053f0c61bba2a54",- "connectors.resetSavedKeys": "764411710357197d3d55fbf646d0ea6249c4236cbc635e0b4212b8d92cf5dea6"+ "connectors.resetSavedKeys": "764411710357197d3d55fbf646d0ea6249c4236cbc635e0b4212b8d92cf5dea6",+ "connectors.savedKeysUnreadable": "6a639d5ea19bf20de5ce7551bea2ccc330cfbd5085d0906a3ec9ece6959c4470"},"zh": {"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",