diff --git a/Cargo.toml b/Cargo.toml index 08915d3..9602c5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "botui" -version = "6.1.2" +version = "6.3.0" edition = "2021" description = "General Bots UI - Pure web interface" license = "AGPL-3.0" diff --git a/ui/suite/chat/chat.html b/ui/suite/chat/chat.html index f7ead7f..224ebc6 100644 --- a/ui/suite/chat/chat.html +++ b/ui/suite/chat/chat.html @@ -796,21 +796,17 @@ return; } - // Get the footer element - var footer = suggestionsEl.closest("footer"); - // Clear existing suggestions suggestionsEl.innerHTML = ""; console.log("Rendering " + suggestions.length + " suggestions"); // Add or remove CSS class based on whether suggestions are displayed - if (footer) { - if (suggestions.length > 0) { - footer.classList.add("has-suggestions"); - } else { - footer.classList.remove("has-suggestions"); - } + // Note: CSS uses .has-bot-suggestions on the suggestions-container + if (suggestions.length > 0) { + suggestionsEl.classList.add("has-bot-suggestions"); + } else { + suggestionsEl.classList.remove("has-bot-suggestions"); } suggestions.forEach(function (suggestion) { @@ -1252,7 +1248,16 @@ function proceedWithChatInit() { var botName = window.__INITIAL_BOT_NAME__ || "default"; - fetch("/api/auth?bot_name=" + encodeURIComponent(botName)) + var sessionIdKey = "gb_session_" + botName; + + // Try to restore session from localStorage + var storedSessionId = localStorage.getItem(sessionIdKey); + var authUrl = "/api/auth?bot_name=" + encodeURIComponent(botName); + if (storedSessionId) { + authUrl += "&session_id=" + encodeURIComponent(storedSessionId); + } + + fetch(authUrl) .then(function (response) { return response.json(); }) @@ -1261,6 +1266,10 @@ currentSessionId = auth.session_id; currentBotId = auth.bot_id || "default"; currentBotName = botName; + + // Save session ID to localStorage for page refreshes + localStorage.setItem(sessionIdKey, currentSessionId); + console.log("Auth:", { currentUserId: currentUserId, currentSessionId: currentSessionId, @@ -1271,7 +1280,7 @@ }) .catch(function (e) { console.error("Auth failed:", e); - // Proceed with anonymous connection - WebSocket handler supports it + // Proceed with anonymous connection currentUserId = crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(); diff --git a/ui/suite/js/htmx-app.js b/ui/suite/js/htmx-app.js index 3951bbe..c3a85e0 100644 --- a/ui/suite/js/htmx-app.js +++ b/ui/suite/js/htmx-app.js @@ -259,6 +259,7 @@ const suggestionsEl = document.getElementById("suggestions"); if (suggestionsEl) { suggestionsEl.innerHTML = ''; + suggestionsEl.classList.remove('has-bot-suggestions'); } } @@ -276,6 +277,7 @@ chip.setAttribute("hx-swap", "beforeend"); suggestionsEl.appendChild(chip); + suggestionsEl.classList.add('has-bot-suggestions'); htmx.process(chip); }