diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index 54ecf480..f4e35131 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -48,6 +48,8 @@ To get started, just start typing below. You can also type / to see a list of co }); } var websocket = null; + var timeout = null; + var timeoutDuration = 600000; // 10 minutes let region = null; let city = null; @@ -861,12 +863,26 @@ To get started, just start typing below. You can also type / to see a list of co rawResponse: "", } + function resetTimeout() { + if (timeout) { + clearTimeout(timeout); + } + + timeout = setTimeout(function() { + if (websocket) { + websocket.close(); + } + }, timeoutDuration); + } + if (chatBody.dataset.conversationId) { webSocketUrl += `?conversation_id=${chatBody.dataset.conversationId}`; webSocketUrl += `®ion=${region}&city=${city}&country=${countryName}`; websocket = new WebSocket(webSocketUrl); websocket.onmessage = function(event) { + resetTimeout(); + // Get the last element in the chat-body let chunk = event.data; if (chunk == "start_llm_response") { @@ -952,6 +968,8 @@ To get started, just start typing below. You can also type / to see a list of co let greenDot = document.getElementById("connected-green-dot"); greenDot.style.display = "flex"; + // Setup the timeout to close the connection after inactivity. + resetTimeout(); } }