From fa192a262410eb98b42ff8fb9e0f4e1111240514 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 25 Jan 2026 09:59:07 +0300 Subject: Feat: autoturn --- bot.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'bot.go') diff --git a/bot.go b/bot.go index cd35445..1a2cebb 100644 --- a/bot.go +++ b/bot.go @@ -813,7 +813,18 @@ out: if err := updateStorageChat(activeChatName, chatBody.Messages); err != nil { logger.Warn("failed to update storage", "error", err, "name", activeChatName) } + // FIXME: recursive calls findCall(respText.String(), toolResp.String(), tv) + // TODO: have a config attr + // Check if this message was sent privately to specific characters + // If so, trigger those characters to respond if that char is not controlled by user + // perhaps we should have narrator role to determine which char is next to act + if cfg.AutoTurn { + lastMsg := chatBody.Messages[len(chatBody.Messages)-1] + if len(lastMsg.KnownTo) > 0 { + triggerPrivateMessageResponses(lastMsg, tv) + } + } } // cleanChatBody removes messages with null or empty content to prevent API issues @@ -1205,3 +1216,27 @@ func init() { scrollToEndEnabled = cfg.AutoScrollEnabled go updateModelLists() } + +// triggerPrivateMessageResponses checks if a message was sent privately to specific characters +// and triggers those non-user characters to respond +func triggerPrivateMessageResponses(msg models.RoleMsg, tv *tview.TextView) { + if cfg == nil || !cfg.CharSpecificContextEnabled { + return + } + userCharacter := cfg.UserRole + if cfg.WriteNextMsgAs != "" { + userCharacter = cfg.WriteNextMsgAs + } + // Check each character in the KnownTo list + for _, recipient := range msg.KnownTo { + // Skip if this is the user character or the sender of the message + if recipient == cfg.UserRole || recipient == userCharacter || recipient == msg.Role || recipient == cfg.ToolRole { + continue + } + // Trigger the recipient character to respond by simulating a prompt + // that indicates it's their turn + triggerMsg := recipient + ":\n" + // Call chatRound with the trigger message to make the recipient respond + chatRound(triggerMsg, recipient, tv, false, false) + } +} -- cgit v1.2.3