Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(server): OpenCode model parsing drops models with a slash in the JSON body (#5072)
Arham Amin2ea51bd31f49
diff --git a/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts b/apps/server/src/provider/opencodeRuntime.cliParsers.test.tsindex 6208f0450..46577f377 100644--- a/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts+++ b/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts@@ -125,6 +125,31 @@ describe("parseModelsCliOutput", () => {NodeAssert.ok(model.variants);NodeAssert.equal(model.variants!["medium"] !== undefined, true);});++ it("keeps a model whose JSON body has a slash and no interior whitespace", () => {+ // OpenRouter-style: the model id contains a `/` and no string value has a+ // space, so the JSON body line itself matches the slug regex. It must still+ // be treated as the body of the preceding slug, not a new slug.+ const stdout = [+ "openrouter/qwen/qwen3-coder",+ JSON.stringify({+ id: "qwen/qwen3-coder",+ providerID: "openrouter",+ name: "qwen3-coder",+ status: "active",+ }),+ ].join("\n");++ const result = parseModelsCliOutput(stdout);+ NodeAssert.equal(result.providers.size, 1);+ NodeAssert.deepEqual([...result.connected], ["openrouter"]);+ const provider = result.providers.get("openrouter")!;+ NodeAssert.ok(provider);+ const model = provider.models["qwen/qwen3-coder"]!;+ NodeAssert.ok(model);+ NodeAssert.equal(model.id, "qwen/qwen3-coder");+ NodeAssert.equal(model.providerID, "openrouter");+ });});describe("parseAgentListCliOutput", () => {diff --git a/apps/server/src/provider/opencodeRuntime.ts b/apps/server/src/provider/opencodeRuntime.tsindex d9a07fb8f..95a6a0045 100644--- a/apps/server/src/provider/opencodeRuntime.ts+++ b/apps/server/src/provider/opencodeRuntime.ts@@ -216,7 +216,13 @@ export function parseModelsCliOutput(stdout: string): {};for (const line of lines) {- const slugMatch = SLUG_LINE_RE.exec(line);+ // A model's JSON body is a single `JSON.stringify` line starting with `{`,+ // while a provider/model slug is a bare `provider/model` header. Only the+ // latter can be a slug: without this guard a body line with no interior+ // whitespace and a `/` in one of its values (e.g. an OpenRouter model whose+ // `id` is `vendor/model`) matches SLUG_LINE_RE, so flushModel runs against+ // an empty body and the model is silently dropped.+ const slugMatch = line.trimStart().startsWith("{") ? null : SLUG_LINE_RE.exec(line);if (slugMatch) {flushModel();currentSlug = slugMatch[1]!;