From ae60b2a7989a96cf3477d7d7e44770fce7901020 Mon Sep 17 00:00:00 2001 From: Jason Laster Date: Fri, 21 Mar 2025 12:43:53 -0700 Subject: [PATCH] Fix lint issues --- app/components/chat/Chat.client.tsx | 3 +++ app/lib/replay/SimulationPrompt.ts | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 14c8e737..2052d342 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -343,6 +343,7 @@ export const ChatImpl = memo( // Update the repository as soon as it has changed. const responseRepositoryId = getMessagesRepositoryId(newMessages); + if (responseRepositoryId && existingRepositoryId != responseRepositoryId) { simulationRepositoryUpdated(responseRepositoryId); updatedRepository = true; @@ -467,10 +468,12 @@ export const ChatImpl = memo( // Erase all messages since the last user message. let rewindMessageId = message.id; + for (let i = messages.length - 2; i >= 0; i--) { if (messages[i].role == 'user') { break; } + rewindMessageId = messages[i].id; } await onRewind(rewindMessageId); diff --git a/app/lib/replay/SimulationPrompt.ts b/app/lib/replay/SimulationPrompt.ts index 4b7ab280..19d4e55e 100644 --- a/app/lib/replay/SimulationPrompt.ts +++ b/app/lib/replay/SimulationPrompt.ts @@ -47,8 +47,8 @@ class ChatManager { pageData: SimulationData = []; // State to ensure that the chat manager is not destroyed until all messages finish. - private pendingMessages = 0; - private mustDestroyAfterChatFinishes = false; + private _pendingMessages = 0; + private _mustDestroyAfterChatFinishes = false; constructor() { this.client = new ProtocolClient(); @@ -69,16 +69,16 @@ class ChatManager { return !!this.client; } - private destroy() { + private _destroy() { this.client?.close(); this.client = undefined; } destroyAfterChatFinishes() { - if (this.pendingMessages == 0) { - this.destroy(); + if (this._pendingMessages == 0) { + this._destroy(); } else { - this.mustDestroyAfterChatFinishes = true; + this._mustDestroyAfterChatFinishes = true; } } @@ -141,7 +141,7 @@ class ChatManager { async sendChatMessage(messages: Message[], references: ChatReference[], onResponsePart: ChatResponsePartCallback) { assert(this.client, 'Chat has been destroyed'); - this.pendingMessages++; + this._pendingMessages++; const responseId = `response-${generateRandomId()}`; @@ -168,8 +168,8 @@ class ChatManager { removeResponseListener(); - if (--this.pendingMessages == 0 && this.mustDestroyAfterChatFinishes) { - this.destroy(); + if (--this._pendingMessages == 0 && this._mustDestroyAfterChatFinishes) { + this._destroy(); } } } @@ -178,9 +178,11 @@ class ChatManager { let gChatManager: ChatManager | undefined; function startChat(repositoryId: string | undefined, pageData: SimulationData) { - // Any existing chat manager won't be used anymore for new messages, but it will - // not close until its messages actually finish and any future repository updates - // occur. + /* + * Any existing chat manager won't be used anymore for new messages, but it will + * not close until its messages actually finish and any future repository updates + * occur. + */ if (gChatManager) { gChatManager.destroyAfterChatFinishes(); }