mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
fix(model-resolver): use numeric-aware version comparison for model alias resolution
This commit is contained in:
@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";
|
||||
import type { Model } from "../../llm/types.js";
|
||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../defaults.js";
|
||||
import type { ModelRegistry } from "./model-registry.js";
|
||||
import { findInitialModel, restoreModelFromSession } from "./model-resolver.js";
|
||||
import { findInitialModel, parseModelPattern, restoreModelFromSession } from "./model-resolver.js";
|
||||
|
||||
function model(provider: string, id: string): Model {
|
||||
return {
|
||||
@@ -57,3 +57,15 @@ describe("model resolver fallback selection", () => {
|
||||
expect(result.model).toBe(firstAvailable);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseModelPattern version sorting", () => {
|
||||
it("selects the numerically highest version when aliases span double-digit minors", () => {
|
||||
const models = [
|
||||
model("anthropic", "claude-opus-4-9"),
|
||||
model("anthropic", "claude-opus-4-10"),
|
||||
model("anthropic", "claude-opus-4-11"),
|
||||
];
|
||||
const result = parseModelPattern("opus", models);
|
||||
expect(result.model?.id).toBe("claude-opus-4-11");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -116,11 +116,11 @@ function tryMatchModel(modelPattern: string, availableModels: Model[]): Model |
|
||||
|
||||
if (aliases.length > 0) {
|
||||
// Prefer alias - if multiple aliases, pick the one that sorts highest
|
||||
aliases.sort((a, b) => b.id.localeCompare(a.id));
|
||||
aliases.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true }));
|
||||
return aliases[0];
|
||||
}
|
||||
// No alias found, pick latest dated version
|
||||
datedVersions.sort((a, b) => b.id.localeCompare(a.id));
|
||||
datedVersions.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true }));
|
||||
return datedVersions[0];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user