diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index a889645f6f..14969f5508 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -906,6 +906,9 @@ Chat Session specific settings tool call proxy server. * however any resultant changes to the available tool calls list wont get reflected, till one reloads the program. +* uirefresh helper ensures client side sliding window is always satisfied. + * now it remove messages no longer in the sliding window, so user only sees what is sent to the ai server, + in the chat session messages ui. #### ToDo @@ -933,14 +936,6 @@ session to the end user, but inturn not to be sent to the ai server. Ex current Updating system prompt, will reset user input area fully now, which seems a good enough behaviour, while keeping the code flow also simple and straight, do I need to change it, I dont think so as of now. -Should I have a toggle to control whether show only the messages sent to ai server based on sliding window -or show all the messages (ie even beyond the sliding window)? -* rather previously with chat_show only whats in current sliding window was being shown, but now with - the uirefresh based logic, all messages from last chat_show will be shown irrespective of whether still - in ai server handshake related sliding window or not. -* Update UIRefresh helper to optionally remove messages no longer in the sliding window, so user only sees - what is sent to the ai server in the chat session messages ui. - For now amn't bringing in mozilla/github/standard-entities pdf, md, mathslatex etal javascript libraries for their respective functionalities. diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 273f6d3e28..6f7706ff85 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -481,6 +481,9 @@ function usage_note(sRecentUserMsgCnt) {
  • ChatHistInCtxt, MaxTokens, ModelCtxt window to expand
  • ${AI_TC_SESSIONNAME} session keeps tool calls disabled, to avoid recursive...
  • + `; return sUsageNote; @@ -1421,6 +1424,7 @@ class MultiChatUI { // Create main section let secMain = document.createElement('section') secMain.id = `cmuid${msg.uniqId}` + secMain.dataset.cmuid = String(msg.uniqId) secMain.classList.add(`role-${msg.ns.role}`) secMain.classList.add('chat-message') secMain.addEventListener('mouseenter', (ev)=>{ @@ -1510,7 +1514,7 @@ class MultiChatUI { } /** - * Refresh UI wrt given chatId, provided it matches the currently selected chatId + * Refresh UI (optionally bruteforce) wrt given chatId, provided it matches the currently selected chatId * * Show the chat contents in elDivChat. * Also update @@ -1522,6 +1526,8 @@ class MultiChatUI { * * option to load prev saved chat if any * * as well as settings/info. * + * Ensures only messages with in the currently set sliding window are shown + * * @param {string} chatId * @param {boolean} bClear * @param {boolean} bShowInfoAll @@ -1585,6 +1591,8 @@ class MultiChatUI { * If the houseKeeping.clear flag is set then fallback to * the brute force full on chat_show. * + * Also ensures only messages with in the currently set sliding window are shown + * * @param {string} chatId * @param {number} lastN */ @@ -1599,9 +1607,20 @@ class MultiChatUI { } this.ui_userinput_reset(false) this.ui_toolcallvalidated_as_needed(new ChatMessageEx()); + let chatToShow = chat.recent_chat(chat.cfg.chatProps.iRecentUserMsgCnt); + // Remove messages outside sliding window + /** @type {NodeListOf} */ + let elList = this.elDivChat.querySelectorAll('[id*="cmuid"]') + for (const el of elList) { + if (Number(el.dataset.cmuid) >= chatToShow[0].uniqId) { + break + } + el.remove() + } + // Refresh last few messages in the chat history, as requested by user for(let i=lastN; i > 0; i-=1) { - let msg = chat.xchat[chat.xchat.length-i] - let nextMsg = chat.xchat[chat.xchat.length-(i-1)] + let msg = chatToShow[chatToShow.length-i] + let nextMsg = chatToShow[chatToShow.length-(i-1)] if (msg) { this.chatmsg_ui_remove(msg.uniqId) this.show_message(this.elDivChat, chat.chatId, msg, (i-1), nextMsg)