Fixed message loading
Root messages weren't being loaded since the refactor, and there was dead code
This commit is contained in:
parent
463ca9ef40
commit
a488ec4fd8
@ -47,6 +47,14 @@ func (m *AppModel) LoadConversations() (error, []LoadedConversation) {
|
|||||||
return nil, conversations
|
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) {
|
func (a *AppModel) LoadConversationMessages() ([]api.Message, error) {
|
||||||
messages, err := a.Ctx.Store.PathToLeaf(a.Conversation.SelectedRoot)
|
messages, err := a.Ctx.Store.PathToLeaf(a.Conversation.SelectedRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,11 +16,6 @@ import (
|
|||||||
|
|
||||||
// custom tea.Msg types
|
// custom tea.Msg types
|
||||||
type (
|
type (
|
||||||
// sent when a conversation is (re)loaded
|
|
||||||
msgConversationLoaded struct {
|
|
||||||
conversation *api.Conversation
|
|
||||||
rootMessages []api.Message
|
|
||||||
}
|
|
||||||
// sent when a new conversation title generated
|
// sent when a new conversation title generated
|
||||||
msgConversationTitleGenerated string
|
msgConversationTitleGenerated string
|
||||||
// sent when the conversation has been persisted, triggers a reload of contents
|
// sent when the conversation has been persisted, triggers a reload of contents
|
||||||
@ -30,7 +25,10 @@ type (
|
|||||||
messages []api.Message
|
messages []api.Message
|
||||||
}
|
}
|
||||||
// sent when a conversation's messages are laoded
|
// 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
|
// a special case of common.MsgError that stops the response waiting animation
|
||||||
msgChatResponseError error
|
msgChatResponseError error
|
||||||
// sent on each chunk received from LLM
|
// sent on each chunk received from LLM
|
||||||
|
@ -21,7 +21,13 @@ func (m *Model) loadConversationMessages() tea.Cmd {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return shared.MsgError(err)
|
return shared.MsgError(err)
|
||||||
}
|
}
|
||||||
return msgMessagesLoaded(messages)
|
rootMessages, err := m.App.LoadConversationRootMessages()
|
||||||
|
if err != nil {
|
||||||
|
return shared.MsgError(err)
|
||||||
|
}
|
||||||
|
return msgConversationMessagesLoaded{
|
||||||
|
messages, rootMessages,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,17 +94,11 @@ func (m Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case msgConversationLoaded:
|
case msgConversationMessagesLoaded:
|
||||||
m.App.Conversation = msg.conversation
|
|
||||||
m.App.RootMessages = msg.rootMessages
|
m.App.RootMessages = msg.rootMessages
|
||||||
m.selectedMessage = -1
|
m.App.Messages = msg.messages
|
||||||
if len(m.App.RootMessages) > 0 {
|
|
||||||
cmds = append(cmds, m.loadConversationMessages())
|
|
||||||
}
|
|
||||||
case msgMessagesLoaded:
|
|
||||||
m.App.Messages = msg
|
|
||||||
if m.selectedMessage == -1 {
|
if m.selectedMessage == -1 {
|
||||||
m.selectedMessage = len(msg) - 1
|
m.selectedMessage = len(msg.messages) - 1
|
||||||
} else {
|
} else {
|
||||||
m.selectedMessage = min(m.selectedMessage, len(m.App.Messages))
|
m.selectedMessage = min(m.selectedMessage, len(m.App.Messages))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user