fix: merge normalized OpenRouter provider settings

This commit is contained in:
Dallin Romney
2026-08-13 16:43:14 +08:00
parent 0f0109882f
commit b594e80ee8
2 changed files with 3 additions and 12 deletions
+2 -2
View File
@@ -1145,13 +1145,13 @@ describe("openrouter provider hooks", () => {
});
});
it("merges routing split across trimmed duplicate OpenRouter provider keys", async () => {
it("merges routing split across case- and whitespace-equivalent OpenRouter keys", async () => {
const provider = await registerSingleProviderPlugin(openrouterPlugin);
const patch = provider.extraParamsForTransport?.({
config: {
models: {
providers: {
" openrouter ": {
" OpenRouter ": {
params: {
provider: {
order: ["anthropic"],
+1 -10
View File
@@ -75,20 +75,11 @@ function resolveOpenRouterProviderConfigParams(
}
const providers = Object.entries(ctx.config?.models?.providers ?? {});
const exactKey = providers.find(([provider]) => provider.trim() === requestedProvider)?.[0];
const fallbackKey = providers.find(
([provider]) => normalizeProviderId(provider) === normalizedProvider,
)?.[0];
const providerKey = (exactKey ?? fallbackKey)?.trim();
if (!providerKey) {
return undefined;
}
// Preserve routing split across normalized duplicates; merge nested params
// field-wise while allowing later scalar settings to override earlier ones.
let matchedParams: Record<string, unknown> | undefined;
for (const [provider, config] of providers) {
if (provider.trim() !== providerKey) {
if (normalizeProviderId(provider) !== normalizedProvider) {
continue;
}
const params = readRecord(config.params);