diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-12 14:49:01 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-21 13:38:42 +0200 |
| commit | 0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345 (patch) | |
| tree | 9b45cabbb2c8f0195d8428445db4d8a710db7951 /internal/tui/page | |
| parent | 8d874b839db169906e18e4277cd198504018e022 (diff) | |
| download | opencode-0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345.tar.gz opencode-0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345.zip | |
implement nested tool calls and initial setup for result metadata
Diffstat (limited to 'internal/tui/page')
| -rw-r--r-- | internal/tui/page/chat.go | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/internal/tui/page/chat.go b/internal/tui/page/chat.go index 7ac0d2293..a7a51bb84 100644 --- a/internal/tui/page/chat.go +++ b/internal/tui/page/chat.go @@ -1,9 +1,10 @@ package page import ( + "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/kujtimiihoxha/termai/internal/app" - "github.com/kujtimiihoxha/termai/internal/message" + "github.com/kujtimiihoxha/termai/internal/llm/agent" "github.com/kujtimiihoxha/termai/internal/session" "github.com/kujtimiihoxha/termai/internal/tui/components/chat" "github.com/kujtimiihoxha/termai/internal/tui/layout" @@ -18,8 +19,32 @@ type chatPage struct { session session.Session } +type ChatKeyMap struct { + NewSession key.Binding +} + +var keyMap = ChatKeyMap{ + NewSession: key.NewBinding( + key.WithKeys("ctrl+n"), + key.WithHelp("ctrl+n", "new session"), + ), +} + func (p *chatPage) Init() tea.Cmd { - return p.layout.Init() + // TODO: remove + cmds := []tea.Cmd{ + p.layout.Init(), + } + + sessions, _ := p.app.Sessions.List() + if len(sessions) > 0 { + p.session = sessions[0] + cmd := p.setSidebar() + cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(p.session)), cmd) + } + return tea.Batch( + cmds..., + ) } func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -31,6 +56,13 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if cmd != nil { return p, cmd } + case tea.KeyMsg: + switch { + case key.Matches(msg, keyMap.NewSession): + p.session = session.Session{} + p.clearSidebar() + return p, util.CmdHandler(chat.SessionClearedMsg{}) + } } u, cmd := p.layout.Update(msg) p.layout = u.(layout.SplitPaneLayout) @@ -51,6 +83,12 @@ func (p *chatPage) setSidebar() tea.Cmd { return sidebarContainer.Init() } +func (p *chatPage) clearSidebar() { + p.layout.SetRightPanel(nil) + width, height := p.layout.GetSize() + p.layout.SetSize(width, height) +} + func (p *chatPage) sendMessage(text string) tea.Cmd { var cmds []tea.Cmd if p.session.ID == "" { @@ -66,15 +104,15 @@ func (p *chatPage) sendMessage(text string) tea.Cmd { } cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(session))) } - // TODO: actually call agent - p.app.Messages.Create(p.session.ID, message.CreateMessageParams{ - Role: message.User, - Parts: []message.ContentPart{ - message.TextContent{ - Text: text, - }, - }, - }) + // TODO: move this to a service + a, err := agent.NewCoderAgent(p.app) + if err != nil { + return util.ReportError(err) + } + go func() { + a.Generate(p.app.Context, p.session.ID, text) + }() + return tea.Batch(cmds...) } @@ -85,7 +123,7 @@ func (p *chatPage) View() string { func NewChatPage(app *app.App) tea.Model { messagesContainer := layout.NewContainer( chat.NewMessagesCmp(app), - layout.WithPadding(1, 1, 1, 1), + layout.WithPadding(1, 1, 0, 1), ) editorContainer := layout.NewContainer( |
