fix: handle all model versions in normalizeModelName for fallback chains (#1679)

This commit is contained in:
YeonGyu-Kim
2026-02-17 01:27:10 +09:00
parent fcf26d9898
commit dab99531e4
3 changed files with 23 additions and 5 deletions

View File

@@ -233,6 +233,27 @@ describe("fuzzyMatchModel", () => {
expect(result).toBe("anthropic/claude-opus-4-6")
})
// given github-copilot serves claude versions with dot notation
// when fallback chain uses hyphen notation in requested model
// then normalize both forms and match github-copilot model
it("should match github-copilot claude-opus-4-6 to claude-opus-4.6", () => {
const available = new Set([
"github-copilot/claude-opus-4.6",
"opencode/glm-4.7-free",
])
const result = fuzzyMatchModel("claude-opus-4-6", available, ["github-copilot"])
expect(result).toBe("github-copilot/claude-opus-4.6")
})
// given claude models can evolve to newer version numbers
// when matching across dot and hyphen version separators
// then normalize generically without hardcoding specific versions
it("should normalize claude version separators for future versions", () => {
const available = new Set(["github-copilot/claude-sonnet-5.1"])
const result = fuzzyMatchModel("claude-sonnet-5-1", available, ["github-copilot"])
expect(result).toBe("github-copilot/claude-sonnet-5.1")
})
// given available models from multiple providers
// when providers filter is specified
// then only search models from specified providers

View File

@@ -28,8 +28,7 @@ import { normalizeSDKResponse } from "./normalize-sdk-response"
function normalizeModelName(name: string): string {
return name
.toLowerCase()
.replace(/claude-(opus|sonnet|haiku)-4-5/g, "claude-$1-4.5")
.replace(/claude-(opus|sonnet|haiku)-4\.5/g, "claude-$1-4.5")
.replace(/claude-(opus|sonnet|haiku)-(\d+)[.-](\d+)/g, "claude-$1-$2.$3")
}
export function fuzzyMatchModel(

View File

@@ -3,8 +3,7 @@ import { log } from "./logger"
function normalizeModelName(name: string): string {
return name
.toLowerCase()
.replace(/claude-(opus|sonnet|haiku)-4-5/g, "claude-$1-4.5")
.replace(/claude-(opus|sonnet|haiku)-4\.5/g, "claude-$1-4.5")
.replace(/claude-(opus|sonnet|haiku)-(\d+)[.-](\d+)/g, "claude-$1-$2.$3")
}
export function fuzzyMatchModel(
@@ -82,4 +81,3 @@ export function fuzzyMatchModel(
log("[fuzzyMatchModel] shortest match", { result })
return result
}