SimpleChatTCRV:UIRefresh cleanup: Show only msgs in sliding window

Ensure we are working with the Chat Messages in Chat session, which
are in the currently active sliding window.

Remove any chat message blocks in the chat session ui, which are
no longer in the sliding window of context.

This brings uirefresh semantic to be in sync with chat_show logic
This commit is contained in:
hanishkvc 2025-11-24 14:43:50 +05:30
parent 856f403f1d
commit 4bca1f6f3e
2 changed files with 25 additions and 11 deletions

View File

@ -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.

View File

@ -481,6 +481,9 @@ function usage_note(sRecentUserMsgCnt) {
<li> ChatHistInCtxt, MaxTokens, ModelCtxt window to expand</li>
</ul>
<li> ${AI_TC_SESSIONNAME} session keeps tool calls disabled, to avoid recursive...</li>
<ul class="ul2">
<li> Used by external_ai tool call, which allows ai calling ai, as needed.</li>
</ul>
</ul>
</details>`;
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<HTMLElement>} */
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)