Skip to content

Commit 581280e

Browse files
committed
SimpleChatTC:MultiChatUI.ChatShow: Mov SimpleChat.Show in -initial
Also take care of updating the toolcall ui if needed from within this.
1 parent 4d79c29 commit 581280e

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

tools/server/public_simplechat/simplechat.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class SimpleChat {
488488
* @param {boolean} bClear
489489
* @param {boolean} bShowInfoAll
490490
*/
491-
show(div, elInUser, bClear=true, bShowInfoAll=false) {
491+
showTOREMOVE(div, elInUser, bClear=true, bShowInfoAll=false) {
492492
if (bClear) {
493493
div.replaceChildren();
494494
}
@@ -865,6 +865,17 @@ class MultiChatUI {
865865

866866
/**
867867
* Refresh UI wrt given chatId, provided it matches the currently selected chatId
868+
*
869+
* Show the chat contents in elDivChat.
870+
* Also update
871+
* * the user query input box, with ToolTemp role message, if last one.
872+
* * the tool call trigger ui, with Tool role message, if last one.
873+
*
874+
* If requested to clear prev stuff and inturn no chat content then show
875+
* * usage info
876+
* * option to load prev saved chat if any
877+
* * as well as settings/info.
878+
*
868879
* @param {string} chatId
869880
* @param {boolean} bClear
870881
* @param {boolean} bShowInfoAll
@@ -874,7 +885,34 @@ class MultiChatUI {
874885
return false
875886
}
876887
let chat = this.simpleChats[this.curChatId];
877-
chat.show(this.elDivChat, this.elInUser, bClear, bShowInfoAll)
888+
if (bClear) {
889+
this.elDivChat.replaceChildren();
890+
this.ui_reset_toolcall_as_needed(new ChatMessageEx());
891+
}
892+
let last = undefined;
893+
for(const [i, x] of chat.recent_chat(gMe.chatProps.iRecentUserMsgCnt).entries()) {
894+
if (x.ns.role === Roles.ToolTemp) {
895+
if (i == (chat.xchat.length - 1)) {
896+
this.elInUser.value = x.ns.content;
897+
}
898+
continue
899+
}
900+
let entry = ui.el_create_append_p(`${x.ns.role}: ${x.content_equiv()}`, this.elDivChat);
901+
entry.className = `role-${x.ns.role}`;
902+
last = entry;
903+
if (x.ns.role === Roles.Tool) {
904+
this.ui_reset_toolcall_as_needed(x);
905+
}
906+
}
907+
if (last !== undefined) {
908+
last.scrollIntoView(false);
909+
} else {
910+
if (bClear) {
911+
this.elDivChat.innerHTML = gUsageMsg;
912+
gMe.setup_load(this.elDivChat, chat);
913+
gMe.show_info(this.elDivChat, bShowInfoAll);
914+
}
915+
}
878916
return true
879917
}
880918

@@ -1040,7 +1078,6 @@ class MultiChatUI {
10401078
} else {
10411079
console.debug(`DBUG:SimpleChat:MCUI:HandleUserSubmit:ChatId has changed:[${chatId}] [${this.curChatId}]`);
10421080
}
1043-
this.ui_reset_toolcall_as_needed(theResp);
10441081
this.ui_reset_userinput();
10451082
}
10461083

@@ -1250,7 +1287,7 @@ class Me {
12501287
console.log("DBUG:SimpleChat:SC:Load", chat);
12511288
chat.load();
12521289
queueMicrotask(()=>{
1253-
chat.show(div, this.multiChat.elInUser, true, true);
1290+
this.multiChat.chat_show(chat.chatId, true, true);
12541291
this.multiChat.elInSystem.value = chat.get_system_latest().ns.content;
12551292
});
12561293
});

0 commit comments

Comments
 (0)