From c029cea9abbd999ff161b71d7207b040f9ea061c Mon Sep 17 00:00:00 2001 From: tauraamui Date: Fri, 7 Nov 2025 12:42:38 +0000 Subject: [PATCH] chore: handle opening or closing history state messages --- internal/tui/components/chat/editor/editor.go | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 2fb9dabc953375e0e8be465b321eafed0b4fb755..d26016083c09084fe7e2eb873629852d38704864 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -11,6 +11,7 @@ import ( "runtime" "slices" "strings" + "time" "unicode" "charm.land/bubbles/v2/key" @@ -271,9 +272,15 @@ func (m *editorCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) { m.setEditorPrompt() return m, nil case loadHistoryMsg: - m.history = InitialiseHistory([]string{}) + msgs, err := m.getUserMessagesAsText() + if err != nil { + // TODO(tauraamui): handle error for loading history better in the UI later + } + m.history = InitialiseHistory(msgs) + m.textarea.SetValue("opened history state") case closeHistoryMsg: m.history = nil + m.textarea.SetValue("closed history") // for easier temporary visual debugging case tea.KeyPressMsg: cur := m.textarea.Cursor() curIdx := m.textarea.Width()*cur.Y + cur.X @@ -468,11 +475,10 @@ func (m *editorCmp) View() string { return content } -/* -func (m *editorCmp) getUserMessagesAsText(ctx context.Context) ([]string, error) { - if len(m.historyCache) > 0 { - return m.historyCache, nil - } +func (m *editorCmp) getUserMessagesAsText() ([]string, error) { + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + allMessages, err := m.app.Messages.List(ctx, m.session.ID) if err != nil { return nil, err @@ -486,10 +492,10 @@ func (m *editorCmp) getUserMessagesAsText(ctx context.Context) ([]string, error) } userMessages = append(userMessages, m.textarea.Value()) - m.historyCache = userMessages return userMessages, nil } +/* type direction int const (