rework llm

This commit is contained in:
Kujtim Hoxha
2025-03-27 22:35:48 +01:00
parent 904061c243
commit afd9ad0560
61 changed files with 5882 additions and 2074 deletions

View File

@@ -89,7 +89,23 @@ func (i *sessionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return i, i.list.SetItems(items)
case pubsub.Event[session.Session]:
if msg.Type == pubsub.UpdatedEvent {
if msg.Type == pubsub.CreatedEvent && msg.Payload.ParentSessionID == "" {
// Check if the session is already in the list
items := i.list.Items()
for _, item := range items {
s := item.(listItem)
if s.id == msg.Payload.ID {
return i, nil
}
}
// insert the new session at the top of the list
items = append([]list.Item{listItem{
id: msg.Payload.ID,
title: msg.Payload.Title,
desc: formatTokensAndCost(msg.Payload.PromptTokens+msg.Payload.CompletionTokens, msg.Payload.Cost),
}}, items...)
return i, i.list.SetItems(items)
} else if msg.Type == pubsub.UpdatedEvent {
// update the session in the list
items := i.list.Items()
for idx, item := range items {
@@ -229,3 +245,4 @@ func NewSessionsCmp(app *app.App) SessionsCmp {
focused: false,
}
}