diff --git a/src/interface/desktop/assets/icons/trash-solid.svg b/src/interface/desktop/assets/icons/trash-solid.svg new file mode 100644 index 00000000..768d80f8 --- /dev/null +++ b/src/interface/desktop/assets/icons/trash-solid.svg @@ -0,0 +1 @@ + diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index 4997ef99..8b77fe22 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -377,6 +377,32 @@ chat(); } } + + async function clearConversationHistory() { + let chatInput = document.getElementById("chat-input"); + let originalPlaceholder = chatInput.placeholder; + let chatBody = document.getElementById("chat-body"); + + const hostURL = await window.hostURLAPI.getURL(); + const khojToken = await window.tokenAPI.getToken(); + const headers = { 'Authorization': `Bearer ${khojToken}` }; + + fetch(`${hostURL}/api/chat/history?client=desktop`, { method: "DELETE", headers }) + .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); + }); + }