fix: isEdited edge case where latest Message is not saved due to aborting too quickly

This commit is contained in:
Danny Avila 2023-08-25 09:29:19 -04:00 committed by Danny Avila
parent ae5c06f381
commit 39c626aa8e

View file

@ -412,8 +412,21 @@ class BaseClient {
// depending on subclass implementation of handling messages // depending on subclass implementation of handling messages
// When this is an edit, all messages are already in currentMessages, both user and response // When this is an edit, all messages are already in currentMessages, both user and response
if (isEdited) { if (isEdited) {
/* TODO: edge case where latest message doesn't exist */ let latestMessage = this.currentMessages[this.currentMessages.length - 1];
this.currentMessages[this.currentMessages.length - 1].text = generation; if (!latestMessage) {
latestMessage = {
messageId: responseMessageId,
conversationId,
parentMessageId: userMessage.messageId,
isCreatedByUser: false,
model: this.modelOptions.model,
sender: this.sender,
text: generation,
};
this.currentMessages.push(userMessage, latestMessage);
} else {
latestMessage.text = generation;
}
} else { } else {
this.currentMessages.push(userMessage); this.currentMessages.push(userMessage);
} }