From 1b4e1aa6827c5868c34233c3bbd1f586aceb99b1 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Sat, 15 Nov 2025 01:44:01 +0530 Subject: [PATCH] SimpleChatTCRV:MCUI:ChatMsgAddShow, Use4 toolresp nonhappy paths Make the toolresp non happy path use a direct insert chat msg wrt ui, rather than recreating the full chat session ui fresh. --- tools/server/public_simplechat/readme.md | 7 ++++- tools/server/public_simplechat/simplechat.js | 32 ++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index f07b470fa5..709646bcd0 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -762,10 +762,15 @@ sliding window based drop off or even before they kick in, this can help in many * MultiChatUI * chat_show takes care of showing or clearing tool call edit / trigger as well as tool response - edit / submit. Also show the currently active tool call and its response before it is submit + edit / submit. Also show the currently active tool call and its response before it is submitted was previously only shown in the edit / trigger and edit / submit ui elements, now instead it also shows as part of the chat session message blocks, so that user can delete or copy these if needed using the same mechanism as other messages in the chat session. + * use a delete msg helper, which takes care of deleting the msg from chat session as well as + efficiently update ui to any extent by removing the corresponding element directly from existing + chat session ui without recreating the full chat session ui. + * a helper to add a message into specified chat session, as well as show/update in the chat session + ui by appending the chat message, instead of recreating the full chat session ui. #### ToDo diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index cbf29b7a20..c1c7e80cbc 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -1347,14 +1347,36 @@ class MultiChatUI { return true } + /** + * Add a chatmsg to specified chat session, + * and update the chat session ui. + * + * @param {string} chatId + * @param {ChatMessageEx} msg + */ + chatmsg_add_show(chatId, msg) { + let chat = this.simpleChats[chatId]; + if (!chat) { + return + } + 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) + } + this.show_message(this.elDivChat, msg, 0, undefined) + } + /** * Remove the specified ChatMessage block in ui, without needing to show full chat session again. * @param {string} curChatId * @param {number} uniqIdChatMsg + * @param {boolean} bUpdateUI */ - ui_chatmessage_delete(curChatId, uniqIdChatMsg) { + ui_chatmessage_delete(curChatId, uniqIdChatMsg, bUpdateUI=true) { let index = this.simpleChats[curChatId].delete(uniqIdChatMsg) - if ((index >= 0) && (curChatId == this.curChatId)) { + if ((index >= 0) && (curChatId == this.curChatId) && bUpdateUI) { let el = document.querySelector(`[CMUniqId="${uniqIdChatMsg}"]`) el?.remove() if (index >= (this.simpleChats[curChatId].xchat.length-1)) { @@ -1587,14 +1609,12 @@ class MultiChatUI { } let toolResult = await chat.handle_toolcall(toolCallId, toolname, this.elInToolArgs.value) if (toolResult !== undefined) { - chat.add(new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, toolResult))) - this.chat_show(chat.chatId) + this.chatmsg_add_show(chat.chatId, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, toolResult))) this.ui_reset_userinput(false) } else { this.timers.toolcallResponseTimeout = setTimeout(() => { this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut') - chat.add(new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`))) - this.chat_show(chat.chatId) + this.chatmsg_add_show(chat.chatId, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`))) this.ui_reset_userinput(false) }, this.me.tools.toolCallResponseTimeoutMS) }