fix(models): store provider custom models by provider scope

This commit is contained in:
nguyenha935
2026-06-20 15:19:22 +07:00
committed by decolua
parent 8efacc1147
commit 707a91555d
6 changed files with 282 additions and 118 deletions
+84
View File
@@ -0,0 +1,84 @@
import { describe, expect, it } from "vitest";
import { getProviderCustomModelRows } from "@/shared/utils/providerCustomModels.js";
describe("provider custom model rows", () => {
it("keeps identical model IDs separate per provider", () => {
const customModels = [
{ providerAlias: "ollama", id: "minimax-m2.5", type: "llm", name: "MiniMax M2.5" },
{ providerAlias: "opencode-go", id: "minimax-m2.5", type: "llm", name: "MiniMax M2.5" },
];
expect(getProviderCustomModelRows({ customModels, providerAlias: "ollama" })).toEqual([
{
id: "minimax-m2.5",
name: "MiniMax M2.5",
fullModel: "ollama/minimax-m2.5",
source: "custom",
type: "llm",
},
]);
expect(getProviderCustomModelRows({ customModels, providerAlias: "opencode-go" })).toEqual([
{
id: "minimax-m2.5",
name: "MiniMax M2.5",
fullModel: "opencode-go/minimax-m2.5",
source: "custom",
type: "llm",
},
]);
});
it("keeps legacy alias-backed models visible without duplicating custom models", () => {
const rows = getProviderCustomModelRows({
customModels: [
{ providerAlias: "ollama", id: "custom-a", type: "llm", name: "Custom A" },
],
modelAliases: {
"custom-a": "ollama/custom-a",
"legacy-b": "ollama/legacy-b",
"other-provider": "opencode-go/legacy-b",
},
providerAlias: "ollama",
});
expect(rows).toEqual([
{
id: "custom-a",
name: "Custom A",
fullModel: "ollama/custom-a",
source: "custom",
type: "llm",
},
{
id: "legacy-b",
alias: "legacy-b",
fullModel: "ollama/legacy-b",
source: "legacyAlias",
type: "llm",
},
]);
});
it("filters built-in models and typed custom models", () => {
const rows = getProviderCustomModelRows({
customModels: [
{ providerAlias: "ollama", id: "llama3", type: "llm", name: "Llama 3" },
{ providerAlias: "ollama", id: "custom-image", type: "image", name: "Custom Image" },
{ providerAlias: "ollama", id: "custom-llm", type: "llm", name: "Custom LLM" },
],
providerAlias: "ollama",
builtInModels: [{ id: "llama3" }],
type: "llm",
});
expect(rows).toEqual([
{
id: "custom-llm",
name: "Custom LLM",
fullModel: "ollama/custom-llm",
source: "custom",
type: "llm",
},
]);
});
});