fix: normalize model scan provider filters

This commit is contained in:
Tak Hoffman
2026-03-27 21:23:21 -05:00
parent 3143cf86e8
commit d519beb925
2 changed files with 34 additions and 2 deletions

View File

@@ -80,4 +80,35 @@ describe("scanOpenRouterModels", () => {
).rejects.toThrow(/Missing OpenRouter API key/);
});
});
it("matches provider filters across canonical provider aliases", async () => {
const fetchImpl = createFetchFixture({
data: [
{
id: "z.ai/glm-5",
name: "GLM-5",
context_length: 128_000,
supported_parameters: [],
modality: "text",
pricing: { prompt: "0", completion: "0" },
},
{
id: "openai/gpt-5",
name: "GPT-5",
context_length: 128_000,
supported_parameters: [],
modality: "text",
pricing: { prompt: "0", completion: "0" },
},
],
});
const results = await scanOpenRouterModels({
fetchImpl,
probe: false,
providerFilter: "z-ai",
});
expect(results.map((entry) => entry.id)).toEqual(["z.ai/glm-5"]);
});
});

View File

@@ -9,6 +9,7 @@ import {
} from "@mariozechner/pi-ai";
import { Type } from "@sinclair/typebox";
import { inferParamBFromIdOrName } from "../shared/model-param-b.js";
import { normalizeProviderId } from "./provider-id.js";
const OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models";
const DEFAULT_TIMEOUT_MS = 12_000;
@@ -408,7 +409,7 @@ export async function scanOpenRouterModels(
const concurrency = Math.max(1, Math.floor(options.concurrency ?? DEFAULT_CONCURRENCY));
const minParamB = Math.max(0, Math.floor(options.minParamB ?? 0));
const maxAgeDays = Math.max(0, Math.floor(options.maxAgeDays ?? 0));
const providerFilter = options.providerFilter?.trim().toLowerCase() ?? "";
const providerFilter = normalizeProviderId(options.providerFilter ?? "");
const catalog = await fetchOpenRouterModels(fetchImpl);
const now = Date.now();
@@ -418,7 +419,7 @@ export async function scanOpenRouterModels(
return false;
}
if (providerFilter) {
const prefix = entry.id.split("/")[0]?.toLowerCase() ?? "";
const prefix = normalizeProviderId(entry.id.split("/")[0] ?? "");
if (prefix !== providerFilter) {
return false;
}