tui: Error handling tweak
Moved errors to bottom of screen, fix infinite loop by typing errors properly
This commit is contained in:
@@ -25,11 +25,13 @@ type (
|
||||
}
|
||||
// sent when a conversation's messages are laoded
|
||||
msgConversationMessagesLoaded struct {
|
||||
messages []api.Message
|
||||
messages []api.Message
|
||||
rootMessages []api.Message
|
||||
}
|
||||
// a special case of common.MsgError that stops the response waiting animation
|
||||
msgChatResponseError error
|
||||
msgChatResponseError struct {
|
||||
Err error
|
||||
}
|
||||
// sent on each chunk received from LLM
|
||||
msgChatResponseChunk api.Chunk
|
||||
// sent on each completed reply
|
||||
@@ -72,9 +74,9 @@ const (
|
||||
|
||||
type Model struct {
|
||||
// App state
|
||||
App *model.AppModel
|
||||
App *model.AppModel
|
||||
Height int
|
||||
Width int
|
||||
Width int
|
||||
|
||||
// Chat view state
|
||||
state state // current overall status of the view
|
||||
@@ -108,8 +110,8 @@ func Chat(app *model.AppModel) *Model {
|
||||
m := Model{
|
||||
App: app,
|
||||
|
||||
state: idle,
|
||||
persistence: true,
|
||||
state: idle,
|
||||
persistence: true,
|
||||
|
||||
stopSignal: make(chan struct{}),
|
||||
replyChan: make(chan api.Message),
|
||||
|
||||
@@ -19,11 +19,11 @@ func (m *Model) loadConversationMessages() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
messages, err := m.App.LoadConversationMessages()
|
||||
if err != nil {
|
||||
return shared.MsgError(err)
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
rootMessages, err := m.App.LoadConversationRootMessages()
|
||||
if err != nil {
|
||||
return shared.MsgError(err)
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
return msgConversationMessagesLoaded{
|
||||
messages, rootMessages,
|
||||
@@ -35,7 +35,7 @@ func (m *Model) generateConversationTitle() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
title, err := m.App.GenerateConversationTitle(m.App.Messages)
|
||||
if err != nil {
|
||||
return shared.MsgError(err)
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
return msgConversationTitleGenerated(title)
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func (m *Model) persistConversation() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
conversation, messages, err := m.App.PersistConversation(m.App.Conversation, m.App.Messages)
|
||||
if err != nil {
|
||||
return shared.MsgError(err)
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
return msgConversationPersisted{conversation.ID == 0, conversation, messages}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (m *Model) executeToolCalls(toolCalls []api.ToolCall) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
results, err := m.App.ExecuteToolCalls(toolCalls)
|
||||
if err != nil {
|
||||
return shared.MsgError(err)
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
return msgToolResults(results)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func (m *Model) promptLLM() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
resp, err := m.App.PromptLLM(m.App.Messages, m.chatReplyChunks, m.stopSignal)
|
||||
if err != nil {
|
||||
return msgChatResponseError(err)
|
||||
return msgChatResponseError{ Err: err }
|
||||
}
|
||||
return msgChatResponse(resp)
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (m *Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) {
|
||||
case msgChatResponseError:
|
||||
m.state = idle
|
||||
m.updateContent()
|
||||
return m, shared.WrapError(msg)
|
||||
return m, shared.WrapError(msg.Err)
|
||||
case msgToolResults:
|
||||
last := len(m.App.Messages) - 1
|
||||
if last < 0 {
|
||||
|
||||
Reference in New Issue
Block a user