CLI: isolate provider model id transforms from shared mocks
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
|
|
||||||
import { transformModelForProvider } from "./provider-model-id-transform"
|
import { transformModelForProvider } from "./provider-model-id-transform"
|
||||||
|
import { transformModelForProvider as transformSharedModelForProvider } from "../shared/provider-model-id-transform"
|
||||||
|
|
||||||
describe("transformModelForProvider", () => {
|
describe("transformModelForProvider", () => {
|
||||||
describe("github-copilot provider", () => {
|
describe("github-copilot provider", () => {
|
||||||
@@ -336,4 +337,15 @@ describe("transformModelForProvider", () => {
|
|||||||
expect(result).toBe("gemini-3-flash")
|
expect(result).toBe("gemini-3-flash")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("uses a CLI-local transform implementation", () => {
|
||||||
|
// #given
|
||||||
|
const cliResult = transformModelForProvider("anthropic", "claude-opus-4-6")
|
||||||
|
const sharedResult = transformSharedModelForProvider("anthropic", "claude-opus-4-6")
|
||||||
|
|
||||||
|
// #when
|
||||||
|
expect(transformModelForProvider).not.toBe(transformSharedModelForProvider)
|
||||||
|
expect(cliResult).toBe("claude-opus-4.6")
|
||||||
|
expect(sharedResult).toBe("claude-opus-4.6")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1 +1,61 @@
|
|||||||
export { transformModelForProvider } from "../shared/provider-model-id-transform"
|
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"
|
||||||
|
if (model.startsWith("minimax-")) return "minimax"
|
||||||
|
if (model.startsWith("kimi-")) return "moonshotai"
|
||||||
|
if (model.startsWith("glm-")) return "zai"
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
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",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformModelForProvider(provider: string, model: string): string {
|
||||||
|
if (provider === "vercel") {
|
||||||
|
const slashIndex = model.indexOf("/")
|
||||||
|
if (slashIndex !== -1) {
|
||||||
|
const subProvider = model.substring(0, slashIndex)
|
||||||
|
const subModel = model.substring(slashIndex + 1)
|
||||||
|
return `${subProvider}/${applyGatewayTransforms(subModel)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const subProvider = inferSubProvider(model)
|
||||||
|
if (subProvider) {
|
||||||
|
return `${subProvider}/${applyGatewayTransforms(model)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
if (provider === "github-copilot") {
|
||||||
|
return claudeVersionDot(model)
|
||||||
|
.replace(GEMINI_31_PRO_PREVIEW, "gemini-3.1-pro-preview")
|
||||||
|
.replace(GEMINI_3_FLASH_PREVIEW, "gemini-3-flash-preview")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (provider === "google") {
|
||||||
|
return model
|
||||||
|
.replace(GEMINI_31_PRO_PREVIEW, "gemini-3.1-pro-preview")
|
||||||
|
.replace(GEMINI_3_FLASH_PREVIEW, "gemini-3-flash-preview")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (provider === "anthropic") {
|
||||||
|
return claudeVersionDot(model)
|
||||||
|
}
|
||||||
|
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user