fix(server): OpenCode model parsing drops models with a slash in the JSON body (#5072)
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
1 parent
e5c82d79a0
commit
2ea51bd31f
2 files changed
+32
-1
No files matched your search
@@ -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", () => {
|
||||
|
||||
@@ -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]!;
|
||||
|
||||
Reference in new issue
Block a user