Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

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

Danny Avila39c626aa8e6c
diff --git a/api/app/clients/BaseClient.js b/api/app/clients/BaseClient.js
index ea1f9c0dab..ec4344bb46 100644
--- a/api/app/clients/BaseClient.js
+++ b/api/app/clients/BaseClient.js
@@ -412,8 +412,21 @@ class BaseClient {
// depending on subclass implementation of handling messages
// When this is an edit, all messages are already in currentMessages, both user and response
if (isEdited) {
- /* TODO: edge case where latest message doesn't exist */
- this.currentMessages[this.currentMessages.length - 1].text = generation;
+ let latestMessage = this.currentMessages[this.currentMessages.length - 1];
+ 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 {
this.currentMessages.push(userMessage);
}