Agent Zero AI framework
Update index.js
Alessandro3942b2275b0e
diff --git a/webui/index.js b/webui/index.jsindex 47fc36472..31cde1e50 100644--- a/webui/index.js+++ b/webui/index.js@@ -1,7 +1,7 @@import * as msgs from "./messages.js"-const splitter = document.getElementById('splitter');const leftPanel = document.getElementById('left-panel');+const rightPanel = document.getElementById('right-panel');const container = document.querySelector('.container');const chatInput = document.getElementById('chat-input');const chatHistory = document.getElementById('chat-history');@@ -9,64 +9,95 @@ const sendButton = document.getElementById('send-button');const inputSection = document.getElementById('input-section');const statusSection = document.getElementById('status-section');const chatsSection = document.getElementById('chats-section');+const scrollbarThumb = document.querySelector('#chat-history::-webkit-scrollbar-thumb');let autoScroll = true;let context = "";-// Sidebar Toggle Setup:-function setupSidebarToggle() {- const toggleSidebarButton = document.getElementById('toggle-sidebar');+// Initialize the toggle button+setupSidebarToggle();++function isMobile() {+ return window.innerWidth <= 768;+ }++ function toggleSidebar() {+ leftPanel.classList.toggle('hidden');+ rightPanel.classList.toggle('expanded');+ }++ function handleResize() {+ if (isMobile()) {+ leftPanel.classList.add('hidden');+ rightPanel.classList.add('expanded');+ } else {+ leftPanel.classList.remove('hidden');+ rightPanel.classList.remove('expanded');+ }+ }++ // Run on startup and window resize+ window.addEventListener('load', handleResize);+ window.addEventListener('resize', handleResize);++ function setupSidebarToggle() {const leftPanel = document.getElementById('left-panel');const rightPanel = document.getElementById('right-panel');-- if (toggleSidebarButton && leftPanel && rightPanel) {- toggleSidebarButton.addEventListener('click', () => {- leftPanel.classList.toggle('hidden');- rightPanel.classList.toggle('expanded');- });+ const toggleSidebarButton = document.getElementById('toggle-sidebar');+ if (toggleSidebarButton) {+ toggleSidebarButton.addEventListener('click', toggleSidebar);} else {- setTimeout(setupSidebarToggle, 100);+ console.error('Toggle sidebar button not found');+ setTimeout(setupSidebarToggle, 100);}-}+ }+ // Make sure to call this function+ document.addEventListener('DOMContentLoaded', setupSidebarToggle);-// Initialize the toggle button-setupSidebarToggle();async function sendMessage() {const message = chatInput.value.trim();if (message) {-+const response = await sendJsonData("/msg", { text: message, context });-+//setMessage('user', message);chatInput.value = '';adjustTextareaHeight();}}-+chatInput.addEventListener('keydown', (e) => {if (e.key === 'Enter' && !e.shiftKey) {e.preventDefault();sendMessage();}});-+sendButton.addEventListener('click', sendMessage);--function updateUTCTime() {+function updateUserTime() {const now = new Date();- const hours = now.getUTCHours();- const minutes = now.getUTCMinutes();- const seconds = now.getUTCSeconds(); // Get UTC seconds+ const hours = now.getHours();+ const minutes = now.getMinutes();+ const seconds = now.getSeconds();const ampm = hours >= 12 ? 'pm' : 'am';const formattedHours = hours % 12 || 12;++ // Format the time+ const timeString = `${formattedHours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${ampm}`;++ // Format the date+ const options = { year: 'numeric', month: 'short', day: 'numeric' };+ const dateString = now.toLocaleDateString(undefined, options);++ // Update the HTML+ const userTimeElement = document.getElementById('time-date');+ userTimeElement.innerHTML = `${timeString}<br><span id="user-date">${dateString}</span>`;+}- document.getElementById('utc-time').textContent =- `${formattedHours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${ampm} UTC`;- }--updateUTCTime();-setInterval(updateUTCTime, 1000);+updateUserTime();+setInterval(updateUserTime, 1000);+function setMessage(id, type, heading, content, kvps = null) {// Search for the existing message container by idlet messageContainer = document.getElementById(`message-${id}`);@@ -93,7 +124,6 @@ function setMessage(id, type, heading, content, kvps = null) {if (autoScroll) chatHistory.scrollTop = chatHistory.scrollHeight;}-function adjustTextareaHeight() {chatInput.style.height = 'auto';chatInput.style.height = (chatInput.scrollHeight) + 'px';@@ -130,7 +160,7 @@ let lastLogGuid = ""async function poll() {try {const response = await sendJsonData("/poll", { log_from: lastLogVersion, context });- // console.log(response)+ //console.log(response)if (response.ok) {@@ -168,8 +198,22 @@ async function poll() {}}+function updatePauseButtonState(isPaused) {+ const pauseButton = document.getElementById('pause-button');+ const unpauseButton = document.getElementById('unpause-button');++ if (isPaused) {+ pauseButton.style.display = 'none';+ unpauseButton.style.display = 'flex';+ } else {+ pauseButton.style.display = 'flex';+ unpauseButton.style.display = 'none';+ }+}+window.pauseAgent = async function (paused) {const resp = await sendJsonData("/pause", { paused: paused, context });+ updatePauseButtonState(paused);}window.resetChat = async function () {@@ -215,7 +259,6 @@ const setContext = function (id) {chatsAD.selected = id}-window.toggleAutoScroll = async function (_autoScroll) {autoScroll = _autoScroll;}@@ -230,6 +273,7 @@ window.toggleThoughts = async function (showThoughts) {toggleCssProperty('.msg-thoughts', 'display', showThoughts ? undefined : 'none');}+window.toggleDarkMode = function(isDark) {if (isDark) {document.body.classList.remove('light-mode');@@ -238,7 +282,7 @@ window.toggleDarkMode = function(isDark) {}console.log("Dark mode:", isDark);localStorage.setItem('darkMode', isDark);- };+};// Modify this partdocument.addEventListener('DOMContentLoaded', () => {