on main help sign in
fix: fix panic that can happen on sending a message (#817)
d86f739Andrey Nering
internal/tui/page/chat/chat.go+8−2
@@ -2,6 +2,7 @@ package chat
2
2
3import (
3import (
4 "context"
4 "context"
5+ "fmt"
5 "time"
6 "time"
6
7
7 "github.com/charmbracelet/bubbles/v2/help"
8 "github.com/charmbracelet/bubbles/v2/help"
@@ -649,7 +650,9 @@ func (p *chatPage) changeFocus() {
649func (p *chatPage) cancel() tea.Cmd {
650func (p *chatPage) cancel() tea.Cmd {
650 if p.isCanceling {
651 if p.isCanceling {
651 p.isCanceling = false
652 p.isCanceling = false
653+ if p.app.CoderAgent != nil {
652− p.app.CoderAgent.Cancel(p.session.ID)
654+ p.app.CoderAgent.Cancel(p.session.ID)
655+ }
653 return nil
656 return nil
654 }
657 }
655
658
@@ -687,6 +690,9 @@ func (p *chatPage) sendMessage(text string, attachments []message.Attachment) te
687 session = newSession
690 session = newSession
688 cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(session)))
691 cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(session)))
689 }
692 }
693+ if p.app.CoderAgent == nil {
694+ return util.ReportError(fmt.Errorf("coder agent is not initialized - please check your configuration"))
695+ }
690 _, err := p.app.CoderAgent.Run(context.Background(), session.ID, text, attachments...)
696 _, err := p.app.CoderAgent.Run(context.Background(), session.ID, text, attachments...)
691 if err != nil {
697 if err != nil {
692 return util.ReportError(err)
698 return util.ReportError(err)
@@ -832,7 +838,7 @@ func (p *chatPage) Help() help.KeyMap {
832 key.WithHelp("esc", "press again to cancel"),
838 key.WithHelp("esc", "press again to cancel"),
833 )
839 )
834 }
840 }
835− if p.app.CoderAgent.QueuedPrompts(p.session.ID) > 0 {
841+ if p.app.CoderAgent != nil && p.app.CoderAgent.QueuedPrompts(p.session.ID) > 0 {
836 cancelBinding = key.NewBinding(
842 cancelBinding = key.NewBinding(
837 key.WithKeys("esc"),
843 key.WithKeys("esc"),
838 key.WithHelp("esc", "clear queue"),
844 key.WithHelp("esc", "clear queue"),