on main help sign in
fix(ui): dialog: show provider name for recent models
commit82eafde6a9ce0b10ea44c3b54ee0ba6b01b9bf4f authorAyman Bagabas <ayman.bagabas@gmail.com> dateThu 18 Dec 2025, 16:33 (1 year ago) parent179e17f
3 files changed+57−43
internal/ui/dialog/models.go+7−2 internal/ui/dialog/models_item.go+24−13 internal/ui/dialog/models_list.go+26−28
internal/ui/dialog/models.go+7−2
@@ -314,7 +314,7 @@ func (m *Models) setProviderItems() error {
314314
315315 group := NewModelGroup(t, name, true)
316316 for _, model := range p.Models {
317− item := NewModelItem(t, provider, model)
317+ item := NewModelItem(t, provider, model, false)
318318 group.AppendItems(item)
319319 itemsMap[item.ID()] = item
320320 if model.ID == currentModel.Model && string(provider.ID) == currentModel.Provider {
@@ -368,7 +368,7 @@ func (m *Models) setProviderItems() error {
368368
369369 group := NewModelGroup(t, name, providerConfigured)
370370 for _, model := range displayProvider.Models {
371− item := NewModelItem(t, provider, model)
371+ item := NewModelItem(t, provider, model, false)
372372 group.AppendItems(item)
373373 itemsMap[item.ID()] = item
374374 if model.ID == currentModel.Model && string(provider.ID) == currentModel.Provider {
@@ -390,6 +390,10 @@ func (m *Models) setProviderItems() error {
390390 continue
391391 }
392392
393+ // Show provider for recent items
394+ item = NewModelItem(t, item.prov, item.model, true)
395+ item.showProvider = true
396+
393397 validRecentItems = append(validRecentItems, recent)
394398 recentGroup.AppendItems(item)
395399 if recent.Model == currentModel.Model && recent.Provider == currentModel.Provider {
@@ -412,6 +416,7 @@ func (m *Models) setProviderItems() error {
412416 // Set model groups in the list.
413417 m.list.SetGroups(groups...)
414418 m.list.SetSelectedItem(selectedItemID)
419+
415420 // Update placeholder based on model type
416421 if m.modelType == ModelTypeLarge {
417422 m.input.Placeholder = largeModelInputPlaceholder
internal/ui/dialog/models_item.go+24−13
@@ -20,9 +20,10 @@ type ModelGroup struct {
2020// NewModelGroup creates a new ModelGroup.
2121func NewModelGroup(t *styles.Styles, title string, configured bool, items ...*ModelItem) ModelGroup {
2222 return ModelGroup{
23− Title: title,
24− Items: items,
25− t: t,
23+ Title: title,
24+ Items: items,
25+ configured: configured,
26+ t: t,
2627 }
2728}
2829
@@ -51,21 +52,23 @@ type ModelItem struct {
5152 prov catwalk.Provider
5253 model catwalk.Model
5354
54− cache map[int]string
55− t *styles.Styles
56− m fuzzy.Match
57− focused bool
55+ cache map[int]string
56+ t *styles.Styles
57+ m fuzzy.Match
58+ focused bool
59+ showProvider bool
5860}
5961
6062var _ ListItem = &ModelItem{}
6163
6264// NewModelItem creates a new ModelItem.
63−func NewModelItem(t *styles.Styles, prov catwalk.Provider, model catwalk.Model) *ModelItem {
65+func NewModelItem(t *styles.Styles, prov catwalk.Provider, model catwalk.Model, showProvider bool) *ModelItem {
6466 return &ModelItem{
65− prov: prov,
66− model: model,
67− t: t,
68− cache: make(map[int]string),
67+ prov: prov,
68+ model: model,
69+ t: t,
70+ cache: make(map[int]string),
71+ showProvider: showProvider,
6972 }
7073}
7174
@@ -81,15 +84,23 @@ func (m *ModelItem) ID() string {
8184
8285// Render implements ListItem.
8386func (m *ModelItem) Render(width int) string {
84− return renderItem(m.t, m.model.Name, "", m.focused, width, m.cache, &m.m)
87+ var providerInfo string
88+ if m.showProvider {
89+ providerInfo = string(m.prov.Name)
90+ }
91+ return renderItem(m.t, m.model.Name, providerInfo, m.focused, width, m.cache, &m.m)
8592}
8693
8794// SetFocused implements ListItem.
8895func (m *ModelItem) SetFocused(focused bool) {
96+ if m.focused != focused {
97+ m.cache = nil
98+ }
8999 m.focused = focused
90100}
91101
92102// SetMatch implements ListItem.
93103func (m *ModelItem) SetMatch(fm fuzzy.Match) {
104+ m.cache = nil
94105 m.m = fm
95106}
internal/ui/dialog/models_list.go+26−28
@@ -12,7 +12,6 @@ import (
1212type ModelsList struct {
1313 *list.List
1414 groups []ModelGroup
15− items []list.Item
1615 query string
1716 t *styles.Styles
1817}
@@ -30,6 +29,16 @@ func NewModelsList(sty *styles.Styles, groups ...ModelGroup) *ModelsList {
3029// SetGroups sets the model groups and updates the list items.
3130func (f *ModelsList) SetGroups(groups ...ModelGroup) {
3231 f.groups = groups
32+ items := []list.Item{}
33+ for _, g := range f.groups {
34+ items = append(items, &g)
35+ for _, item := range g.Items {
36+ items = append(items, item)
37+ }
38+ // Add a space separator after each provider section
39+ items = append(items, list.NewSpacerItem(1))
40+ }
41+ f.List.SetItems(items...)
3342}
3443
3544// SetFilter sets the filter query and updates the list items.
@@ -39,6 +48,11 @@ func (f *ModelsList) SetFilter(q string) {
3948
4049// SetSelectedItem sets the selected item in the list by item ID.
4150func (f *ModelsList) SetSelectedItem(itemID string) {
51+ if itemID == "" {
52+ f.SetSelected(0)
53+ return
54+ }
55+
4256 count := 0
4357 for _, g := range f.groups {
4458 for _, item := range g.Items {
@@ -51,26 +65,6 @@ func (f *ModelsList) SetSelectedItem(itemID string) {
5165 }
5266}
5367
54−// SelectNext selects the next selectable item in the list.
55−func (f *ModelsList) SelectNext() bool {
56− for f.List.SelectNext() {
57− if _, ok := f.List.SelectedItem().(*ModelItem); ok {
58− return true
59− }
60− }
61− return false
62−}
63−
64−// SelectPrev selects the previous selectable item in the list.
65−func (f *ModelsList) SelectPrev() bool {
66− for f.List.SelectPrev() {
67− if _, ok := f.List.SelectedItem().(*ModelItem); ok {
68− return true
69− }
70− }
71− return false
72−}
73−
7468// VisibleItems returns the visible items after filtering.
7569func (f *ModelsList) VisibleItems() []list.Item {
7670 if len(f.query) == 0 {
@@ -110,10 +104,11 @@ func (f *ModelsList) VisibleItems() []list.Item {
110104 visitedGroups := map[int]bool{}
111105
112106 // Reconstruct groups with matched items
113− for _, match := range matches {
114− item := filterableItems[match.Index]
115− // Find which group this item belongs to
116− for gi, g := range f.groups {
107+ // Find which group this item belongs to
108+ for gi, g := range f.groups {
109+ addedCount := 0
110+ for _, match := range matches {
111+ item := filterableItems[match.Index]
117112 if slices.Contains(groupItems[gi], item.(*ModelItem)) {
118113 if !visitedGroups[gi] {
119114 // Add section header
@@ -125,11 +120,14 @@ func (f *ModelsList) VisibleItems() []list.Item {
125120 ms.SetMatch(match)
126121 item = ms.(list.FilterableItem)
127122 }
128− // Add a space separator after each provider section
129− items = append(items, item, list.NewSpacerItem(1))
130− break
123+ items = append(items, item)
124+ addedCount++
131125 }
132126 }
127+ if addedCount > 0 {
128+ // Add a space separator after each provider section
129+ items = append(items, list.NewSpacerItem(1))
130+ }
133131 }
134132
135133 return items