SimpleChatTC:ChatMessageEx: RecentChat, GetSystemLatest

GetSystemLatest and its users updated wrt ChatMessageEx.

RecentChat updated wrt ChatMessageEx. Also now irrespective of
whether full history is being retrieved or only a subset, both
cases refer to the ChatMessageEx instances in SimpleChat.xchat
without creating new instances of anything.
This commit is contained in:
hanishkvc 2025-10-14 19:33:24 +05:30
parent 343d414dd3
commit c65c1d5f0f
1 changed files with 9 additions and 10 deletions

View File

@ -248,8 +248,8 @@ class SimpleChat {
/** @type{ChatMessages} */ /** @type{ChatMessages} */
let rchat = []; let rchat = [];
let sysMsg = this.get_system_latest(); let sysMsg = this.get_system_latest();
if (sysMsg.length != 0) { if (sysMsg.ns.content.length != 0) {
rchat.push({role: Roles.System, content: sysMsg}); rchat.push(sysMsg)
} }
let iUserCnt = 0; let iUserCnt = 0;
let iStart = this.xchat.length; let iStart = this.xchat.length;
@ -258,17 +258,17 @@ class SimpleChat {
break; break;
} }
let msg = this.xchat[i]; let msg = this.xchat[i];
if (msg.role == Roles.User) { if (msg.ns.role == Roles.User) {
iStart = i; iStart = i;
iUserCnt += 1; iUserCnt += 1;
} }
} }
for(let i = iStart; i < this.xchat.length; i++) { for(let i = iStart; i < this.xchat.length; i++) {
let msg = this.xchat[i]; let msg = this.xchat[i];
if (msg.role == Roles.System) { if (msg.ns.role == Roles.System) {
continue; continue;
} }
rchat.push({role: msg.role, content: msg.content}); rchat.push(msg)
} }
return rchat; return rchat;
} }
@ -453,10 +453,9 @@ class SimpleChat {
*/ */
get_system_latest() { get_system_latest() {
if (this.iLastSys == -1) { if (this.iLastSys == -1) {
return ""; return new ChatMessageEx(Roles.System);
} }
let sysPrompt = this.xchat[this.iLastSys].ns.content; return this.xchat[this.iLastSys];
return sysPrompt;
} }
@ -882,7 +881,7 @@ class MultiChatUI {
console.error(`ERRR:SimpleChat:MCUI:HandleSessionSwitch:${chatId} missing...`); console.error(`ERRR:SimpleChat:MCUI:HandleSessionSwitch:${chatId} missing...`);
return; return;
} }
this.elInSystem.value = chat.get_system_latest(); this.elInSystem.value = chat.get_system_latest().ns.content;
this.elInUser.value = ""; this.elInUser.value = "";
chat.show(this.elDivChat); chat.show(this.elDivChat);
this.elInUser.focus(); this.elInUser.focus();
@ -959,7 +958,7 @@ class Me {
chat.load(); chat.load();
queueMicrotask(()=>{ queueMicrotask(()=>{
chat.show(div); chat.show(div);
this.multiChat.elInSystem.value = chat.get_system_latest(); this.multiChat.elInSystem.value = chat.get_system_latest().ns.content;
}); });
}); });
div.appendChild(btn); div.appendChild(btn);