fix(ui): prevent double-qualifying already-qualified model values

When the server returns a model string that already contains a provider
prefix (e.g. "ollama/gpt-oss:120b-cloud"), buildQualifiedChatModelValue
would blindly prepend the session's default provider, producing invalid
refs like "anthropic/ollama/gpt-oss:120b-cloud".

Skip provider prepending when the model string already contains "/".

Closes #51139
Closes #51306

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cypherm 2026-03-21 10:30:14 +08:00
parent a4a5ed8948
commit c58de43f35
3 changed files with 18 additions and 0 deletions

View File

@ -47,4 +47,16 @@ describe("chat-model-ref helpers", () => {
expect(resolveServerChatModelValue("gpt-5-mini", "openai")).toBe("openai/gpt-5-mini");
expect(resolveServerChatModelValue("alias-only", null)).toBe("alias-only");
});
it("does not double-qualify already-qualified model values", () => {
expect(resolveServerChatModelValue("ollama/gpt-oss:120b-cloud", "anthropic")).toBe(
"ollama/gpt-oss:120b-cloud",
);
});
it("preserves nested vendor/model identifiers", () => {
expect(
resolveServerChatModelValue("openrouter/anthropic/claude-sonnet-4-6", "openrouter"),
).toBe("openrouter/anthropic/claude-sonnet-4-6");
});
});

View File

@ -15,6 +15,11 @@ export function buildQualifiedChatModelValue(model: string, provider?: string |
if (!trimmedModel) {
return "";
}
// If the model string already contains "/" it is already provider-qualified
// (e.g. "ollama/gpt-oss:120b-cloud"); return as-is to avoid double-qualifying.
if (trimmedModel.includes("/")) {
return trimmedModel;
}
const trimmedProvider = provider?.trim();
return trimmedProvider ? `${trimmedProvider}/${trimmedModel}` : trimmedModel;
}

View File

@ -37,6 +37,7 @@ export default defineConfig({
"src/**/*.test.ts",
"extensions/**/*.test.ts",
"test/**/*.test.ts",
"ui/src/ui/chat-model-ref.test.ts",
"ui/src/ui/app-chat.test.ts",
"ui/src/ui/views/agents-utils.test.ts",
"ui/src/ui/views/chat.test.ts",