mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 23:02:10 +03:00
fix(auth): normalize codex alias credential lookup
This commit is contained in:
@@ -105,12 +105,13 @@ export function parseModel(modelStr) {
|
||||
extendedContext = true;
|
||||
cleanStr = cleanStr.slice(0, -4);
|
||||
}
|
||||
cleanStr = cleanStr.trim();
|
||||
|
||||
// Check if standard format: provider/model or alias/model
|
||||
if (cleanStr.includes("/")) {
|
||||
const firstSlash = cleanStr.indexOf("/");
|
||||
const providerOrAlias = cleanStr.slice(0, firstSlash);
|
||||
const model = cleanStr.slice(firstSlash + 1);
|
||||
const providerOrAlias = cleanStr.slice(0, firstSlash).trim();
|
||||
const model = cleanStr.slice(firstSlash + 1).trim();
|
||||
const provider = resolveProviderAlias(providerOrAlias);
|
||||
return { provider, model, isAlias: false, providerAlias: providerOrAlias, extendedContext };
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from "@omniroute/open-sse/config/providerRegistry.ts";
|
||||
import { COOLDOWN_MS } from "@omniroute/open-sse/config/constants.ts";
|
||||
import { getCodexModelScope } from "@omniroute/open-sse/executors/codex.ts";
|
||||
import { getProviderAlias, resolveProviderId } from "@/shared/constants/providers";
|
||||
import * as log from "../utils/logger";
|
||||
import { fisherYatesShuffle, getNextFromDeckSync } from "@/shared/utils/shuffleDeck";
|
||||
|
||||
@@ -316,13 +317,17 @@ export { fisherYatesShuffle, getNextFromDeckSync as getNextFromDeck };
|
||||
* Resolve provider aliases (e.g., nvidia -> nvidia_nim) for DB lookup
|
||||
*/
|
||||
function getProviderSearchPool(provider: string): string[] {
|
||||
const canonicalProvider = resolveProviderId(provider);
|
||||
const canonicalAlias = getProviderAlias(canonicalProvider);
|
||||
|
||||
if (provider === "nvidia") {
|
||||
return ["nvidia", "nvidia_nim"];
|
||||
}
|
||||
if (provider === "nvidia_nim") {
|
||||
return ["nvidia_nim", "nvidia"];
|
||||
}
|
||||
return [provider];
|
||||
|
||||
return Array.from(new Set([provider, canonicalProvider, canonicalAlias].filter(Boolean)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,3 +56,19 @@ test("clearAccountError clears stale provider error metadata after recovery", as
|
||||
assert.equal(updated.rateLimitedUntil, undefined);
|
||||
assert.equal(updated.backoffLevel, 0);
|
||||
});
|
||||
|
||||
test("getProviderCredentials resolves provider aliases to canonical DB records", async () => {
|
||||
await resetStorage();
|
||||
|
||||
const created = await providersDb.createProviderConnection({
|
||||
provider: "codex",
|
||||
authType: "oauth",
|
||||
email: "alias@example.com",
|
||||
accessToken: "access",
|
||||
refreshToken: "refresh",
|
||||
testStatus: "active",
|
||||
});
|
||||
|
||||
const credentials = await auth.getProviderCredentials("cx");
|
||||
assert.equal(credentials.connectionId, created.id);
|
||||
});
|
||||
|
||||
@@ -20,3 +20,10 @@ test("[1m] suffix: works with provider prefix", () => {
|
||||
assert.strictEqual(result.model, "claude-sonnet-4-6");
|
||||
assert.strictEqual(result.extendedContext, true);
|
||||
});
|
||||
|
||||
test("parseModel trims provider prefix and model id", () => {
|
||||
const result = parseModel(" cx / gpt-5.4 ");
|
||||
assert.strictEqual(result.providerAlias, "cx");
|
||||
assert.strictEqual(result.provider, "codex");
|
||||
assert.strictEqual(result.model, "gpt-5.4");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user