@@ -64,11 +64,6 @@ type openEditorMsg struct {
6464 Text string
6565}
6666
67−// listSessionsMsg is a message to list available sessions.
68−type listSessionsMsg struct {
69− sessions []session.Session
70−}
71−
7267// UI represents the main user interface model.
7368type UI struct {
7469 com *common.Common
@@ -190,10 +185,6 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
190185 if !m.sendProgressBar {
191186 m.sendProgressBar = slices.Contains(msg, "WT_SESSION")
192187 }
193− case listSessionsMsg:
194− if cmd := m.openSessionsDialog(msg.sessions); cmd != nil {
195− cmds = append(cmds, cmd)
196− }
197188 case loadSessionMsg:
198189 m.state = uiChat
199190 m.session = msg.session
@@ -499,11 +490,8 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
499490 }
500491 return true
501492 case key.Matches(msg, m.keyMap.Sessions):
502− if m.dialog.ContainsDialog(dialog.SessionsID) {
503− // Bring to front
504− m.dialog.BringToFront(dialog.SessionsID)
505− } else {
506− cmds = append(cmds, m.listSessions)
493+ if cmd := m.openSessionsDialog(); cmd != nil {
494+ cmds = append(cmds, cmd)
507495 }
508496 return true
509497 }
@@ -536,15 +524,30 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
536524 m.dialog.CloseDialog(dialog.SessionsID)
537525 cmds = append(cmds, m.loadSession(msg.Session.ID))
538526
527+ // Open dialog message
528+ case dialog.OpenDialogMsg:
529+ switch msg.DialogID {
530+ case dialog.SessionsID:
531+ if cmd := m.openSessionsDialog(); cmd != nil {
532+ cmds = append(cmds, cmd)
533+ }
534+ case dialog.ModelsID:
535+ if cmd := m.openModelsDialog(); cmd != nil {
536+ cmds = append(cmds, cmd)
537+ }
538+ default:
539+ // Unknown dialog
540+ break
541+ }
542+
543+ m.dialog.CloseDialog(msg.DialogID)
544+
539545 // Command dialog messages
540546 case dialog.ToggleYoloModeMsg:
541547 yolo := !m.com.App.Permissions.SkipRequests()
542548 m.com.App.Permissions.SetSkipRequests(yolo)
543549 m.setEditorPrompt(yolo)
544550 m.dialog.CloseDialog(dialog.CommandsID)
545− case dialog.SwitchSessionsMsg:
546− cmds = append(cmds, m.listSessions)
547− m.dialog.CloseDialog(dialog.CommandsID)
548551 case dialog.NewSessionsMsg:
549552 if m.com.App.AgentCoordinator != nil && m.com.App.AgentCoordinator.IsBusy() {
550553 cmds = append(cmds, uiutil.ReportWarn("Agent is busy, please wait before starting a new session..."))
@@ -562,11 +565,6 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
562565 m.dialog.CloseDialog(dialog.CommandsID)
563566 case dialog.QuitMsg:
564567 cmds = append(cmds, tea.Quit)
565− case dialog.SwitchModelMsg:
566− m.dialog.CloseDialog(dialog.CommandsID)
567− if cmd := m.openModelsDialog(); cmd != nil {
568− cmds = append(cmds, cmd)
569− }
570568 case dialog.ModelSelectedMsg:
571569 // TODO: Handle model switching
572570 }
@@ -1428,14 +1426,21 @@ func (m *UI) openCommandsDialog() tea.Cmd {
14281426 return nil
14291427}
14301428
1431−// openSessionsDialog opens the sessions dialog with the given sessions.
1432−func (m *UI) openSessionsDialog(sessions []session.Session) tea.Cmd {
1429+// openSessionsDialog opens the sessions dialog. If the dialog is already open,
1430+// it brings it to the front. Otherwise, it will list all the sessions and open
1431+// the dialog.
1432+func (m *UI) openSessionsDialog() tea.Cmd {
14331433 if m.dialog.ContainsDialog(dialog.SessionsID) {
14341434 // Bring to front
14351435 m.dialog.BringToFront(dialog.SessionsID)
14361436 return nil
14371437 }
14381438
1439+ sessions, err := m.com.App.Sessions.List(context.TODO())
1440+ if err != nil {
1441+ return uiutil.ReportError(err)
1442+ }
1443+
14391444 dialog := dialog.NewSessions(m.com, sessions...)
14401445 // TODO: Get. Rid. Of. Magic numbers!
14411446 dialog.SetSize(min(120, m.width-8), 30)
@@ -1444,13 +1449,6 @@ func (m *UI) openSessionsDialog(sessions []session.Session) tea.Cmd {
14441449 return nil
14451450}
14461451
1447−// listSessions is a [tea.Cmd] that lists all sessions and returns them in a
1448−// [listSessionsMsg].
1449−func (m *UI) listSessions() tea.Msg {
1450− allSessions, _ := m.com.App.Sessions.List(context.TODO())
1451− return listSessionsMsg{sessions: allSessions}
1452−}
1453−
14541452// newSession clears the current session state and prepares for a new session.
14551453// The actual session creation happens when the user sends their first message.
14561454func (m *UI) newSession() {