mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-01 07:04:20 +01:00
feat: session manager
This commit is contained in:
@@ -91,8 +91,11 @@ func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return s, nil
|
||||
case key.Matches(msg, sessionKeys.Enter):
|
||||
if len(s.sessions) > 0 {
|
||||
selectedSession := s.sessions[s.selectedIdx]
|
||||
// Update the session manager with the selected session
|
||||
session.SetCurrentSession(selectedSession.ID)
|
||||
return s, util.CmdHandler(SessionSelectedMsg{
|
||||
Session: s.sessions[s.selectedIdx],
|
||||
Session: selectedSession,
|
||||
})
|
||||
}
|
||||
case key.Matches(msg, sessionKeys.Escape):
|
||||
|
||||
@@ -128,17 +128,20 @@ func (p *chatPage) clearSidebar() tea.Cmd {
|
||||
func (p *chatPage) sendMessage(text string, attachments []message.Attachment) tea.Cmd {
|
||||
var cmds []tea.Cmd
|
||||
if p.session.ID == "" {
|
||||
session, err := p.app.Sessions.Create(context.Background(), "New Session")
|
||||
newSession, err := p.app.Sessions.Create(context.Background(), "New Session")
|
||||
if err != nil {
|
||||
return util.ReportError(err)
|
||||
}
|
||||
|
||||
p.session = session
|
||||
p.session = newSession
|
||||
// Update the current session in the session manager
|
||||
session.SetCurrentSession(newSession.ID)
|
||||
|
||||
cmd := p.setSidebar()
|
||||
if cmd != nil {
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(session)))
|
||||
cmds = append(cmds, util.CmdHandler(chat.SessionSelectedMsg(newSession)))
|
||||
}
|
||||
|
||||
_, err := p.app.CoderAgent.Run(context.Background(), p.session.ID, text, attachments...)
|
||||
|
||||
Reference in New Issue
Block a user