Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(ollama): reload the added Ollama's models when a check finds a newly pulled one
AdityaUmaleccec24bff9dc
diff --git a/src/components/OllamaServer.tsx b/src/components/OllamaServer.tsxindex 1a4f7c3950..dd7f47ea95 100644--- a/src/components/OllamaServer.tsx+++ b/src/components/OllamaServer.tsx@@ -3,7 +3,7 @@ import { Loader2 } from "lucide-react";import { api, useStore, type InstanceInfo } from "@/state/store";import { t } from "@/lib/i18n";import { keySaved } from "@/lib/product-events";-import { addedServers } from "@/lib/openai-compat-endpoints";+import { addedServers, isAddedServer } from "@/lib/openai-compat-endpoints";import type { OllamaStatus } from "../../shared/local-model";import { KEY_FIELD } from "./keys/KeyRow";import { OllamaStatusLine } from "./OllamaStatusLine";@@ -17,7 +17,7 @@ const sameBase = (a: string | undefined, b: string) => a?.trim().replace(/\/+$/,/** Finds Ollama on this computer, or at an address someone enters, and adds it in one click: no key, no URL to type. */export function OllamaServer({ visible }: { visible: boolean }) {- const { state, dispatch, refreshInstances } = useStore();+ const { state, dispatch, refreshInstances, refreshModels } = useStore();const [address, setAddress] = useState("");const [status, setStatus] = useState<OllamaStatus | null>(null);const [checking, setChecking] = useState(false);@@ -43,8 +43,22 @@ export function OllamaServer({ visible }: { visible: boolean }) {check("");}, [visible, check]);+ // The added Ollama keeps the list it got when added; a model pulled since shows only in the check until that list reloads.+ const compatUrl = state.config?.openaiCompat?.url;+ const reloaded = useRef<OllamaStatus | null>(null);+ useEffect(() => {+ if (status?.state !== "ready" || reloaded.current === status) return;+ const base = ollamaBaseUrl(status.url);+ const stale = state.instances.filter((instance) =>+ (isAddedServer(instance) ? instance.url === base : instance.instanceId === "openaiCompat" && sameBase(compatUrl, base))+ && status.models.some((model) => !instance.models.options.some((option) => option.id === model.name)));+ if (!stale.length) return;+ reloaded.current = status;+ for (const instance of stale) void refreshModels(instance.instanceId).catch(() => {});+ }, [status, state.instances, compatUrl, refreshModels]);+const target = status ? ollamaBaseUrl(status.url) : null;- const present = Boolean(target && (addedServers(state.instances).some((server) => server.url === target) || sameBase(state.config?.openaiCompat?.url, target)));+ const present = Boolean(target && (addedServers(state.instances).some((server) => server.url === target) || sameBase(compatUrl, target)));const canAdd = Boolean(target && !present && !busy && !checking && (status?.state === "ready" || status?.state === "no-models"));const add = () => {diff --git a/src/components/keys/KeysPage.dom.test.ts b/src/components/keys/KeysPage.dom.test.tsindex a55a014fd2..9038850cd1 100644--- a/src/components/keys/KeysPage.dom.test.ts+++ b/src/components/keys/KeysPage.dom.test.ts@@ -11,6 +11,7 @@ const fx = vi.hoisted(() => ({listeners: new Set<() => void>(),api: vi.fn(),dispatch: vi.fn(),+ refreshModels: vi.fn(),}));vi.mock("@/state/store", async (original) => {const actual = await original<typeof import("@/state/store")>();@@ -21,7 +22,7 @@ vi.mock("@/state/store", async (original) => {api: (...args: unknown[]) => fx.api(...args),useStore: () => {const config = useSyncExternalStore(subscribe, () => fx.config);- return { state: { ...actual.initialState, config, instances: fx.instances as never }, dispatch: fx.dispatch };+ return { state: { ...actual.initialState, config, instances: fx.instances as never }, dispatch: fx.dispatch, refreshModels: fx.refreshModels };},};});@@ -75,6 +76,8 @@ beforeEach(() => {setLocale("en");fx.api.mockReset();fx.dispatch.mockReset();+ fx.refreshModels.mockReset();+ fx.refreshModels.mockResolvedValue(undefined);fx.dispatch.mockImplementation((action: { type: string; config?: Record<string, unknown> }) => {if (action.type === "configStatus") setConfig(action.config!);});@@ -366,6 +369,24 @@ describe("the Ollama row", () => {expect(row("ollama")!.textContent).toContain("already added");expect(button("Add Ollama").disabled).toBe(true);});++ it("reloads the added Ollama's model list when a check finds a model it lacks, as after ollama pull", async () => {+ const served = (instanceId: string, url: string) => ({+ instanceId, driverKind: "openai-compat", displayName: "Ollama", url, snapshot: { state: "available" },+ models: { default: "qwen3.5:9b", options: [{ id: "qwen3.5:9b", label: "qwen3.5:9b" }, { id: "bonsai-2:9b", label: "bonsai-2:9b" }] },+ });+ fx.instances = [served("openai-compat-here", "http://127.0.0.1:11434/v1"), served("openai-compat-elsewhere", "http://gpu-box.local:11434/v1")];+ answer("ready", undefined, [{ name: "qwen3.5:9b" }, { name: "bonsai-2:9b" }]);+ page();+ openServers();+ await found("ready");+ expect(fx.refreshModels).not.toHaveBeenCalled();+ answer("ready", undefined, [{ name: "qwen3.5:9b" }, { name: "bonsai-2:9b" }, { name: "nemotron-3.5-bolt:e4b" }]);+ flushSync(() => button("Check again").click());+ await vi.waitFor(() => expect(row("ollama")!.textContent).toContain("Pulled models: 3."));+ await vi.waitFor(() => expect(fx.refreshModels).toHaveBeenCalledWith("openai-compat-here"));+ expect(fx.refreshModels).toHaveBeenCalledOnce();+ });});describe("Boat's credit offer on the Boat card", () => {