Skip to content

Commit b53c609

Browse files
committed
fix(ui): stop discarding recently used models over a missing API key
The model picker pruned the stored list of recently used models down to whatever providers were resolvable at that moment, and saved the result. Since a provider configured through an environment variable is only visible when Crush is launched from a shell that exported it, opening the picker could permanently drop history for providers that were merely temporarily absent. Unresolvable entries are now skipped when drawing the list and left in the config. 💘 Generated with Crush
1 parent fb7abdc commit b53c609

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

internal/ui/dialog/models.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@ func (m *Models) setProviderItems() error {
454454
if len(recentItems) > 0 {
455455
recentGroup := NewModelGroup(t, "Recently used", false)
456456

457-
var validRecentItems []config.SelectedModel
457+
// Recents that cannot be resolved right now are skipped for
458+
// display but left in the config. Whether a provider is available
459+
// depends on the environment Crush happened to be launched from, so
460+
// pruning the stored list here would permanently discard history
461+
// over a temporarily missing API key. The list is already bounded
462+
// when entries are added.
458463
for _, recent := range recentItems {
459464
key := modelKey(recent.Provider, recent.Model)
460465
item, ok := itemsMap[key]
@@ -466,20 +471,12 @@ func (m *Models) setProviderItems() error {
466471
item = NewModelItem(t, item.prov, item.model, m.modelType, true)
467472
item.showProvider = true
468473

469-
validRecentItems = append(validRecentItems, recent)
470474
recentGroup.AppendItems(item)
471475
if recent.Model == currentModel.Model && recent.Provider == currentModel.Provider {
472476
selectedItemID = item.ID()
473477
}
474478
}
475479

476-
if len(validRecentItems) != len(recentItems) {
477-
// FIXME: Does this need to be here? Is it mutating the config during a read?
478-
if err := m.com.Workspace.SetConfigField(config.ScopeGlobal, fmt.Sprintf("recent_models.%s", selectedType), validRecentItems); err != nil {
479-
return fmt.Errorf("failed to update recent models: %w", err)
480-
}
481-
}
482-
483480
if len(recentGroup.Items) > 0 {
484481
groups = append([]ModelGroup{recentGroup}, groups...)
485482
}

0 commit comments

Comments
 (0)