From 926b5cd8f3a9bc49c477f23046162c6c0dcf09e8 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Fri, 14 Nov 2025 21:57:04 +0530 Subject: [PATCH] SimpleChatTCRV:Cleanup:Delete and Chat UI suitable update If deleting a non last (and non just before last) message, then just directly remove the corresponding chat message block from the ChatSession UI and be done with it. However if deleting the last (or just before last) message, then one needs to decide on whether tool call edit/trigger ui is shown or removed and so... and similarly wrt tool response edit/submit. --- tools/server/public_simplechat/readme.md | 7 ++++ tools/server/public_simplechat/simplechat.js | 34 ++++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index 194762b49e..f07b470fa5 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -760,6 +760,13 @@ sliding window based drop off or even before they kick in, this can help in many * have a del button, which allows one to delete the currently in focus chat message. * have a copy button, which allows one to copy the textual content into system clipboard. +* 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 + 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. + #### ToDo diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 081af20824..cbf29b7a20 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -1212,12 +1212,13 @@ class MultiChatUI { */ show_message(elParent, msg, iFromLast, nextMsg) { // Handle ToolTemp - if (msg.ns.role === Roles.ToolTemp) { - if (iFromLast == 0) { + if (iFromLast == 0) { + if (msg.ns.role === Roles.ToolTemp) { this.elInUser.value = msg.ns.getContent(); - this.elInUser.dataset.role = Roles.ToolTemp + } else { + this.elInUser.value = ""; } - return + this.elInUser.dataset.role = msg.ns.role } // Create main section let secMain = document.createElement('section') @@ -1274,7 +1275,7 @@ class MultiChatUI { img.src = msg.ns.image_url secContents?.append(img) } - // Handle tool call ui, if reqd + // Handle tool call edit/trigger ui, if reqd let bTC = false let bAuto = false if (msg.ns.role === Roles.Assistant) { @@ -1290,8 +1291,8 @@ class MultiChatUI { this.ui_reset_toolcall_as_needed(msg, bAuto); } } - // Handle tool call non ui - if (msg.ns.tool_calls && !bTC) { + // Handle tool call message show + if (msg.ns.tool_calls) { for (const tc of msg.ns.tool_calls) { this.show_message_toolcall(secContents, tc) } @@ -1322,8 +1323,8 @@ class MultiChatUI { let chat = this.simpleChats[this.curChatId]; if (bClear) { this.elDivChat.replaceChildren(); - this.ui_reset_toolcall_as_needed(new ChatMessageEx()); } + this.ui_reset_toolcall_as_needed(new ChatMessageEx()); this.elLastChatMessage = null let chatToShow = chat.recent_chat(this.me.chatProps.iRecentUserMsgCnt); for(const [i, x] of chatToShow.entries()) { @@ -1348,14 +1349,19 @@ class MultiChatUI { /** * Remove the specified ChatMessage block in ui, without needing to show full chat session again. + * @param {string} curChatId * @param {number} uniqIdChatMsg */ - ui_chatmessage_delete(uniqIdChatMsg) { - let index = this.simpleChats[this.curChatId].delete(uniqIdChatMsg) - if (index >= 0) { - let el = document.querySelector(`[CMUniqId="${uniqIdChatMsg}"`) - console.log(el) + ui_chatmessage_delete(curChatId, uniqIdChatMsg) { + let index = this.simpleChats[curChatId].delete(uniqIdChatMsg) + if ((index >= 0) && (curChatId == this.curChatId)) { + let el = document.querySelector(`[CMUniqId="${uniqIdChatMsg}"]`) el?.remove() + if (index >= (this.simpleChats[curChatId].xchat.length-1)) { + // so that tool call edit/trigger control etal can be controlled suitably + // from a single place - need to add that centrally controlled logic flor still. + this.chat_show(curChatId) + } } } @@ -1455,7 +1461,7 @@ class MultiChatUI { this.elPopoverChatMsgDelBtn.addEventListener('click', (ev) => { console.log(`DBUG:MCUI:ChatMsgPO:Del:${this.curChatId}:${this.uniqIdChatMsgPO}`) - this.ui_chatmessage_delete(this.uniqIdChatMsgPO) + this.ui_chatmessage_delete(this.curChatId, this.uniqIdChatMsgPO) }) this.elPopoverChatMsgCopyBtn.addEventListener('click', (ev) => {