Enha: charlist in cards

This commit is contained in:
Grail Finder
2026-01-21 21:01:01 +03:00
parent 4e597e944e
commit a28e8ef9e2
5 changed files with 38 additions and 14 deletions

1
bot.go
View File

@@ -1063,7 +1063,6 @@ func addNewChat(chatName string) {
func applyCharCard(cc *models.CharCard) { func applyCharCard(cc *models.CharCard) {
cfg.AssistantRole = cc.Role cfg.AssistantRole = cc.Role
// FIXME: remove
history, err := loadAgentsLastChat(cfg.AssistantRole) history, err := loadAgentsLastChat(cfg.AssistantRole)
if err != nil { if err != nil {
// too much action for err != nil; loadAgentsLastChat needs to be split up // too much action for err != nil; loadAgentsLastChat needs to be split up

View File

@@ -164,7 +164,7 @@ func setLogLevel(sl string) {
} }
func listRolesWithUser() []string { func listRolesWithUser() []string {
roles := chatBody.ListRoles() roles := listChatRoles()
// Remove user role if it exists in the list (to avoid duplicates and ensure it's at position 0) // Remove user role if it exists in the list (to avoid duplicates and ensure it's at position 0)
filteredRoles := make([]string, 0, len(roles)) filteredRoles := make([]string, 0, len(roles))
for _, role := range roles { for _, role := range roles {
@@ -250,3 +250,26 @@ func randString(n int) string {
} }
return string(b) return string(b)
} }
// set of roles within card definition and mention in chat history
func listChatRoles() []string {
currentChat, ok := chatMap[activeChatName]
cbc := chatBody.ListRoles()
if !ok {
return cbc
}
currentCard, ok := sysMap[currentChat.Agent]
if !ok {
// log error
logger.Warn("failed to find current card in sysMap", "agent", currentChat.Agent, "sysMap", sysMap)
return cbc
}
charset := []string{}
for _, name := range currentCard.Characters {
if !strInSlice(name, cbc) {
charset = append(charset, name)
}
}
charset = append(charset, cbc...)
return charset
}

View File

@@ -35,6 +35,7 @@ func (c *CharCardSpec) Simplify(userName, fpath string) *CharCard {
FirstMsg: fm, FirstMsg: fm,
Role: c.Name, Role: c.Name,
FilePath: fpath, FilePath: fpath,
Characters: []string{c.Name, userName},
} }
} }
@@ -42,6 +43,7 @@ type CharCard struct {
SysPrompt string `json:"sys_prompt"` SysPrompt string `json:"sys_prompt"`
FirstMsg string `json:"first_msg"` FirstMsg string `json:"first_msg"`
Role string `json:"role"` Role string `json:"role"`
Characters []string `json:"chars"`
FilePath string `json:"filepath"` FilePath string `json:"filepath"`
} }

View File

@@ -4,5 +4,6 @@
"role2": "Bob", "role2": "Bob",
"role3": "Carl", "role3": "Carl",
"filepath": "sysprompts/alice_bob_carl.json", "filepath": "sysprompts/alice_bob_carl.json",
"chars": ["Alice", "Bob", "Carl"],
"first_msg": "Hey guys! Want to play Alias like game? I'll tell Bob a word and he needs to describe that word so Carl can guess what it was?" "first_msg": "Hey guys! Want to play Alias like game? I'll tell Bob a word and he needs to describe that word so Carl can guess what it was?"
} }

7
tui.go
View File

@@ -836,7 +836,7 @@ func init() {
if injectRole { if injectRole {
status = "enabled" status = "enabled"
} }
if err := notifyUser("injectRole", fmt.Sprintf("Role injection %s", status)); err != nil { if err := notifyUser("injectRole", "Role injection "+status); err != nil {
logger.Error("failed to send notification", "error", err) logger.Error("failed to send notification", "error", err)
} }
updateStatusLine() updateStatusLine()
@@ -1218,7 +1218,8 @@ func init() {
if cfg.WriteNextMsgAsCompletionAgent != "" { if cfg.WriteNextMsgAsCompletionAgent != "" {
botPersona = cfg.WriteNextMsgAsCompletionAgent botPersona = cfg.WriteNextMsgAsCompletionAgent
} }
roles := chatBody.ListRoles() // roles := chatBody.ListRoles()
roles := listChatRoles()
if len(roles) == 0 { if len(roles) == 0 {
logger.Warn("empty roles in chat") logger.Warn("empty roles in chat")
} }
@@ -1229,11 +1230,9 @@ func init() {
if strings.EqualFold(role, botPersona) { if strings.EqualFold(role, botPersona) {
if i == len(roles)-1 { if i == len(roles)-1 {
cfg.WriteNextMsgAsCompletionAgent = roles[0] // reached last, get first cfg.WriteNextMsgAsCompletionAgent = roles[0] // reached last, get first
botPersona = cfg.WriteNextMsgAsCompletionAgent
break break
} }
cfg.WriteNextMsgAsCompletionAgent = roles[i+1] // get next role cfg.WriteNextMsgAsCompletionAgent = roles[i+1] // get next role
botPersona = cfg.WriteNextMsgAsCompletionAgent
// logger.Info("picked role", "roles", roles, "index", i+1) // logger.Info("picked role", "roles", roles, "index", i+1)
break break
} }