Private
Public Access
1
0

TUI refactor

- Clean up, improved startup logic, initial conversation load
- Moved converation/message business logic (mostly) into `model/tui`
This commit is contained in:
2024-09-16 00:48:45 +00:00
parent 1570988b98
commit 443c8096d3
11 changed files with 431 additions and 350 deletions

View File

@@ -4,6 +4,7 @@ import (
"time"
"git.mlow.ca/mlow/lmcli/pkg/api"
"git.mlow.ca/mlow/lmcli/pkg/tui/model"
"git.mlow.ca/mlow/lmcli/pkg/tui/shared"
"github.com/charmbracelet/bubbles/cursor"
"github.com/charmbracelet/bubbles/spinner"
@@ -76,11 +77,11 @@ type Model struct {
shared.Shared
shared.Sections
// app state
// App state
App *model.AppModel
// Chat view state
state state // current overall status of the view
conversation *api.Conversation
rootMessages []api.Message
messages []api.Message
selectedMessage int
editorTarget editorTarget
stopSignal chan struct{}
@@ -88,7 +89,7 @@ type Model struct {
chatReplyChunks chan api.Chunk
persistence bool // whether we will save new messages in the conversation
// ui state
// UI state
focus focusState
wrap bool // whether message content is wrapped to viewport width
showToolResults bool // whether tool calls and results are shown
@@ -107,12 +108,12 @@ type Model struct {
elapsed time.Duration
}
func Chat(shared shared.Shared) Model {
func Chat(app *model.AppModel, shared shared.Shared) Model {
m := Model{
App: app,
Shared: shared,
state: idle,
conversation: &api.Conversation{},
persistence: true,
stopSignal: make(chan struct{}),
@@ -143,15 +144,15 @@ func Chat(shared shared.Shared) Model {
m.replyCursor.SetChar(" ")
m.replyCursor.Focus()
system := shared.Ctx.DefaultSystemPrompt()
system := app.Ctx.DefaultSystemPrompt()
agent := shared.Ctx.GetAgent(shared.Ctx.Config.Defaults.Agent)
agent := app.Ctx.GetAgent(app.Ctx.Config.Defaults.Agent)
if agent != nil && agent.SystemPrompt != "" {
system = agent.SystemPrompt
}
if system != "" {
m.messages = api.ApplySystemPrompt(m.messages, system, false)
m.App.Messages = api.ApplySystemPrompt(m.App.Messages, system, false)
}
m.input.Focus()