Fix (race): mutex chatbody
This commit is contained in:
30
tables.go
30
tables.go
@@ -128,8 +128,8 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
|
||||
pages.RemovePage(historyPage)
|
||||
return
|
||||
}
|
||||
chatBody.Messages = history
|
||||
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||
chatBody.SetMessages(history)
|
||||
textView.SetText(chatToText(chatBody.GetMessages(), cfg.ShowSys))
|
||||
activeChatName = selectedChat
|
||||
pages.RemovePage(historyPage)
|
||||
return
|
||||
@@ -149,8 +149,8 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
|
||||
}
|
||||
showToast("chat deleted", selectedChat+" was deleted")
|
||||
// load last chat
|
||||
chatBody.Messages = loadOldChatOrGetNew()
|
||||
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||
chatBody.SetMessages(loadOldChatOrGetNew())
|
||||
textView.SetText(chatToText(chatBody.GetMessages(), cfg.ShowSys))
|
||||
pages.RemovePage(historyPage)
|
||||
return
|
||||
case "update card":
|
||||
@@ -163,16 +163,24 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
|
||||
showToast("error", "no such card: "+agentName)
|
||||
return
|
||||
}
|
||||
cc.SysPrompt = chatBody.Messages[0].Content
|
||||
cc.FirstMsg = chatBody.Messages[1].Content
|
||||
if msg0, ok := chatBody.GetMessageAt(0); ok {
|
||||
cc.SysPrompt = msg0.Content
|
||||
}
|
||||
if msg1, ok := chatBody.GetMessageAt(1); ok {
|
||||
cc.FirstMsg = msg1.Content
|
||||
}
|
||||
if err := pngmeta.WriteToPng(cc.ToSpec(cfg.UserRole), cc.FilePath, cc.FilePath); err != nil {
|
||||
logger.Error("failed to write charcard", "error", err)
|
||||
}
|
||||
return
|
||||
case "move sysprompt onto 1st msg":
|
||||
chatBody.Messages[1].Content = chatBody.Messages[0].Content + chatBody.Messages[1].Content
|
||||
chatBody.Messages[0].Content = rpDefenitionSysMsg
|
||||
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||
chatBody.WithLock(func(cb *models.ChatBody) {
|
||||
if len(cb.Messages) >= 2 {
|
||||
cb.Messages[1].Content = cb.Messages[0].Content + cb.Messages[1].Content
|
||||
cb.Messages[0].Content = rpDefenitionSysMsg
|
||||
}
|
||||
})
|
||||
textView.SetText(chatToText(chatBody.GetMessages(), cfg.ShowSys))
|
||||
activeChatName = selectedChat
|
||||
pages.RemovePage(historyPage)
|
||||
return
|
||||
@@ -563,7 +571,7 @@ func makeAgentTable(agentList []string) *tview.Table {
|
||||
return
|
||||
}
|
||||
// replace textview
|
||||
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||
textView.SetText(chatToText(chatBody.GetMessages(), cfg.ShowSys))
|
||||
colorText()
|
||||
updateStatusLine()
|
||||
// sysModal.ClearButtons()
|
||||
@@ -732,7 +740,7 @@ func makeImportChatTable(filenames []string) *tview.Table {
|
||||
colorText()
|
||||
updateStatusLine()
|
||||
// redraw the text in text area
|
||||
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||
textView.SetText(chatToText(chatBody.GetMessages(), cfg.ShowSys))
|
||||
pages.RemovePage(historyPage)
|
||||
app.SetFocus(textArea)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user