From 4d5d3e6433e2e8abb832ca995ded08b1f07a4408 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 23 Apr 2024 10:58:04 +0530 Subject: [PATCH 1/4] Set chat-message height to height of content in web, desktop In some cases, especially with image generation requests, this was causing the chat messages to overlap in the chat UI --- src/interface/desktop/chat.html | 2 ++ src/khoj/interface/web/chat.html | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index 2835f01d..e75effdb 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -1395,11 +1395,13 @@ .chat-message.khoj { margin-left: auto; text-align: left; + height: fit-content; } /* move message by you to right */ .chat-message.you { margin-right: auto; text-align: right; + height: fit-content; } /* basic style chat message text */ .chat-message-text { diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index 4ede4080..0d624713 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -2055,11 +2055,13 @@ To get started, just start typing below. You can also type / to see a list of co .chat-message.khoj { margin-left: auto; text-align: left; + height: fit-content; } /* move message by you to right */ .chat-message.you { margin-right: auto; text-align: right; + height: fit-content; } /* basic style chat message text */ .chat-message-text { From cd05f262a6a45d5c814d6fedf0535a31cccb9d4c Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 23 Apr 2024 10:59:49 +0530 Subject: [PATCH 2/4] Pass auth headers to fix lazy load of chat messages on Desktop app --- src/interface/desktop/chat.html | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index e75effdb..9dbcf908 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -675,28 +675,35 @@ await loadChat(); }); - async function loadChat() { - // Load chat history + async function getChatHistoryUrl() { const hostURL = await window.hostURLAPI.getURL(); const khojToken = await window.tokenAPI.getToken(); const headers = { 'Authorization': `Bearer ${khojToken}` }; - let firstRunSetupMessageRendered = false; let chatBody = document.getElementById("chat-body"); chatBody.innerHTML = ""; let chatHistoryUrl = `${hostURL}/api/chat/history?client=desktop`; if (chatBody.dataset.conversationId) { chatHistoryUrl += `&conversation_id=${chatBody.dataset.conversationId}`; } + return { chatHistoryUrl, headers }; + } + + async function loadChat() { + // Load chat history and body + const hostURL = await window.hostURLAPI.getURL(); + const { chatHistoryUrl, headers } = await getChatHistoryUrl(); // Create loading screen and add it to chat-body let loadingScreen = document.createElement('div'); loadingScreen.classList.add("loading-spinner"); let yellowOrb = document.createElement('div'); loadingScreen.appendChild(yellowOrb); + let chatBody = document.getElementById("chat-body"); chatBody.appendChild(loadingScreen); // Get the most recent 10 chat messages from conversation history + let firstRunSetupMessageRendered = false; fetch(`${chatHistoryUrl}&n=10`, { headers }) .then(response => response.json()) .then(data => { @@ -722,7 +729,7 @@ entries.forEach(entry => { // If the element is in the viewport, fetch the remaining message and unobserve the element if (entry.isIntersecting) { - fetchRemainingChatMessages(chatHistoryUrl); + fetchRemainingChatMessages(chatHistoryUrl, headers); observer.unobserve(entry.target); } }); @@ -817,7 +824,7 @@ } } - function fetchRemainingChatMessages(chatHistoryUrl) { + function fetchRemainingChatMessages(chatHistoryUrl, headers) { // Create a new IntersectionObserver let observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { @@ -842,7 +849,7 @@ }, {rootMargin: '0px 0px 200px 0px'}); // Trigger when the element is within 200px of the viewport // Fetch remaining chat messages from conversation history - fetch(`${chatHistoryUrl}&n=-10`, { method: "GET" }) + fetch(`${chatHistoryUrl}&n=-10`, { headers }) .then(response => response.json()) .then(data => { if (data.status != "ok") { From 5def14e3bbbf17ccbe375aa8d2bfca6f1909e2a1 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 23 Apr 2024 11:01:20 +0530 Subject: [PATCH 3/4] Skip indexing non-existent folders on Desktop app --- src/interface/desktop/main.js | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/interface/desktop/main.js b/src/interface/desktop/main.js index eb3ceb37..2e9f7989 100644 --- a/src/interface/desktop/main.js +++ b/src/interface/desktop/main.js @@ -121,24 +121,36 @@ function isSupportedFileType(filePath) { } function processDirectory(filesToPush, folder) { - const files = fs.readdirSync(folder.path, { withFileTypes: true }); + try { + const files = fs.readdirSync(folder.path, { withFileTypes: true }); - for (const file of files) { - const filePath = path.join(file.path, file.name || ''); - // Skip hidden files and folders - if (file.name.startsWith('.')) { - continue; + for (const file of files) { + const filePath = path.join(file.path, file.name || ''); + // Skip hidden files and folders + if (file.name.startsWith('.')) { + continue; + } + // Add supported files to index + if (file.isFile() && isSupportedFileType(filePath)) { + console.log(`Add ${file.name} in ${file.path} for indexing`); + filesToPush.push(filePath); + } + // Recursively process subdirectories + if (file.isDirectory()) { + processDirectory(filesToPush, {'path': filePath}); + } } - // Add supported files to index - if (file.isFile() && isSupportedFileType(filePath)) { - console.log(`Add ${file.name} in ${file.path} for indexing`); - filesToPush.push(filePath); - } - // Recursively process subdirectories - if (file.isDirectory()) { - processDirectory(filesToPush, {'path': filePath}); + } catch (err) { + if (err.code === 'EACCES') { + console.error(`Access denied to ${folder.path}`); + } else if (err.code === 'ENOENT') { + console.error(`${folder.path} does not exist`); + } else { + console.error(`An error occurred while reading directory: ${error.message}`); } + return; } + } function pushDataToKhoj (regenerate = false) { From 8196ab62f98c8121771ea05ecc7de80612a04c1a Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 23 Apr 2024 11:14:57 +0530 Subject: [PATCH 4/4] Make valid file extension checking case insensitive on Desktop app --- src/interface/desktop/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/desktop/main.js b/src/interface/desktop/main.js index 2e9f7989..978b8220 100644 --- a/src/interface/desktop/main.js +++ b/src/interface/desktop/main.js @@ -116,7 +116,7 @@ function filenameToMimeType (filename) { } function isSupportedFileType(filePath) { - const fileExtension = filePath.split('.').pop(); + const fileExtension = filePath.split('.').pop().toLowerCase(); return validFileTypes.includes(fileExtension); }