Skip to content

Commit 39c626a

Browse files
committed
fix: isEdited edge case where latest Message is not saved due to aborting too quickly
1 parent ae5c06f commit 39c626a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

api/app/clients/BaseClient.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,21 @@ class BaseClient {
412412
// depending on subclass implementation of handling messages
413413
// When this is an edit, all messages are already in currentMessages, both user and response
414414
if (isEdited) {
415-
/* TODO: edge case where latest message doesn't exist */
416-
this.currentMessages[this.currentMessages.length - 1].text = generation;
415+
let latestMessage = this.currentMessages[this.currentMessages.length - 1];
416+
if (!latestMessage) {
417+
latestMessage = {
418+
messageId: responseMessageId,
419+
conversationId,
420+
parentMessageId: userMessage.messageId,
421+
isCreatedByUser: false,
422+
model: this.modelOptions.model,
423+
sender: this.sender,
424+
text: generation,
425+
};
426+
this.currentMessages.push(userMessage, latestMessage);
427+
} else {
428+
latestMessage.text = generation;
429+
}
417430
} else {
418431
this.currentMessages.push(userMessage);
419432
}

0 commit comments

Comments
 (0)