2026-04-13 11:22:22 +09:00
|
|
|
function inferSubProvider(model: string): string | undefined {
|
|
|
|
|
if (model.startsWith("claude-")) return "anthropic"
|
|
|
|
|
if (model.startsWith("gpt-")) return "openai"
|
|
|
|
|
if (model.startsWith("gemini-")) return "google"
|
|
|
|
|
if (model.startsWith("grok-")) return "xai"
|
2026-04-13 13:44:50 +09:00
|
|
|
if (model.startsWith("minimax-")) return "minimax"
|
|
|
|
|
if (model.startsWith("kimi-")) return "moonshotai"
|
|
|
|
|
if (model.startsWith("glm-")) return "zai"
|
2026-04-13 11:22:22 +09:00
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 14:01:17 +09:00
|
|
|
const CLAUDE_VERSION_DOT = /claude-(\w+)-(\d+)-(\d+)/g
|
|
|
|
|
const GEMINI_31_PRO_PREVIEW = /gemini-3\.1-pro(?!-)/g
|
|
|
|
|
const GEMINI_3_FLASH_PREVIEW = /gemini-3-flash(?!-)/g
|
|
|
|
|
|
|
|
|
|
function claudeVersionDot(model: string): string {
|
|
|
|
|
return model.replace(CLAUDE_VERSION_DOT, "claude-$1-$2.$3")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function applyGatewayTransforms(model: string): string {
|
|
|
|
|
return claudeVersionDot(model)
|
|
|
|
|
.replace(GEMINI_31_PRO_PREVIEW, "gemini-3.1-pro-preview")
|
2026-04-13 12:51:56 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-17 22:18:47 +09:00
|
|
|
export function transformModelForProvider(provider: string, model: string): string {
|
2026-04-13 11:22:22 +09:00
|
|
|
if (provider === "vercel") {
|
|
|
|
|
const slashIndex = model.indexOf("/")
|
|
|
|
|
if (slashIndex !== -1) {
|
|
|
|
|
const subProvider = model.substring(0, slashIndex)
|
|
|
|
|
const subModel = model.substring(slashIndex + 1)
|
2026-04-13 14:01:17 +09:00
|
|
|
return `${subProvider}/${applyGatewayTransforms(subModel)}`
|
2026-04-13 11:22:22 +09:00
|
|
|
}
|
|
|
|
|
const subProvider = inferSubProvider(model)
|
|
|
|
|
if (subProvider) {
|
2026-04-13 14:01:17 +09:00
|
|
|
return `${subProvider}/${applyGatewayTransforms(model)}`
|
2026-04-13 11:22:22 +09:00
|
|
|
}
|
|
|
|
|
return model
|
|
|
|
|
}
|
2026-02-17 22:18:47 +09:00
|
|
|
if (provider === "github-copilot") {
|
2026-04-13 14:01:17 +09:00
|
|
|
return claudeVersionDot(model)
|
|
|
|
|
.replace(GEMINI_31_PRO_PREVIEW, "gemini-3.1-pro-preview")
|
|
|
|
|
.replace(GEMINI_3_FLASH_PREVIEW, "gemini-3-flash-preview")
|
2026-02-17 22:18:47 +09:00
|
|
|
}
|
|
|
|
|
if (provider === "google") {
|
|
|
|
|
return model
|
2026-04-13 14:01:17 +09:00
|
|
|
.replace(GEMINI_31_PRO_PREVIEW, "gemini-3.1-pro-preview")
|
|
|
|
|
.replace(GEMINI_3_FLASH_PREVIEW, "gemini-3-flash-preview")
|
2026-02-17 22:18:47 +09:00
|
|
|
}
|
2026-04-12 02:28:27 +09:00
|
|
|
if (provider === "anthropic") {
|
2026-04-13 14:01:17 +09:00
|
|
|
return claudeVersionDot(model)
|
2026-04-12 02:28:27 +09:00
|
|
|
}
|
2026-02-17 22:18:47 +09:00
|
|
|
return model
|
|
|
|
|
}
|