Skip to content

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

fix(modelgo): ask for the model list again while none is listed

AdityaUmale98c3dce01459
diff --git a/server/drivers/modelgo.test.ts b/server/drivers/modelgo.test.ts
index 7a8a2446f1..f45f22c779 100644
--- a/server/drivers/modelgo.test.ts
+++ b/server/drivers/modelgo.test.ts
@@ -136,6 +136,27 @@ describe("ModelGo provider", () => {
expect(await instance.snapshot()).toMatchObject({ state: "unavailable", reason: expect.stringContaining("listed no models") });
});
+ it("asks for the models again on the next status read when the first list failed, as on a slow Windows start", async () => {
+ let down = true;
+ const listed = models;
+ server.removeAllListeners("request");
+ server.on("request", (req, res) => {
+ requests.push({ path: req.url ?? "" });
+ if (down) { req.socket.destroy(); return; }
+ res.writeHead(200, { "content-type": "application/json" });
+ res.end(JSON.stringify(listed));
+ });
+ const instance = await create({ url: base });
+ expect(await instance.snapshot()).toMatchObject({ state: "unavailable" });
+ expect(instance.models.options).toEqual([]);
+ down = false;
+ expect(await instance.snapshot()).toMatchObject({ state: "available", authenticated: true });
+ expect(instance.models.options).toEqual([{ id: "fixture-tool-model", label: "fixture-tool-model" }]);
+ const asked = requests.length;
+ await instance.snapshot();
+ expect(requests).toHaveLength(asked);
+ });
+
it("streams over /chat/completions with the key, tools, reasoning and the usage frame that has no choices", async () => {
reply = (_body, res) => stream(res, [
{ choices: [{ delta: { reasoning_content: "Thinking." } }] },
diff --git a/server/drivers/modelgo.ts b/server/drivers/modelgo.ts
index f1f26bfb6b..fd2d5d714f 100644
--- a/server/drivers/modelgo.ts
+++ b/server/drivers/modelgo.ts
@@ -73,7 +73,7 @@ export const ModelgoDriver: ProviderDriver<ModelgoConfig> = {
};
let catalog = withConfiguredModel(NO_MODELS.options);
let imageModels = new Set<string>();
- const refreshModels = async () => {
+ const fetchModels = async () => {
if (!apiKey) return;
try {
const response = await fetch(`${config.url}/models`, {
@@ -97,7 +97,10 @@ export const ModelgoDriver: ProviderDriver<ModelgoConfig> = {
}
} catch {}
};
- const firstRefresh = refreshModels();
+ // One list request at a time; while no model is listed, each status read asks again, so a start without a network recovers.
+ let listing: Promise<void> | null = null;
+ const refreshModels = () => listing ??= fetchModels().finally(() => { listing = null; });
+ void refreshModels();
return createOpenAIChatRuntime({
input, driverKind: "modelgo", apiKey, apiUrl: config.url,
tools: config.tools, models: () => catalog, refreshModels, reasoning: true,
@@ -109,7 +112,7 @@ export const ModelgoDriver: ProviderDriver<ModelgoConfig> = {
missingKeyError: "Save a ModelGo API key in Settings → AI → Providers, or set MODELGO_API_KEY.",
unavailableReason: "No ModelGo API key — open Settings → AI → Providers.",
serverUnavailable: async () => {
- await firstRefresh;
+ if (apiKey && !catalog.options.length) await refreshModels();
return apiKey && !catalog.options.length ? { reason: "ModelGo listed no models for this key. Check the key in the ModelGo console, then check again." } : null;
},
timeoutMs: 180_000, billing: "metered", includeUsageInCompleted: true,