mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Fix creating new chat sessions from the Desktop app
Code wasn't passing the authorization header in the POST request to create new chat session
This commit is contained in:
@@ -344,22 +344,20 @@
|
|||||||
let chat_body = document.getElementById("chat-body");
|
let chat_body = document.getElementById("chat-body");
|
||||||
|
|
||||||
let conversationID = chat_body.dataset.conversationId;
|
let conversationID = chat_body.dataset.conversationId;
|
||||||
|
|
||||||
let hostURL = await window.hostURLAPI.getURL();
|
let hostURL = await window.hostURLAPI.getURL();
|
||||||
|
const khojToken = await window.tokenAPI.getToken();
|
||||||
|
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
||||||
|
|
||||||
if (!conversationID) {
|
if (!conversationID) {
|
||||||
let response = await fetch(`${hostURL}/api/chat/sessions`, { method: "POST" });
|
let response = await fetch(`${hostURL}/api/chat/sessions`, { method: "POST", headers });
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
conversationID = data.conversation_id;
|
conversationID = data.conversation_id;
|
||||||
chat_body.dataset.conversationId = conversationID;
|
chat_body.dataset.conversationId = conversationID;
|
||||||
await refreshChatSessionsPanel();
|
await refreshChatSessionsPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Generate backend API URL to execute query
|
// Generate backend API URL to execute query
|
||||||
let url = `${hostURL}/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}®ion=${region}&city=${city}&country=${countryName}`;
|
let chatApi = `${hostURL}/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}®ion=${region}&city=${city}&country=${countryName}`;
|
||||||
const khojToken = await window.tokenAPI.getToken();
|
|
||||||
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
|
||||||
|
|
||||||
let new_response = document.createElement("div");
|
let new_response = document.createElement("div");
|
||||||
new_response.classList.add("chat-message", "khoj");
|
new_response.classList.add("chat-message", "khoj");
|
||||||
@@ -382,8 +380,8 @@
|
|||||||
let chatInput = document.getElementById("chat-input");
|
let chatInput = document.getElementById("chat-input");
|
||||||
chatInput.classList.remove("option-enabled");
|
chatInput.classList.remove("option-enabled");
|
||||||
|
|
||||||
// Call specified Khoj API
|
// Call Khoj chat API
|
||||||
let response = await fetch(url, { headers });
|
let response = await fetch(chatApi, { headers });
|
||||||
let rawResponse = "";
|
let rawResponse = "";
|
||||||
const contentType = response.headers.get("content-type");
|
const contentType = response.headers.get("content-type");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user