diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index 1c661a92..d1b85cd3 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -322,7 +322,9 @@ To get started, just start typing below. You can also type / to see a list of co document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight; } - window.onload = function () { + window.onload = loadChat; + + function loadChat() { fetch('/api/chat/history?client=web') .then(response => response.json()) .then(data => { @@ -369,6 +371,28 @@ To get started, just start typing below. You can also type / to see a list of co chat(); } } + + function clearConversationHistory() { + let chatInput = document.getElementById("chat-input"); + let originalPlaceholder = chatInput.placeholder; + let chatBody = document.getElementById("chat-body"); + + fetch(`/api/chat/history?client=web`, { method: "DELETE" }) + .then(response => response.ok ? response.json() : Promise.reject(response)) + .then(data => { + chatBody.innerHTML = ""; + loadChat(); + chatInput.placeholder = "Cleared conversation history"; + }) + .catch(err => { + chatInput.placeholder = "Failed to clear conversation history"; + }) + .finally(() => { + setTimeout(() => { + chatInput.placeholder = originalPlaceholder; + }, 2000); + }); + }