fix: normalize explicit context provider aliases

This commit is contained in:
Tak Hoffman 2026-03-27 21:20:41 -05:00
parent fc542671eb
commit e5c4e89dc6
No known key found for this signature in database
2 changed files with 20 additions and 3 deletions

View File

@ -366,4 +366,19 @@ describe("lookupContextTokens", () => {
});
expect(result).toBe(1_048_576);
});
it("resolveContextTokensForModel normalizes explicit provider aliases before config lookup", async () => {
mockDiscoveryDeps([]);
const cfg = createContextOverrideConfig("z.ai", "glm-5", 256_000);
const { resolveContextTokensForModel } = await import("./context.js");
await flushAsyncWarmup();
const result = resolveContextTokensForModel({
cfg: cfg as never,
provider: "z-ai",
model: "glm-5",
});
expect(result).toBe(256_000);
});
});

View File

@ -292,9 +292,11 @@ function resolveProviderModelRef(params: {
}
const providerRaw = params.provider?.trim();
if (providerRaw) {
// Keep the exact (lowercased) provider key; callers that need the canonical
// alias (e.g. cache key construction) apply normalizeProviderId explicitly.
return { provider: providerRaw.toLowerCase(), model: modelRaw };
const provider = normalizeProviderId(providerRaw);
if (!provider) {
return undefined;
}
return { provider, model: modelRaw };
}
const slash = modelRaw.indexOf("/");
if (slash <= 0) {