From 0c32befbb91e6a0240b1f8b964716a66358c96f1 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Wed, 8 Apr 2026 17:48:12 -0300 Subject: [PATCH] Prevent duplicate suggestion button rendering --- ui/suite/chat/chat.html | 50 ++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/ui/suite/chat/chat.html b/ui/suite/chat/chat.html index 83f4f8f..56164de 100644 --- a/ui/suite/chat/chat.html +++ b/ui/suite/chat/chat.html @@ -788,6 +788,9 @@ } } + // Track last rendered suggestions to prevent duplicates + var lastRenderedSuggestions = null; + // Render suggestion buttons function renderSuggestions(suggestions) { var suggestionsEl = document.getElementById("suggestions"); @@ -796,6 +799,18 @@ return; } + // Prevent duplicate rendering - compare with last rendered suggestions + var currentSuggestionKeys = suggestions + .map(function (s) { + return s.text || ""; + }) + .join("|"); + if (lastRenderedSuggestions === currentSuggestionKeys) { + console.log("Skipping duplicate suggestions render"); + return; + } + lastRenderedSuggestions = currentSuggestionKeys; + // Clear existing suggestions suggestionsEl.innerHTML = ""; @@ -835,7 +850,9 @@ window.sendMessage(sugg.text); } else { // No params needed - invoke tool directly - window.sendMessage("/tool " + action.tool); + window.sendMessage( + "/tool " + action.tool, + ); } } else if (action.type === "send_message") { window.sendMessage( @@ -925,7 +942,8 @@ updateConnectionStatus("connecting"); // Always get the bot name from window.__INITIAL_BOT_NAME__ to ensure it's correct on reconnection - var botNameForWs = window.__INITIAL_BOT_NAME__ || currentBotName || "default"; + var botNameForWs = + window.__INITIAL_BOT_NAME__ || currentBotName || "default"; var url = WS_URL + @@ -953,15 +971,17 @@ disconnectNotified = false; updateConnectionStatus("connected"); // Send empty message to trigger start.bas and load suggestions - ws.send(JSON.stringify({ - bot_id: currentBotId, - user_id: currentUserId, - session_id: currentSessionId, - channel: "web", - content: "", - message_type: MessageType.USER, - timestamp: new Date().toISOString(), - })); + ws.send( + JSON.stringify({ + bot_id: currentBotId, + user_id: currentUserId, + session_id: currentSessionId, + channel: "web", + content: "", + message_type: MessageType.USER, + timestamp: new Date().toISOString(), + }), + ); }; ws.onmessage = function (event) { @@ -1254,14 +1274,14 @@ function proceedWithChatInit() { var botName = window.__INITIAL_BOT_NAME__ || "default"; 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(); @@ -1271,10 +1291,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,