Skip to content

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

fix(keys): pick the missing engine that has an install command; say when Check again fails

AdityaUmalee54a3f9ebfa2
diff --git a/src/components/keys/KeyRow.dom.test.ts b/src/components/keys/KeyRow.dom.test.ts
new file mode 100644
index 0000000000..66690db315
--- /dev/null
+++ b/src/components/keys/KeyRow.dom.test.ts
@@ -0,0 +1,54 @@
+// @vitest-environment happy-dom
+import { createElement } from "react";
+import { flushSync } from "react-dom";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { setLocale } from "@/lib/i18n";
+import type { InstanceInfo } from "@/state/store";
+
+const fx = vi.hoisted(() => ({ refreshInstances: vi.fn() }));
+vi.mock("@/state/store", async (original) => {
+ const actual = await original<typeof import("@/state/store")>();
+ const instances = [{ instanceId: "deepseek", driverKind: "deepseekAgent", displayName: "DeepSeek Harness", snapshot: { state: "unavailable" },
+ install: { platform: "linux", command: { linux: "npm install -g @deepseek-ai/dsh" } }, models: { default: "m", options: [] } }] as unknown as InstanceInfo[];
+ return {
+ ...actual,
+ useStore: () => ({ state: { ...actual.initialState, config: { deepseek: { configured: true, last4: "9z9z" } }, instances }, dispatch: vi.fn(), refreshInstances: fx.refreshInstances }),
+ };
+});
+vi.mock("@/lib/analytics", () => ({ track: vi.fn() }));
+
+const { KeyRow } = await import("./KeyRow");
+
+let host: HTMLDivElement;
+let root: Root;
+
+beforeEach(() => {
+ setLocale("en");
+ fx.refreshInstances.mockReset();
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+ flushSync(() => root.render(createElement(KeyRow, { id: "deepseek" })));
+});
+afterEach(() => {
+ flushSync(() => root.unmount());
+ host.remove();
+});
+
+const checkAgain = () => host.querySelector<HTMLButtonElement>("[data-key-engine-check]")!;
+const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
+
+it("says when Check again could not reach the server, and clears that on the next try", async () => {
+ fx.refreshInstances.mockRejectedValueOnce(new Error("fixture offline"));
+ flushSync(() => checkAgain().click());
+ expect(fx.refreshInstances).toHaveBeenCalledWith({ reportErrors: true });
+ await settle();
+ expect(host.querySelector("[data-key-engine-missing] [role=alert]")?.textContent).toContain("fixture offline");
+ expect(checkAgain().disabled).toBe(false);
+
+ fx.refreshInstances.mockResolvedValueOnce(undefined);
+ flushSync(() => checkAgain().click());
+ await settle();
+ expect(host.querySelector("[data-key-engine-missing] [role=alert]")).toBeNull();
+});
diff --git a/src/components/keys/KeyRow.test.ts b/src/components/keys/KeyRow.test.ts
index 6521e15c7d..4173f869c9 100644
--- a/src/components/keys/KeyRow.test.ts
+++ b/src/components/keys/KeyRow.test.ts
@@ -112,6 +112,9 @@ describe("a saved key", () => {
expect(render({ id: "xai" })).not.toContain("data-key-engine-missing");
fixture.instances = [{ ...deepseek("unavailable"), instanceId: "grok", displayName: "Grok" }];
expect(render({ id: "xai" })).toContain("data-key-engine-missing");
+ // An unavailable engine with nothing to install (xAI API on a custom URL) doesn't hide the one that has a command.
+ fixture.instances = [{ ...deepseek("unavailable"), instanceId: "xaiApi", displayName: "xAI API", install: undefined }, { ...deepseek("unavailable"), instanceId: "grok", displayName: "Grok" }];
+ expect(render({ id: "xai" })).toContain("Saved, but Grok can&#x27;t run on this computer yet");
fixture.config = {};
fixture.instances = [deepseek("unavailable")];
expect(render({ id: "deepseek" })).not.toContain("data-key-engine-missing");
diff --git a/src/components/keys/KeyRow.tsx b/src/components/keys/KeyRow.tsx
index e7c7f4c8ed..cb02d083be 100644
--- a/src/components/keys/KeyRow.tsx
+++ b/src/components/keys/KeyRow.tsx
@@ -109,6 +109,7 @@ export function KeyRow({
const [verdict, setVerdict] = useState<string | null>(null);
const [works, setWorks] = useState(false);
const [enginesChecking, setEnginesChecking] = useState(false);
+ const [engineCheckError, setEngineCheckError] = useState<string | null>(null);
const busyRef = useRef(false);
const generation = useRef(0);
const inputRef = useRef<HTMLInputElement>(null);
@@ -135,7 +136,7 @@ export function KeyRow({
const keyEngines = saved.configured ? (state.instances ?? []).filter((instance) => keyForInstance(instance.instanceId) === entry.id) : [];
const missingEngine = keyEngines.some((instance) => instance.snapshot.state === "available")
? undefined
- : keyEngines.find((instance) => instance.snapshot.state === "unavailable");
+ : keyEngines.find((instance) => instance.snapshot.state === "unavailable" && installCommandFor(instance.install) !== null);
const installCommand = installCommandFor(missingEngine?.install);
const rejected = !works && (rejectedHere ?? (saved.configured && engineRejected));
const failure = problem ?? (rejected && !busy ? t("keys.testRejected") : null);
@@ -205,6 +206,18 @@ export function KeyRow({
}
};
+ const checkEngines = async () => {
+ setEnginesChecking(true);
+ setEngineCheckError(null);
+ try {
+ await refreshInstances({ reportErrors: true });
+ } catch (cause) {
+ setEngineCheckError(errorText(cause));
+ } finally {
+ setEnginesChecking(false);
+ }
+ };
+
const recheck = async () => {
if (busyRef.current) return;
busyRef.current = true;
@@ -367,9 +380,10 @@ export function KeyRow({
</p>
<code className="select-all break-all rounded-md bg-inset px-2 py-1 font-mono text-[12px] text-ink">{installCommand}</code>
<button type="button" data-key-engine-check className="cursor-pointer self-start text-ink-secondary hover:text-ink hover:underline disabled:opacity-50" disabled={enginesChecking}
- onClick={() => { setEnginesChecking(true); void refreshInstances().finally(() => setEnginesChecking(false)); }}>
+ onClick={() => void checkEngines()}>
{enginesChecking ? t("common.checking") : t("common.checkAgain")}
</button>
+ {engineCheckError && <p role="alert" className="text-danger">{t("engineSetup.checkFailed", { reason: engineCheckError })}</p>}
</div>
)}
{note && <p className="text-ink-secondary">{note}</p>}