on main help sign in
fix(ui): dialog: show provider name for recent models
82eafdeAyman Bagabas
internal/ui/dialog/models.go+7−2
@@ -314,7 +314,7 @@ func (m *Models) setProviderItems() error {
314
314
315 group := NewModelGroup(t, name, true)
315 group := NewModelGroup(t, name, true)
316 for _, model := range p.Models {
316 for _, model := range p.Models {
317− item := NewModelItem(t, provider, model)
317+ item := NewModelItem(t, provider, model, false)
318 group.AppendItems(item)
318 group.AppendItems(item)
319 itemsMap[item.ID()] = item
319 itemsMap[item.ID()] = item
320 if model.ID == currentModel.Model && string(provider.ID) == currentModel.Provider {
320 if model.ID == currentModel.Model && string(provider.ID) == currentModel.Provider {
@@ -368,7 +368,7 @@ func (m *Models) setProviderItems() error {
368
368
369 group := NewModelGroup(t, name, providerConfigured)
369 group := NewModelGroup(t, name, providerConfigured)
370 for _, model := range displayProvider.Models {
370 for _, model := range displayProvider.Models {
371− item := NewModelItem(t, provider, model)
371+ item := NewModelItem(t, provider, model, false)
372 group.AppendItems(item)
372 group.AppendItems(item)
373 itemsMap[item.ID()] = item
373 itemsMap[item.ID()] = item
374 if model.ID == currentModel.Model && string(provider.ID) == currentModel.Provider {
374 if model.ID == currentModel.Model && string(provider.ID) == currentModel.Provider {
@@ -390,6 +390,10 @@ func (m *Models) setProviderItems() error {
390 continue
390 continue
391 }
391 }
392
392
393+ // Show provider for recent items
394+ item = NewModelItem(t, item.prov, item.model, true)
395+ item.showProvider = true
396+
393 validRecentItems = append(validRecentItems, recent)
397 validRecentItems = append(validRecentItems, recent)
394 recentGroup.AppendItems(item)
398 recentGroup.AppendItems(item)
395 if recent.Model == currentModel.Model && recent.Provider == currentModel.Provider {
399 if recent.Model == currentModel.Model && recent.Provider == currentModel.Provider {
@@ -412,6 +416,7 @@ func (m *Models) setProviderItems() error {
412 // Set model groups in the list.
416 // Set model groups in the list.
413 m.list.SetGroups(groups...)
417 m.list.SetGroups(groups...)
414 m.list.SetSelectedItem(selectedItemID)
418 m.list.SetSelectedItem(selectedItemID)
419+
415 // Update placeholder based on model type
420 // Update placeholder based on model type
416 if m.modelType == ModelTypeLarge {
421 if m.modelType == ModelTypeLarge {
417 m.input.Placeholder = largeModelInputPlaceholder
422 m.input.Placeholder = largeModelInputPlaceholder
internal/ui/dialog/models_item.go+24−13
@@ -20,9 +20,10 @@ type ModelGroup struct {
20// NewModelGroup creates a new ModelGroup.
20// NewModelGroup creates a new ModelGroup.
21func NewModelGroup(t *styles.Styles, title string, configured bool, items ...*ModelItem) ModelGroup {
21func NewModelGroup(t *styles.Styles, title string, configured bool, items ...*ModelItem) ModelGroup {
22 return ModelGroup{
22 return ModelGroup{
23− Title: title,
23+ Title: title,
24− Items: items,
24+ Items: items,
25+ configured: configured,
25− t: t,
26+ t: t,
26 }
27 }
27}
28}
28
29
@@ -51,21 +52,23 @@ type ModelItem struct {
51 prov catwalk.Provider
52 prov catwalk.Provider
52 model catwalk.Model
53 model catwalk.Model
53
54
54− cache map[int]string
55+ cache map[int]string
55− t *styles.Styles
56+ t *styles.Styles
56− m fuzzy.Match
57+ m fuzzy.Match
57− focused bool
58+ focused bool
59+ showProvider bool
58}
60}
59
61
60var _ ListItem = &ModelItem{}
62var _ ListItem = &ModelItem{}
61
63
62// NewModelItem creates a new ModelItem.
64// 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 {
64 return &ModelItem{
66 return &ModelItem{
65− prov: prov,
67+ prov: prov,
66− model: model,
68+ model: model,
67− t: t,
69+ t: t,
68− cache: make(map[int]string),
70+ cache: make(map[int]string),
71+ showProvider: showProvider,
69 }
72 }
70}
73}
71
74
@@ -81,15 +84,23 @@ func (m *ModelItem) ID() string {
81
84
82// Render implements ListItem.
85// Render implements ListItem.
83func (m *ModelItem) Render(width int) string {
86func (m *ModelItem) Render(width int) string {
87+ var providerInfo string
88+ if m.showProvider {
89+ providerInfo = string(m.prov.Name)
90+ }
84− return renderItem(m.t, m.model.Name, "", m.focused, width, m.cache, &m.m)
91+ return renderItem(m.t, m.model.Name, providerInfo, m.focused, width, m.cache, &m.m)
85}
92}
86
93
87// SetFocused implements ListItem.
94// SetFocused implements ListItem.
88func (m *ModelItem) SetFocused(focused bool) {
95func (m *ModelItem) SetFocused(focused bool) {
96+ if m.focused != focused {
97+ m.cache = nil
98+ }
89 m.focused = focused
99 m.focused = focused
90}
100}
91
101
92// SetMatch implements ListItem.
102// SetMatch implements ListItem.
93func (m *ModelItem) SetMatch(fm fuzzy.Match) {
103func (m *ModelItem) SetMatch(fm fuzzy.Match) {
104+ m.cache = nil
94 m.m = fm
105 m.m = fm
95}
106}
internal/ui/dialog/models_list.go+26−28
@@ -12,7 +12,6 @@ import (
12type ModelsList struct {
12type ModelsList struct {
13 *list.List
13 *list.List
14 groups []ModelGroup
14 groups []ModelGroup
15− items []list.Item
16 query string
15 query string
17 t *styles.Styles
16 t *styles.Styles
18}
17}
@@ -30,6 +29,16 @@ func NewModelsList(sty *styles.Styles, groups ...ModelGroup) *ModelsList {
30// SetGroups sets the model groups and updates the list items.
29// SetGroups sets the model groups and updates the list items.
31func (f *ModelsList) SetGroups(groups ...ModelGroup) {
30func (f *ModelsList) SetGroups(groups ...ModelGroup) {
32 f.groups = groups
31 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...)
33}
42}
34
43
35// SetFilter sets the filter query and updates the list items.
44// SetFilter sets the filter query and updates the list items.
@@ -39,6 +48,11 @@ func (f *ModelsList) SetFilter(q string) {
39
48
40// SetSelectedItem sets the selected item in the list by item ID.
49// SetSelectedItem sets the selected item in the list by item ID.
41func (f *ModelsList) SetSelectedItem(itemID string) {
50func (f *ModelsList) SetSelectedItem(itemID string) {
51+ if itemID == "" {
52+ f.SetSelected(0)
53+ return
54+ }
55+
42 count := 0
56 count := 0
43 for _, g := range f.groups {
57 for _, g := range f.groups {
44 for _, item := range g.Items {
58 for _, item := range g.Items {
@@ -51,26 +65,6 @@ func (f *ModelsList) SetSelectedItem(itemID string) {
51 }
65 }
52}
66}
53
67
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−
74// VisibleItems returns the visible items after filtering.
68// VisibleItems returns the visible items after filtering.
75func (f *ModelsList) VisibleItems() []list.Item {
69func (f *ModelsList) VisibleItems() []list.Item {
76 if len(f.query) == 0 {
70 if len(f.query) == 0 {
@@ -110,10 +104,11 @@ func (f *ModelsList) VisibleItems() []list.Item {
110 visitedGroups := map[int]bool{}
104 visitedGroups := map[int]bool{}
111
105
112 // Reconstruct groups with matched items
106 // Reconstruct groups with matched items
113− for _, match := range matches {
114− item := filterableItems[match.Index]
115− // Find which group this item belongs to
107+ // Find which group this item belongs to
116− for gi, g := range f.groups {
108+ for gi, g := range f.groups {
109+ addedCount := 0
110+ for _, match := range matches {
111+ item := filterableItems[match.Index]
117 if slices.Contains(groupItems[gi], item.(*ModelItem)) {
112 if slices.Contains(groupItems[gi], item.(*ModelItem)) {
118 if !visitedGroups[gi] {
113 if !visitedGroups[gi] {
119 // Add section header
114 // Add section header
@@ -125,11 +120,14 @@ func (f *ModelsList) VisibleItems() []list.Item {
125 ms.SetMatch(match)
120 ms.SetMatch(match)
126 item = ms.(list.FilterableItem)
121 item = ms.(list.FilterableItem)
127 }
122 }
128− // Add a space separator after each provider section
129− items = append(items, item, list.NewSpacerItem(1))
123+ items = append(items, item)
130− break
124+ addedCount++
131 }
125 }
132 }
126 }
127+ if addedCount > 0 {
128+ // Add a space separator after each provider section
129+ items = append(items, list.NewSpacerItem(1))
130+ }
133 }
131 }
134
132
135 return items
133 return items