Skip to content

Commit c416ede

Browse files
authored
fix(tui): sort model picker by release date (#33558)
1 parent 784eea3 commit c416ede

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

packages/tui/src/component/dialog-model.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ export function DialogModel(props: { providerID?: string }) {
118118

119119
if (needle) {
120120
return [
121-
...fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj),
121+
...sortModelOptions(
122+
fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj),
123+
false,
124+
),
122125
...fuzzysort.go(needle, popularProviders, { keys: ["title"] }).map((x) => x.obj),
123126
]
124127
}
@@ -188,6 +191,7 @@ export function sortModelOptions<T extends { footer?: string; releaseDate: strin
188191
return sortBy(
189192
options,
190193
(option) => option.footer !== "Free",
194+
[(option) => option.releaseDate, "desc"],
191195
(option) => option.title,
192196
)
193197
}

packages/tui/test/cli/cmd/tui/model-options.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ describe("sortModelOptions", () => {
1515
expect(sorted.map((model) => model.title)).toEqual(["GPT 5.4", "GPT 5.2", "GPT 5.1"])
1616
})
1717

18-
test("preserves free-first alphabetical ordering for the regular picker", () => {
18+
test("orders regular model choices free-first and then newest-first", () => {
1919
const sorted = sortModelOptions(
2020
[
21-
{ title: "Beta", releaseDate: "2026-01-01" },
22-
{ title: "Alpha", releaseDate: "2025-01-01", footer: "Free" },
23-
{ title: "Gamma", releaseDate: "2024-01-01", footer: "Free" },
21+
{ title: "GLM 5", releaseDate: "2025-07-28" },
22+
{ title: "GLM 5.1", releaseDate: "2025-12-09" },
23+
{ title: "GLM 5.2", releaseDate: "2026-02-16" },
24+
{ title: "Free old", releaseDate: "2024-01-01", footer: "Free" },
25+
{ title: "Free new", releaseDate: "2025-01-01", footer: "Free" },
2426
],
2527
false,
2628
)
2729

28-
expect(sorted.map((model) => model.title)).toEqual(["Alpha", "Gamma", "Beta"])
30+
expect(sorted.map((model) => model.title)).toEqual(["Free new", "Free old", "GLM 5.2", "GLM 5.1", "GLM 5"])
2931
})
3032
})

0 commit comments

Comments
 (0)