fix: normalize anthropic model ids

This commit is contained in:
Peter Steinberger
2026-01-09 05:07:16 +00:00
parent 9114331218
commit f9fe067f68
3 changed files with 32 additions and 3 deletions

View File

@@ -27,6 +27,15 @@ export function normalizeProviderId(provider: string): string {
return normalized;
}
function normalizeAnthropicModelId(model: string): string {
const trimmed = model.trim();
if (!trimmed) return trimmed;
const lower = trimmed.toLowerCase();
if (lower === "opus-4.5") return "claude-opus-4-5";
if (lower === "sonnet-4.5") return "claude-sonnet-4-5";
return trimmed;
}
export function parseModelRef(
raw: string,
defaultProvider: string,
@@ -35,13 +44,18 @@ export function parseModelRef(
if (!trimmed) return null;
const slash = trimmed.indexOf("/");
if (slash === -1) {
return { provider: normalizeProviderId(defaultProvider), model: trimmed };
const provider = normalizeProviderId(defaultProvider);
const model =
provider === "anthropic" ? normalizeAnthropicModelId(trimmed) : trimmed;
return { provider, model };
}
const providerRaw = trimmed.slice(0, slash).trim();
const provider = normalizeProviderId(providerRaw);
const model = trimmed.slice(slash + 1).trim();
if (!provider || !model) return null;
return { provider, model };
const normalizedModel =
provider === "anthropic" ? normalizeAnthropicModelId(model) : model;
return { provider, model: normalizedModel };
}
export function buildModelAliasIndex(params: {