SimpleChatTCRV:UICleanup:Ai Reasoning/Live response

Implement todo noted in last commit, and bit more.

This brings in clearing of the external ai tool call special chat
session divStream during chat show, which ensures that it gets
hidden by default wrt other chat sessions and inturn only get
enabled if user triggers a new tool call involving external ai
tool call.

This patch also ensures that if ext ai tool call takes too much
time and so logic gives you back control with a timed out response
as a possible response back to ai wrt the tool call, then the
external ai tool call's ai live response is no longer visible in
the current chat session ui. So user can go ahead with the timed
out response or some other user decided response as the response
to the tool call. And take the chat in a different direction of
their and ai's choosing.

Or else, if they want to they can switch to the External Ai
specific special chat session and continue to monitor the response
from the tool call there, to understand what the final response
would have been wrt that tool call.

Rather this should keep the ui flow clean.

ALERT: If the user triggers a new ext ai tool call, when the
old one is still alive in the background, then response from
both will be in a race for user visibility, so beware of it.
This commit is contained in:
hanishkvc 2025-11-29 04:42:20 +05:30
parent 29f9abede9
commit 2981033fac
3 changed files with 37 additions and 0 deletions

View File

@ -307,6 +307,11 @@ Chat Session specific settings
* tables, fenced code blocks, blockquotes
* User given control to enable markdown implicitly at a session level, or explicitly set wrt individual msgs.
* Rename fetch_web_url_raw to fetch_url_raw, avoids confusion and matchs semantic of access to local and web.
* Now external_ai specific special chat session's and inturn external ai tool call's ai live response stream
is visible in the chat session which triggered external ai, only till one gets respose or the tool call times
out. In turn if the tool call times out, one can send the timeout message as the response to the tool call
or what ever they see fit. Parallely, they can always look into the external ai specific special chat session
tab to see the ai response live stream and the progress wrt the tool call that timed out.
## ToDo

View File

@ -537,6 +537,8 @@ class ELDivStream {
});
elDiv.appendChild(elDivData)
this.divData = elDivData
/** @type {string | undefined} */
this.styleDisplay = ui.ss_get(0, '.chat-message', 'display')
}
/**
@ -545,6 +547,9 @@ class ELDivStream {
show() {
this.div.hidden = false
this.div.style.visibility = "visible"
if (this.styleDisplay) {
this.div.style.display = this.styleDisplay
}
}
/**
@ -556,6 +561,7 @@ class ELDivStream {
this.divData.replaceChildren()
this.div.hidden = true
this.div.style.visibility = "collapse"
this.div.style.display = "none"
}
}
@ -1621,6 +1627,7 @@ class MultiChatUI {
this.elDivChat.replaceChildren();
this.ui_userinput_reset()
this.elDivStreams[chatId]?.clear()
this.elDivStreams[AI_TC_SESSIONNAME].clear()
}
if (bShowOwnDivStream) {
this.elDivStreams[chatId]?.show()
@ -1862,6 +1869,9 @@ class MultiChatUI {
this.elPopoverChatMsg.addEventListener('beforetoggle', (tev)=>{
let chatSession = this.simpleChats[this.curChatId]
let index = chatSession.get_chatmessage_index(this.uniqIdChatMsgPO)
if (index == -1) {
return
}
let chat = chatSession.xchat[index]
if (chat.ns.has_content()) {
this.elPopoverChatMsgFormatSelect.value = chat.textFormat
@ -2021,6 +2031,7 @@ class MultiChatUI {
this.chatmsg_addsmart_uishow(chat.chatId, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, toolResult)))
} else {
this.timers.toolcallResponseTimeout = setTimeout(() => {
this.elDivStreams[AI_TC_SESSIONNAME].clear()
this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut')
this.chatmsg_addsmart_uishow(chat.chatId, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`)))
}, chat.cfg.tools.toolCallResponseTimeoutMS)

View File

@ -374,3 +374,24 @@ export function remove_els(sSelectorsTemplate) {
el?.remove()
}
}
/**
* Get value of specified property belonging to specified css rule and stylesheet.
* @param {number} ssIndex
* @param {string} selectorText
* @param {string} property
*/
export function ss_get(ssIndex, selectorText, property) {
for (const rule of document.styleSheets[ssIndex].cssRules) {
if (rule.constructor.name == "CSSStyleRule") {
let sr = /** @type {CSSStyleRule} */(rule)
if (sr.selectorText.trim() != selectorText) {
continue
}
// @ts-ignore
return sr.style[property]
}
}
return undefined
}