Enha: sort chat table (by updated_at)

This commit is contained in:
Grail Finder
2026-01-14 10:06:15 +03:00
parent e120a62939
commit 3b542421e3
3 changed files with 17 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ import (
"os"
"path"
"strings"
"time"
"unicode"
"math/rand/v2"
@@ -115,6 +116,7 @@ func startNewChat() {
Name: fmt.Sprintf("%d_%s", id+1, cfg.AssistantRole),
Msgs: string(defaultStarterBytes),
Agent: cfg.AssistantRole,
CreatedAt: time.Now(),
}
activeChatName = newChat.Name
chatMap[newChat.Name] = newChat

View File

@@ -23,6 +23,15 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
chatList[i] = name
i++
}
// Sort chatList by UpdatedAt field in descending order (most recent first)
for i := 0; i < len(chatList)-1; i++ {
for j := i + 1; j < len(chatList); j++ {
if chatMap[chatList[i]].UpdatedAt.Before(chatMap[chatList[j]].UpdatedAt) {
// Swap chatList[i] and chatList[j]
chatList[i], chatList[j] = chatList[j], chatList[i]
}
}
}
// Add 1 extra row for header
rows, cols := len(chatMap)+1, len(actions)+4 // +2 for name, +2 for timestamps
chatActTable := tview.NewTable().

View File

@@ -330,6 +330,7 @@ func memorise(args map[string]string) []byte {
Topic: args["topic"],
Mind: args["data"],
UpdatedAt: time.Now(),
CreatedAt: time.Now(),
}
if _, err := store.Memorise(memory); err != nil {
logger.Error("failed to save memory", "err", err, "memoory", memory)