SimpleChatTCRV:UICleanup: Use chat_uirefresh not chat_show

Rename chatmsg_ui_refresh to chat_uirefresh.

Even in case of the delete path and inturn deleting one of the last
two messages in a chat session, now use the generified chat uirefresh
logic instead of the chat_show full session refresh / recreation of
the session ui

Inturn to make the uirefresh really generic and usable in all cases
including above case, now take care of clearing the tool call edit
/ trigger at the beginning, so that the last 2 messages decide in
turn whether to show a tool call edit/trigger ui or not, as well as
the tool call response edit / submit ui.
This commit is contained in:
hanishkvc 2025-11-16 14:05:57 +05:30
parent dda9f81d37
commit 511fcb0016
2 changed files with 22 additions and 16 deletions

View File

@ -771,6 +771,15 @@ sliding window based drop off or even before they kick in, this can help in many
chat session ui without recreating the full chat session ui. 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 * 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. ui by appending the chat message, instead of recreating the full chat session ui.
...
* MultiChatUI+
* both chat_show and chat_uirefresh (if lastN >= 2) both take care of updating tool call edit/trigger
as well as the tool call response edit/submit related ui elements suitably.
* chat_show recreates currently active sliding window of chat session (which could even be full)
* while chat_uirefresh recreates/updates ui only for the lastN messages (prefer in general, as optimal)
* normal user response / query submit as well as tool call response or error submit have been updated
to use the optimal uirefresh logic now.
#### ToDo #### ToDo
@ -792,16 +801,13 @@ same when saved chat is loaded.
MAYBE make the settings in general chat session specific, rather than the current global config flow. MAYBE make the settings in general chat session specific, rather than the current global config flow.
Have a seperate helper to show the user input area, based on set state. And have support for multiple images Have a seperate helper to show the user input area, based on set state. And have support for multiple images
if the models support same. if the models support same. It should also take care of some aspects of the tool call response edit / submit,
potentially.
Make chat show messages by default only appends new chat messages to existing list of shown messages in ui, Make chat show messages by default only appends new chat messages to existing list of shown messages in ui,
instead of clearing ui and recreating each message ui element again. Have forgotten what I had originally instead of clearing ui and recreating each message ui element again. Have forgotten what I had originally
implemented, need to cross check. implemented, need to cross check.
The ui update helpers should call the tool call edit/trigger ui reset logic.
With the new optimized limited ui update based flow, avoid duplicate chat message ui blocks.
Show a loading message, when a previously saved chat session is being loaded. Show a loading message, when a previously saved chat session is being loaded.

View File

@ -1397,19 +1397,18 @@ class MultiChatUI {
* OR ELSE * OR ELSE
* appending new ui block wrt that given message. * appending new ui block wrt that given message.
* *
* Also tool call edit/trigger/submit ui will be handled as needed, * Also tool call & response edit/trigger/submit ui will be
* provided lastN is atleast 2. * updated as needed, provided lastN is atleast 2.
* *
* @param {string} chatId * @param {string} chatId
* @param {number} lastN * @param {number} lastN
*/ */
chatmsg_ui_refresh(chatId, lastN=2) { chat_uirefresh(chatId, lastN=2) {
let chat = this.simpleChats[chatId]; let chat = this.simpleChats[chatId];
if (chat.chatId != this.curChatId) { if (chat.chatId != this.curChatId) {
return false return false
} }
// TODO: MAYBE: Call toolcall related ui reset here. this.ui_reset_toolcall_as_needed(new ChatMessageEx());
//this.ui_reset_toolcall_as_needed(new ChatMessageEx());
for(let i=lastN; i > 0; i-=1) { for(let i=lastN; i > 0; i-=1) {
let msg = chat.xchat[chat.xchat.length-i] let msg = chat.xchat[chat.xchat.length-i]
let nextMsg = chat.xchat[chat.xchat.length-(i-1)] let nextMsg = chat.xchat[chat.xchat.length-(i-1)]
@ -1437,7 +1436,7 @@ class MultiChatUI {
return { added: false, shown: false } return { added: false, shown: false }
} }
chat.add_smart(msg) chat.add_smart(msg)
return { added: true, shown: this.chatmsg_ui_refresh(chat.chatId) } return { added: true, shown: this.chat_uirefresh(chat.chatId) }
} }
/** /**
@ -1451,9 +1450,10 @@ class MultiChatUI {
if ((index >= 0) && (curChatId == this.curChatId) && bUpdateUI) { if ((index >= 0) && (curChatId == this.curChatId) && bUpdateUI) {
this.chatmsg_ui_remove(uniqIdChatMsg) this.chatmsg_ui_remove(uniqIdChatMsg)
if (index >= (this.simpleChats[curChatId].xchat.length-1)) { if (index >= (this.simpleChats[curChatId].xchat.length-1)) {
// so that tool call edit/trigger control etal can be controlled suitably // so that tool call edit/trigger and tool call response/submit
// from a single place - need to add that centrally controlled logic flor still. // ui / control etal can be suitably adjusted, force a refresh
this.chat_show(curChatId) // of the ui wrt the currently last two messages.
this.chat_uirefresh(curChatId)
} }
} }
} }
@ -1618,7 +1618,7 @@ class MultiChatUI {
let content = this.elInUser.value; let content = this.elInUser.value;
if (this.elInUser.dataset.role == Roles.ToolTemp) { if (this.elInUser.dataset.role == Roles.ToolTemp) {
chat.promote_tooltemp(content) chat.promote_tooltemp(content)
this.chatmsg_ui_refresh(chat.chatId) this.chat_uirefresh(chat.chatId)
} else { } else {
if (content.trim() == "") { if (content.trim() == "") {
this.elInUser.placeholder = "dont forget to enter a message, before submitting to ai" this.elInUser.placeholder = "dont forget to enter a message, before submitting to ai"
@ -1650,7 +1650,7 @@ class MultiChatUI {
try { try {
let theResp = await chat.handle_chat_hs(this.me.baseURL, apiEP, this.elDivChat) let theResp = await chat.handle_chat_hs(this.me.baseURL, apiEP, this.elDivChat)
if (chatId == this.curChatId) { if (chatId == this.curChatId) {
this.chatmsg_ui_refresh(chatId); this.chat_uirefresh(chatId);
if ((theResp.trimmedContent) && (theResp.trimmedContent.length > 0)) { if ((theResp.trimmedContent) && (theResp.trimmedContent.length > 0)) {
let p = ui.el_create_append_p(`TRIMMED:${theResp.trimmedContent}`, this.elDivChat); let p = ui.el_create_append_p(`TRIMMED:${theResp.trimmedContent}`, this.elDivChat);
p.className="role-trim"; p.className="role-trim";