From 3e20b5c6802616fb68b0db08e6d5d9df3f4d31e3 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Sat, 15 Nov 2025 14:20:42 +0530 Subject: [PATCH] SimpleChatTCRV:MCUI:CMAddShow:tool response happy path Rename lastMsg to prevLastMsg to match semantic better Return seperate flags to indicate add and show success or not Update tool response happy path to use this optimised add show instead of chat_show (which recreates the full chat session ui). --- tools/server/public_simplechat/simplechat.js | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index c1c7e80cbc..2027e4cdd4 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -1348,8 +1348,8 @@ class MultiChatUI { } /** - * Add a chatmsg to specified chat session, - * and update the chat session ui. + * Add a chatmsg to specified chat session. + * Update the chat session ui, if current. * * @param {string} chatId * @param {ChatMessageEx} msg @@ -1357,15 +1357,19 @@ class MultiChatUI { chatmsg_add_show(chatId, msg) { let chat = this.simpleChats[chatId]; if (!chat) { - return + return { added: false, shown: false } } - let lastMsg = chat.xchat[chat.xchat.length-1] chat.add(msg) - if (lastMsg) { - this.ui_chatmessage_delete(chatId, lastMsg.uniqId, false) - this.show_message(this.elDivChat, lastMsg, 1, msg) + if (chatId != this.curChatId) { + return { added: true, shown: false } + } + let prevLastMsg = chat.xchat[chat.xchat.length-2] + if (prevLastMsg) { + this.ui_chatmessage_delete(chatId, prevLastMsg.uniqId, false) + this.show_message(this.elDivChat, prevLastMsg, 1, msg) } this.show_message(this.elDivChat, msg, 0, undefined) + return { added: true, shown: true } } /** @@ -1444,8 +1448,7 @@ class MultiChatUI { limitedData = data.slice(0, this.me.tools.iResultMaxDataLength) + `\n\n\nALERT: Data too long, was chopped ....` } } - chat.add(new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, tcid, name, limitedData))) - if (this.chat_show(cid)) { + if (this.chatmsg_add_show(cid, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, tcid, name, limitedData))).shown) { if (this.me.tools.autoSecs > 0) { this.timers.toolcallResponseSubmitClick = setTimeout(()=>{ this.elBtnUser.click()