Skip to content

Commit d86bcc5

Browse files
committed
SimpleChatTC:ToolTemp: Ensure add removes non promoted ToolTemp
1 parent efdce1b commit d86bcc5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/server/public_simplechat/simplechat.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,21 @@ class SimpleChat {
407407

408408
/**
409409
* Add an entry into xchat.
410+
* If the last message in chat history is a ToolTemp message, discard it
411+
* as the runtime logic is asking for adding new message instead of promoting the tooltemp message.
412+
*
410413
* NOTE: A new copy is created and added into xchat.
411414
* Also update iLastSys system prompt index tracker
412415
* @param {ChatMessageEx} chatMsg
413416
*/
414417
add(chatMsg) {
418+
if (this.xchat.length > 0) {
419+
let lastIndex = this.xchat.length - 1;
420+
if (this.xchat[lastIndex].ns.role == Roles.ToolTemp) {
421+
console.debug("DBUG:SimpleChat:Add:Discarding prev ToolTemp message...")
422+
this.xchat.pop()
423+
}
424+
}
415425
this.xchat.push(ChatMessageEx.newFrom(chatMsg));
416426
if (chatMsg.ns.role == Roles.System) {
417427
this.iLastSys = this.xchat.length - 1;

0 commit comments

Comments
 (0)