Fixed message loading

Root messages weren't being loaded since the refactor, and there was
dead code
This commit is contained in:
Matt Low 2024-09-21 02:32:54 +00:00
parent 463ca9ef40
commit a488ec4fd8
4 changed files with 22 additions and 16 deletions

View File

@ -47,6 +47,14 @@ func (m *AppModel) LoadConversations() (error, []LoadedConversation) {
return nil, conversations
}
func (a *AppModel) LoadConversationRootMessages() ([]api.Message, error) {
messages, err := a.Ctx.Store.RootMessages(a.Conversation.ID)
if err != nil {
return nil, fmt.Errorf("Could not load conversation root messages: %v %v", a.Conversation.SelectedRoot, err)
}
return messages, nil
}
func (a *AppModel) LoadConversationMessages() ([]api.Message, error) {
messages, err := a.Ctx.Store.PathToLeaf(a.Conversation.SelectedRoot)
if err != nil {

View File

@ -16,11 +16,6 @@ import (
// custom tea.Msg types
type (
// sent when a conversation is (re)loaded
msgConversationLoaded struct {
conversation *api.Conversation
rootMessages []api.Message
}
// sent when a new conversation title generated
msgConversationTitleGenerated string
// sent when the conversation has been persisted, triggers a reload of contents
@ -30,7 +25,10 @@ type (
messages []api.Message
}
// sent when a conversation's messages are laoded
msgMessagesLoaded []api.Message
msgConversationMessagesLoaded struct {
messages []api.Message
rootMessages []api.Message
}
// a special case of common.MsgError that stops the response waiting animation
msgChatResponseError error
// sent on each chunk received from LLM

View File

@ -21,7 +21,13 @@ func (m *Model) loadConversationMessages() tea.Cmd {
if err != nil {
return shared.MsgError(err)
}
return msgMessagesLoaded(messages)
rootMessages, err := m.App.LoadConversationRootMessages()
if err != nil {
return shared.MsgError(err)
}
return msgConversationMessagesLoaded{
messages, rootMessages,
}
}
}

View File

@ -94,17 +94,11 @@ func (m Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) {
}
}
}
case msgConversationLoaded:
m.App.Conversation = msg.conversation
case msgConversationMessagesLoaded:
m.App.RootMessages = msg.rootMessages
m.selectedMessage = -1
if len(m.App.RootMessages) > 0 {
cmds = append(cmds, m.loadConversationMessages())
}
case msgMessagesLoaded:
m.App.Messages = msg
m.App.Messages = msg.messages
if m.selectedMessage == -1 {
m.selectedMessage = len(msg) - 1
m.selectedMessage = len(msg.messages) - 1
} else {
m.selectedMessage = min(m.selectedMessage, len(m.App.Messages))
}