SimpleChatTCRV:DivStreams: Prepared for switching in middle

Missing DivStream caught. Logic ready for a distant future,
where one may allow the chat session to be switched even
if there is a pending ai server / tool call response.

Avoids the unneeded removeChild before calling appendChild.

Also found the reason why sometimes the DivStream was missing
from DivChat. Rather when I switched from the transient <p>
element to the persistant session specific <div> elements,
I had forgotten to convert the flow fully, rather I had
forgotten to replace the elP.remove() with elP.replaceChildren

Also retaining that debug log wrt missing DivStream path, Just
in case for now, to cross check once later, I havent missed
any other path.
This commit is contained in:
hanishkvc 2025-11-22 04:38:30 +05:30
parent 5a1eaf94bf
commit d5e5d58d85
2 changed files with 13 additions and 7 deletions

View File

@ -467,6 +467,10 @@ The following tools/functions are currently provided by default
* helps ai to process stuff that it needs, without having to worry about any previous chat history
etal messing with the current data's processing.
* helps ai to process stuff with targeted system prompts of its choosing, for the job at hand.
* tool calling is disabled wrt the external_ai's independent session, for now.
* it was noticed that else even the external_ai may call into more external_ai calls trying to
find answer to the same question. maybe one can enable tool calling, while explicitly disabling
external_ai tool call from within external_ai tool call or so ...
* Could be used by ai for example to
* summarise a large text content, where it could use the context of the text to generate a
suitable system prompt for summarising things suitably
@ -854,6 +858,11 @@ Cleanup in general
* Use popover ui to allow user to view larger versions of loaded images as well as remove before submitting
to ai, if and when needed.
* add external_ai toolcall
* maintain chat session specific DivStream elements, so that in future, if the logic is updated to allow
switching in the middle of a pending tool call or pending ai server response, things dont mess up wrt
ui, as they will be updating their respective DivStream and switching sessions will also take care of
making the right DivStream the currently active one, so that end user can see the streamed response
as it is occuring.
#### ToDo

View File

@ -919,7 +919,7 @@ class SimpleChat {
}
}
} finally {
elP.remove()
elP.replaceChildren()
}
console.debug("DBUG:SC:PART:Full:", this.latestResponse.content_equiv());
return ChatMessageEx.newFrom(this.latestResponse);
@ -1509,13 +1509,10 @@ class MultiChatUI {
this.show_message(this.elDivChat, msg, (i-1), nextMsg)
}
}
try {
this.elDivChat.removeChild(this.elDivStreams[chatId])
} catch {
console.log(`DBUG:SimpleChat:MCUI:UiRefresh:Removing ${chatId} DivStream ${this.elDivStreams[chatId].id} failed...`)
} finally {
this.elDivChat.appendChild(this.elDivStreams[chatId])
if (!this.elDivChat.contains(this.elDivStreams[chatId])) {
console.log(`DBUG:SimpleChat:MCUI:UiRefresh:${chatId}: DivStream ${this.elDivStreams[chatId].id} missing...`)
}
this.elDivChat.appendChild(this.elDivStreams[chatId])
if (this.elLastChatMessage != null) {
this.scroll_el_into_view(this.elLastChatMessage)
}