Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-start option and clean up header display #11

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions pkg/chat/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Status struct {

type model struct {
conversationManager geppetto_conversation.Manager
autoStartBackend bool

viewport viewport.Model
scrollToBottom bool
Expand Down Expand Up @@ -93,6 +94,12 @@ func WithStatus(status *Status) ModelOption {
}
}

func WithAutoStartBackend(autoStartBackend bool) ModelOption {
return func(m *model) {
m.autoStartBackend = autoStartBackend
}
}

// TODO(manuel, 2024-04-07) Add options to configure filepicker

func InitialModel(manager geppetto_conversation.Manager, backend Backend, options ...ModelOption) model {
Expand Down Expand Up @@ -151,6 +158,12 @@ func (m model) Init() tea.Cmd {

m.updateKeyBindings()

if m.autoStartBackend {
cmds = append(cmds, func() tea.Msg {
return StartBackendMsg{}
})
}

return tea.Batch(cmds...)
}

Expand Down Expand Up @@ -271,6 +284,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.state = StateUserInput
m.updateKeyBindings()

case StartBackendMsg:
return m, m.startBackend()

case UserActionMsg:
return m.handleUserAction(msg_)

Expand Down Expand Up @@ -356,7 +372,7 @@ func (m *model) recomputeSize() {
}

func (m model) headerView() string {
return m.title
return ""
}

func (m model) textAreaView() string {
Expand Down Expand Up @@ -401,7 +417,7 @@ func (m model) View() string {

ret := ""
if headerView != "" {
ret = headerView + "\n" + helpView
ret = headerView
}

switch m.state {
Expand All @@ -415,17 +431,7 @@ func (m model) View() string {
return ret
}

func (m *model) submit() tea.Cmd {
if !m.backend.IsFinished() {
return func() tea.Msg {
return errMsg(errors.New("already streaming"))
}
}

m.conversationManager.AppendMessages(
geppetto_conversation.NewChatMessage(geppetto_conversation.RoleUser, m.textArea.Value()))
m.textArea.SetValue("")

func (m *model) startBackend() tea.Cmd {
m.state = StateStreamCompletion
m.updateKeyBindings()

Expand All @@ -448,6 +454,20 @@ func (m *model) submit() tea.Cmd {
)
}

func (m *model) submit() tea.Cmd {
if !m.backend.IsFinished() {
return func() tea.Msg {
return errMsg(errors.New("already streaming"))
}
}

m.conversationManager.AppendMessages(
geppetto_conversation.NewChatMessage(geppetto_conversation.RoleUser, m.textArea.Value()))
m.textArea.SetValue("")

return m.startBackend()
}

type refreshMessageMsg struct {
GoToBottom bool
}
Expand Down
1 change: 1 addition & 0 deletions pkg/chat/user_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type FocusMessageMsg struct{}
type SelectNextMessageMsg struct{}
type SelectPrevMessageMsg struct{}
type SubmitMessageMsg struct{}
type StartBackendMsg struct{}
type CopyToClipboardMsg struct{}
type CopyLastResponseToClipboardMsg struct{}
type CopyLastSourceBlocksToClipboardMsg struct{}
Expand Down
Loading