Skip to content

Commit fac185d

Browse files
committed
SimpleChatTC:MultiChatUI:ChatShow cleanup of Initial skeleton
Fix up the initial skeleton / logic as needed. Remember that we are working with potentially a subset of chat messages from the session, given the sliding window logic of context managing on client ui side, so fix up the logic to use the right subset of messages array and not the global xchat when deciding whether a message is the last or last but one, which need special handling wrt Assistant (with toolcall) and Tool (ie response) messages. Moving tool call ui setup as well as tool call response got ui setup into ChatShow of MultiChatUI ensures that switching between chat sessions handle the ui wrt tool call triggering ui and tool call response submission related ui as needed properly. Rather even loading a previously auto saved chat session if it had tool call or tool call response to be handled, the chat ui will be setup as needed to continue that session properly.
1 parent 581280e commit fac185d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

tools/server/public_simplechat/simplechat.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ class SimpleChat {
353353

354354
/**
355355
* Recent chat messages.
356-
* If iRecentUserMsgCnt < 0
357-
* Then return the full chat history
358-
* Else
359-
* Return chat messages from latest going back till the last/latest system prompt.
360-
* While keeping track that the number of user queries/messages doesnt exceed iRecentUserMsgCnt.
356+
*
357+
* If iRecentUserMsgCnt < 0, Then return the full chat history
358+
*
359+
* Else Return chat messages from latest going back till the last/latest system prompt.
360+
* While keeping track that the number of user queries/messages doesnt exceed iRecentUserMsgCnt.
361361
* @param {number} iRecentUserMsgCnt
362362
*/
363363
recent_chat(iRecentUserMsgCnt) {
@@ -890,18 +890,30 @@ class MultiChatUI {
890890
this.ui_reset_toolcall_as_needed(new ChatMessageEx());
891891
}
892892
let last = undefined;
893-
for(const [i, x] of chat.recent_chat(gMe.chatProps.iRecentUserMsgCnt).entries()) {
893+
let chatToShow = chat.recent_chat(gMe.chatProps.iRecentUserMsgCnt);
894+
for(const [i, x] of chatToShow.entries()) {
894895
if (x.ns.role === Roles.ToolTemp) {
895-
if (i == (chat.xchat.length - 1)) {
896+
if (i == (chatToShow.length - 1)) {
896897
this.elInUser.value = x.ns.content;
897898
}
898899
continue
899900
}
900901
let entry = ui.el_create_append_p(`${x.ns.role}: ${x.content_equiv()}`, this.elDivChat);
901902
entry.className = `role-${x.ns.role}`;
902903
last = entry;
903-
if (x.ns.role === Roles.Tool) {
904-
this.ui_reset_toolcall_as_needed(x);
904+
if (x.ns.role === Roles.Assistant) {
905+
let bTC = false
906+
if (i == (chatToShow.length-1)) {
907+
bTC = true
908+
}
909+
if (i == (chatToShow.length-2)) {
910+
if (chatToShow[i+1].ns.role == Roles.ToolTemp) {
911+
bTC = true
912+
}
913+
}
914+
if (bTC) {
915+
this.ui_reset_toolcall_as_needed(x);
916+
}
905917
}
906918
}
907919
if (last !== undefined) {

0 commit comments

Comments
 (0)