mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-24 08:02:14 +03:00
Release v3.8.42 — full CHANGELOG in CHANGELOG.md. CI: 103 checks green incl. CodeQL (all languages), Semgrep, all 8 unit shards, coverage, Node 24 compat, and integration tests. Full unit suite validated locally: 19437 pass / 0 fail. The 3 red checks are advisory and do not gate main (no required status checks): SonarCloud/SonarQube new-code coverage gate, and PR Test Policy (test-masking detector flagging the legitimate dead-Phind provider removal in #5530 — reviewed, correct). Includes cycle-close reconciliation + repair of inherited base-red tests from #5480/#5527/#5427/#5521 that the PR->release fast-path did not exercise.
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
const FAMILY_FIRST_MODEL_PATTERN =
|
|
/^((?:gpt-[a-z0-9._-]+|claude[a-z0-9._-]*))(?:__provider_([a-z0-9-]+))(?:__tier_(priority|flex))?$/i;
|
|
const TIER_SUFFIX_PATTERN = /(__tier_(?:priority|flex))$/i;
|
|
|
|
function normalizeFamily(value: string | null | undefined) {
|
|
return typeof value === "string" ? value.trim() : "";
|
|
}
|
|
|
|
function splitActualModelId(modelId: string) {
|
|
const trimmedModelId = modelId.trim();
|
|
const slashIndex = trimmedModelId.indexOf("/");
|
|
if (slashIndex <= 0 || slashIndex === trimmedModelId.length - 1) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
providerPrefix: trimmedModelId.slice(0, slashIndex),
|
|
providerModelId: trimmedModelId.slice(slashIndex + 1),
|
|
};
|
|
}
|
|
|
|
function extractTierSuffix(modelId: string) {
|
|
const match = modelId.match(TIER_SUFFIX_PATTERN);
|
|
return match?.[1] || "";
|
|
}
|
|
|
|
function stripTierSuffix(modelId: string) {
|
|
return modelId.replace(TIER_SUFFIX_PATTERN, "");
|
|
}
|
|
|
|
function isFamilyFirstEligibleFamily(family: string) {
|
|
const normalized = family.toLowerCase();
|
|
return normalized.startsWith("gpt-") || normalized.startsWith("claude");
|
|
}
|
|
|
|
export function getFamilyFirstPublishedModelId(
|
|
actualModelId: string,
|
|
family: string | null | undefined
|
|
) {
|
|
const normalizedFamily = normalizeFamily(family);
|
|
if (!normalizedFamily || !isFamilyFirstEligibleFamily(normalizedFamily)) {
|
|
return actualModelId;
|
|
}
|
|
|
|
const parts = splitActualModelId(actualModelId);
|
|
if (!parts) {
|
|
return actualModelId;
|
|
}
|
|
|
|
const tierSuffix = extractTierSuffix(parts.providerModelId);
|
|
const providerModelBase = stripTierSuffix(parts.providerModelId);
|
|
if (providerModelBase !== normalizedFamily) {
|
|
return actualModelId;
|
|
}
|
|
|
|
return `${normalizedFamily}__provider_${parts.providerPrefix}${tierSuffix}`;
|
|
}
|
|
|
|
export function resolveFamilyFirstPublishedModelId(modelId: string | null | undefined) {
|
|
const trimmedModelId = typeof modelId === "string" ? modelId.trim() : "";
|
|
if (!trimmedModelId) {
|
|
return trimmedModelId;
|
|
}
|
|
|
|
const match = trimmedModelId.match(FAMILY_FIRST_MODEL_PATTERN);
|
|
if (!match) {
|
|
return trimmedModelId;
|
|
}
|
|
|
|
const [, family, providerPrefix, serviceTier] = match;
|
|
const tierSuffix = serviceTier ? `__tier_${serviceTier.toLowerCase()}` : "";
|
|
return `${providerPrefix}/${family}${tierSuffix}`;
|
|
}
|
|
|
|
export function getFamilyFirstModelCandidates(
|
|
actualModelId: string,
|
|
family: string | null | undefined
|
|
) {
|
|
const normalizedFamily = normalizeFamily(family);
|
|
const candidates = new Set<string>([actualModelId]);
|
|
const publishedModelId = getFamilyFirstPublishedModelId(actualModelId, normalizedFamily);
|
|
if (publishedModelId !== actualModelId) {
|
|
candidates.add(publishedModelId);
|
|
}
|
|
|
|
if (normalizedFamily && isFamilyFirstEligibleFamily(normalizedFamily)) {
|
|
const tierSuffix = extractTierSuffix(actualModelId);
|
|
candidates.add(`${normalizedFamily}${tierSuffix}`);
|
|
}
|
|
|
|
return [...candidates];
|
|
}
|