diff options
| author | Grail Finder <wohilas@gmail.com> | 2026-03-03 11:46:03 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2026-03-03 11:46:03 +0300 |
| commit | 0e5d37666f92bc75f12f118fc77a7e4af4a5924b (patch) | |
| tree | 967b9de608288a3cfbd40aaf284b6bd7b640a4b9 /tables.go | |
| parent | 093103bdd7cd02e10f2339e7beeb71375fb16256 (diff) | |
Enha: id for card map
Diffstat (limited to 'tables.go')
| -rw-r--r-- | tables.go | 33 |
1 files changed, 12 insertions, 21 deletions
@@ -159,27 +159,18 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table { // save updated card fi := strings.Index(selectedChat, "_") agentName := selectedChat[fi+1:] - cc, ok := sysMap[agentName] - if !ok { + cc := GetCardByRole(agentName) + if cc == nil { logger.Warn("no such card", "agent", agentName) - //no:lint if err := notifyUser("error", "no such card: "+agentName); err != nil { logger.Warn("failed ot notify", "error", err) } return } - // if chatBody.Messages[0].Role != "system" || chatBody.Messages[1].Role != agentName { - // if err := notifyUser("error", "unexpected chat structure; card: "+agentName); err != nil { - // logger.Warn("failed ot notify", "error", err) - // } - // return - // } - // change sys_prompt + first msg cc.SysPrompt = chatBody.Messages[0].Content cc.FirstMsg = chatBody.Messages[1].Content if err := pngmeta.WriteToPng(cc.ToSpec(cfg.UserRole), cc.FilePath, cc.FilePath); err != nil { - logger.Error("failed to write charcard", - "error", err) + logger.Error("failed to write charcard", "error", err) } return case "move sysprompt onto 1st msg": @@ -190,18 +181,16 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table { pages.RemovePage(historyPage) return case "new_chat_from_card": - // Reread card from file and start fresh chat fi := strings.Index(selectedChat, "_") agentName := selectedChat[fi+1:] - cc, ok := sysMap[agentName] - if !ok { + cc := GetCardByRole(agentName) + if cc == nil { logger.Warn("no such card", "agent", agentName) if err := notifyUser("error", "no such card: "+agentName); err != nil { logger.Warn("failed to notify", "error", err) } return } - // Reload card from disk newCard, err := pngmeta.ReadCard(cc.FilePath, cfg.UserRole) if err != nil { logger.Error("failed to reload charcard", "path", cc.FilePath, "error", err) @@ -214,9 +203,11 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table { return } } - // Update sysMap with fresh card data - sysMap[agentName] = newCard - // fetching sysprompt and first message anew from the card + if newCard.ID == "" { + newCard.ID = models.ComputeCardID(newCard.Role, newCard.FilePath) + } + sysMap[newCard.ID] = newCard + roleToID[newCard.Role] = newCard.ID startNewChat(false) pages.RemovePage(historyPage) return @@ -529,8 +520,8 @@ func makeAgentTable(agentList []string) *tview.Table { SetSelectable(false)) case 1: if actions[c-1] == "filepath" { - cc, ok := sysMap[agentList[r]] - if !ok { + cc := GetCardByRole(agentList[r]) + if cc == nil { continue } chatActTable.SetCell(r, c, |
