(msg tea.Msg)
| 187 | } |
| 188 | |
| 189 | func (m *workspaceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 190 | // Forward to dialog manager first; if a dialog is open, it captures input |
| 191 | dcmd := m.dlg.Handle(msg) |
| 192 | if m.dlg.HasDialogs() { |
| 193 | // Only allow WindowSizeMsg to continue to adjust layout beneath |
| 194 | if _, ok := msg.(tea.WindowSizeMsg); !ok { |
| 195 | return m, dcmd |
| 196 | } |
| 197 | } |
| 198 | switch msg := msg.(type) { |
| 199 | case tea.WindowSizeMsg: |
| 200 | m.width, m.height = msg.Width, msg.Height |
| 201 | if m.choosingAgent { |
| 202 | m.agentList.SetSize(max(20, m.width/2), max(10, m.height/2)) |
| 203 | } |
| 204 | if m.naming { |
| 205 | m.sessionInput.Width = max(10, m.width/2-4) |
| 206 | } |
| 207 | return m, m.resize() |
| 208 | case agentChosenMsg: |
| 209 | a := msg.agent |
| 210 | m.agent = &a |
| 211 | m.agentRef = utils.ConvertToKubernetesIdentifier(a.ID) |
| 212 | // Clear current session and chat when switching agents |
| 213 | m.current = nil |
| 214 | m.chat = nil |
| 215 | m.focus = focusSessions |
| 216 | m.renderDetails() |
| 217 | return m, m.loadSessions() |
| 218 | case wsAgentsLoadedMsg: |
| 219 | if msg.err != nil { |
| 220 | fmt.Fprintf(&m.details, "Error: failed to load agents: %v", msg.err) |
| 221 | return m, nil |
| 222 | } |
| 223 | // Sort and store agents for later; do not auto-open chooser or auto-select. |
| 224 | slices.SortStableFunc(msg.agents, func(a, b api.AgentResponse) int { |
| 225 | return strings.Compare( |
| 226 | utils.ResourceRefString(a.Agent.Metadata.Namespace, a.Agent.Metadata.Name), |
| 227 | utils.ResourceRefString(b.Agent.Metadata.Namespace, b.Agent.Metadata.Name), |
| 228 | ) |
| 229 | }) |
| 230 | m.agents = msg.agents |
| 231 | // Keep welcome screen visible until user presses Ctrl+A |
| 232 | return m, nil |
| 233 | case loadAgentMsg: |
| 234 | if msg.err != nil { |
| 235 | fmt.Fprintf(&m.details, "Error: %v", msg.err) |
| 236 | return m, nil |
| 237 | } |
| 238 | a := msg.agent |
| 239 | m.agent = &a |
| 240 | m.agentRef = utils.ConvertToKubernetesIdentifier(a.ID) |
| 241 | // Clear current session and chat when switching agents |
| 242 | m.current = nil |
| 243 | m.chat = nil |
| 244 | m.focus = focusSessions |
| 245 | m.renderDetails() |
| 246 | return m, m.loadSessions() |
no test coverage detected