From 47b7df4fc3fc25ec99859988d2de393043a2ff1d Mon Sep 17 00:00:00 2001
From: Timothy Carambat <rambat1010@gmail.com>
Date: Wed, 1 May 2024 20:39:58 -0700
Subject: [PATCH] Clear chat window on `/reset` (#1261)

clear chat window on /reset
---
 frontend/src/utils/chat/index.js     | 7 +++++++
 server/utils/chats/commands/reset.js | 1 +
 2 files changed, 8 insertions(+)

diff --git a/frontend/src/utils/chat/index.js b/frontend/src/utils/chat/index.js
index a2b18c7f4..c5730dbe0 100644
--- a/frontend/src/utils/chat/index.js
+++ b/frontend/src/utils/chat/index.js
@@ -17,6 +17,7 @@ export default function handleChat(
     error,
     close,
     chatId = null,
+    action = null,
   } = chatResult;
 
   if (type === "abort" || type === "statusResponse") {
@@ -132,6 +133,12 @@ export default function handleChat(
     setChatHistory([..._chatHistory]);
     setLoadingResponse(false);
   }
+
+  // Action Handling via special 'action' attribute on response.
+  if (action === "reset_chat") {
+    // Chat was reset, keep reset message and clear everything else.
+    setChatHistory([_chatHistory.pop()]);
+  }
 }
 
 export function chatPrompt(workspace) {
diff --git a/server/utils/chats/commands/reset.js b/server/utils/chats/commands/reset.js
index a23eef7aa..f2bd4562c 100644
--- a/server/utils/chats/commands/reset.js
+++ b/server/utils/chats/commands/reset.js
@@ -23,6 +23,7 @@ async function resetMemory(
     sources: [],
     close: true,
     error: false,
+    action: "reset_chat",
   };
 }
 
-- 
GitLab