MCPcopy
hub / github.com/kagent-dev/kagent / Update

Method Update

go/core/cli/internal/tui/workspace.go:189–434  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

187}
188
189func (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()

Callers 1

resizeMethod · 0.45

Calls 14

resizeMethod · 0.95
renderDetailsMethod · 0.95
loadSessionsMethod · 0.95
startChatMethod · 0.95
loadAgentsMethod · 0.95
createSessionMethod · 0.95
sortSessionsFunction · 0.85
HasDialogsMethod · 0.80
HeightMethod · 0.80
SetInputVisibleMethod · 0.80
HandleMethod · 0.45
appendEventMethod · 0.45

Tested by

no test coverage detected