mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 01:34:22 +01:00
Feat: Add F2 Keybind to Cycle Through the 5 Most Recent Models (#1778)
This commit is contained in:
committed by
GitHub
parent
8db75266d0
commit
73a8356b10
@@ -280,6 +280,39 @@ func (a *App) SwitchAgentReverse() (*App, tea.Cmd) {
|
|||||||
return a.cycleMode(false)
|
return a.cycleMode(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) CycleRecentModel() (*App, tea.Cmd) {
|
||||||
|
recentModels := a.State.RecentlyUsedModels
|
||||||
|
if len(recentModels) > 5 {
|
||||||
|
recentModels = recentModels[:5]
|
||||||
|
}
|
||||||
|
if len(recentModels) < 2 {
|
||||||
|
return a, toast.NewInfoToast("Need at least 2 recent models to cycle")
|
||||||
|
}
|
||||||
|
nextIndex := 0
|
||||||
|
for i, recentModel := range recentModels {
|
||||||
|
if a.Provider != nil && a.Model != nil && recentModel.ProviderID == a.Provider.ID && recentModel.ModelID == a.Model.ID {
|
||||||
|
nextIndex = (i + 1) % len(recentModels)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for range recentModels {
|
||||||
|
currentRecentModel := recentModels[nextIndex%len(recentModels)]
|
||||||
|
provider, model := findModelByProviderAndModelID(a.Providers, currentRecentModel.ProviderID, currentRecentModel.ModelID)
|
||||||
|
if provider != nil && model != nil {
|
||||||
|
a.Provider, a.Model = provider, model
|
||||||
|
a.State.AgentModel[a.Agent().Name] = AgentModel{ProviderID: provider.ID, ModelID: model.ID}
|
||||||
|
return a, tea.Sequence(a.SaveState(), toast.NewSuccessToast(fmt.Sprintf("Switched to %s (%s)", model.Name, provider.Name)))
|
||||||
|
}
|
||||||
|
recentModels = append(recentModels[:nextIndex%len(recentModels)], recentModels[nextIndex%len(recentModels)+1:]...)
|
||||||
|
if len(recentModels) < 2 {
|
||||||
|
a.State.RecentlyUsedModels = recentModels
|
||||||
|
return a, tea.Sequence(a.SaveState(), toast.NewInfoToast("Not enough valid recent models to cycle"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.State.RecentlyUsedModels = recentModels
|
||||||
|
return a, toast.NewErrorToast("Recent model not found")
|
||||||
|
}
|
||||||
|
|
||||||
// findModelByFullID finds a model by its full ID in the format "provider/model"
|
// findModelByFullID finds a model by its full ID in the format "provider/model"
|
||||||
func findModelByFullID(
|
func findModelByFullID(
|
||||||
providers []opencode.Provider,
|
providers []opencode.Provider,
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ const (
|
|||||||
ToolDetailsCommand CommandName = "tool_details"
|
ToolDetailsCommand CommandName = "tool_details"
|
||||||
ModelListCommand CommandName = "model_list"
|
ModelListCommand CommandName = "model_list"
|
||||||
AgentListCommand CommandName = "agent_list"
|
AgentListCommand CommandName = "agent_list"
|
||||||
|
ModelCycleRecentCommand CommandName = "model_cycle_recent"
|
||||||
ThemeListCommand CommandName = "theme_list"
|
ThemeListCommand CommandName = "theme_list"
|
||||||
FileListCommand CommandName = "file_list"
|
FileListCommand CommandName = "file_list"
|
||||||
FileCloseCommand CommandName = "file_close"
|
FileCloseCommand CommandName = "file_close"
|
||||||
@@ -256,6 +257,11 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
|||||||
Keybindings: parseBindings("<leader>a"),
|
Keybindings: parseBindings("<leader>a"),
|
||||||
Trigger: []string{"agents"},
|
Trigger: []string{"agents"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: ModelCycleRecentCommand,
|
||||||
|
Description: "cycle recent models",
|
||||||
|
Keybindings: parseBindings("f2"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: ThemeListCommand,
|
Name: ThemeListCommand,
|
||||||
Description: "list themes",
|
Description: "list themes",
|
||||||
|
|||||||
@@ -1148,6 +1148,11 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
|||||||
case commands.AgentListCommand:
|
case commands.AgentListCommand:
|
||||||
agentDialog := dialog.NewAgentDialog(a.app)
|
agentDialog := dialog.NewAgentDialog(a.app)
|
||||||
a.modal = agentDialog
|
a.modal = agentDialog
|
||||||
|
case commands.ModelCycleRecentCommand:
|
||||||
|
slog.Debug("ModelCycleRecentCommand triggered")
|
||||||
|
updated, cmd := a.app.CycleRecentModel()
|
||||||
|
a.app = updated
|
||||||
|
cmds = append(cmds, cmd)
|
||||||
case commands.ThemeListCommand:
|
case commands.ThemeListCommand:
|
||||||
themeDialog := dialog.NewThemeDialog()
|
themeDialog := dialog.NewThemeDialog()
|
||||||
a.modal = themeDialog
|
a.modal = themeDialog
|
||||||
|
|||||||
Reference in New Issue
Block a user