Large refactor - it compiles!
This refactor splits out all conversation concerns into a new `conversation` package. There is now a split between `conversation` and `api`s representation of `Message`, the latter storing the minimum information required for interaction with LLM providers. There is necessary conversation between the two when making LLM calls.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/conversation"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/model"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/shared"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@@ -21,13 +22,7 @@ func (m *Model) loadConversationMessages() tea.Cmd {
|
||||
if err != nil {
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
rootMessages, err := m.App.LoadConversationRootMessages()
|
||||
if err != nil {
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
return msgConversationMessagesLoaded{
|
||||
messages, rootMessages,
|
||||
}
|
||||
return msgConversationMessagesLoaded{messages}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +36,7 @@ func (m *Model) generateConversationTitle() tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) updateConversationTitle(conversation *api.Conversation) tea.Cmd {
|
||||
func (m *Model) updateConversationTitle(conversation *conversation.Conversation) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
err := m.App.UpdateConversationTitle(conversation)
|
||||
if err != nil {
|
||||
@@ -51,7 +46,7 @@ func (m *Model) updateConversationTitle(conversation *api.Conversation) tea.Cmd
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) cloneMessage(message api.Message, selected bool) tea.Cmd {
|
||||
func (m *Model) cloneMessage(message conversation.Message, selected bool) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
msg, err := m.App.CloneMessage(message, selected)
|
||||
if err != nil {
|
||||
@@ -61,7 +56,7 @@ func (m *Model) cloneMessage(message api.Message, selected bool) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) updateMessageContent(message *api.Message) tea.Cmd {
|
||||
func (m *Model) updateMessageContent(message *conversation.Message) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
err := m.App.UpdateMessageContent(message)
|
||||
if err != nil {
|
||||
@@ -71,14 +66,13 @@ func (m *Model) updateMessageContent(message *api.Message) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) cycleSelectedRoot(conv *api.Conversation, dir model.MessageCycleDirection) tea.Cmd {
|
||||
if len(m.App.RootMessages) < 2 {
|
||||
|
||||
func (m *Model) cycleSelectedRoot(conv *conversation.Conversation, dir model.MessageCycleDirection) tea.Cmd {
|
||||
if len(conv.RootMessages) < 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return func() tea.Msg {
|
||||
nextRoot, err := m.App.CycleSelectedRoot(conv, m.App.RootMessages, dir)
|
||||
nextRoot, err := m.App.CycleSelectedRoot(conv, dir)
|
||||
if err != nil {
|
||||
return shared.WrapError(err)
|
||||
}
|
||||
@@ -86,7 +80,7 @@ func (m *Model) cycleSelectedRoot(conv *api.Conversation, dir model.MessageCycle
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) cycleSelectedReply(message *api.Message, dir model.MessageCycleDirection) tea.Cmd {
|
||||
func (m *Model) cycleSelectedReply(message *conversation.Message, dir model.MessageCycleDirection) tea.Cmd {
|
||||
if len(message.Replies) < 2 {
|
||||
return nil
|
||||
}
|
||||
@@ -106,7 +100,7 @@ func (m *Model) persistConversation() tea.Cmd {
|
||||
if err != nil {
|
||||
return shared.AsMsgError(err)
|
||||
}
|
||||
return msgConversationPersisted{conversation.ID == 0, conversation, messages}
|
||||
return msgConversationPersisted{conversation, messages}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user