Просмотр исходного кода

tui: boost favorites and recents when filtering model dialog

When the user types a query in the model selection dialog, favorites
and recents previously lost all positional priority and were ranked
purely by fuzzysort score on title/category. Now matching favorites
float to the top, followed by matching recents, then everything else,
each group preserving fuzzysort order.
Kit Langton 1 день назад
Родитель
Сommit
054bcdca43
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

+ 11 - 1
packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

@@ -119,8 +119,18 @@ export function DialogModel(props: { providerID?: string }) {
       : []
 
     if (needle) {
+      const isFavorite = (v: { providerID: string; modelID: string }) =>
+        favorites.some((f) => f.providerID === v.providerID && f.modelID === v.modelID)
+      const isRecent = (v: { providerID: string; modelID: string }) =>
+        recents.some((r) => r.providerID === v.providerID && r.modelID === v.modelID)
+      const matches = fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj)
+      const fav = matches.filter((x) => isFavorite(x.value))
+      const rec = matches.filter((x) => !isFavorite(x.value) && isRecent(x.value))
+      const rest = matches.filter((x) => !isFavorite(x.value) && !isRecent(x.value))
       return [
-        ...fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj),
+        ...fav,
+        ...rec,
+        ...rest,
         ...fuzzysort.go(needle, popularProviders, { keys: ["title"] }).map((x) => x.obj),
       ]
     }