Skip to content

Commit d6efc3b

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 26f062e commit d6efc3b

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
@@ -448,7 +448,12 @@ func (m *Models) setProviderItems() error {
448448
if len(recentItems) > 0 {
449449
recentGroup := NewModelGroup(t, "Recently used", false)
450450

451-
var validRecentItems []config.SelectedModel
451+
// Recents that cannot be resolved right now are skipped for
452+
// display but left in the config. Whether a provider is available
453+
// depends on the environment Crush happened to be launched from, so
454+
// pruning the stored list here would permanently discard history
455+
// over a temporarily missing API key. The list is already bounded
456+
// when entries are added.
452457
for _, recent := range recentItems {
453458
key := modelKey(recent.Provider, recent.Model)
454459
item, ok := itemsMap[key]
@@ -460,20 +465,12 @@ func (m *Models) setProviderItems() error {
460465
item = NewModelItem(t, item.prov, item.model, m.modelType, true)
461466
item.showProvider = true
462467

463-
validRecentItems = append(validRecentItems, recent)
464468
recentGroup.AppendItems(item)
465469
if recent.Model == currentModel.Model && recent.Provider == currentModel.Provider {
466470
selectedItemID = item.ID()
467471
}
468472
}
469473

470-
if len(validRecentItems) != len(recentItems) {
471-
// FIXME: Does this need to be here? Is it mutating the config during a read?
472-
if err := m.com.Workspace.SetConfigField(config.ScopeGlobal, fmt.Sprintf("recent_models.%s", selectedType), validRecentItems); err != nil {
473-
return fmt.Errorf("failed to update recent models: %w", err)
474-
}
475-
}
476-
477474
if len(recentGroup.Items) > 0 {
478475
groups = append([]ModelGroup{recentGroup}, groups...)
479476
}

0 commit comments

Comments
 (0)