Skip to content

Agent Zero AI framework

refactor(webui): migrate welcome screen to component system architecture

Chadwick Jones8c444c0f7f9a
diff --git a/webui/components/welcome/welcome-screen.html b/webui/components/welcome/welcome-screen.html
new file mode 100644
index 000000000..856b6a10e
--- /dev/null
+++ b/webui/components/welcome/welcome-screen.html
@@ -0,0 +1,263 @@
+<html>
+ <head>
+ <script type="module">
+ import { store } from "/components/welcome/welcome-store.js";
+ </script>
+ </head>
+ <body>
+ <div x-data x-show="$store.welcomeStore && $store.welcomeStore.isVisible">
+ <template x-if="$store.welcomeStore">
+ <div x-data="$store.welcomeStore" class="welcome-container">
+ <!-- Agent Zero Logo -->
+ <div class="welcome-logo-container">
+ <img
+ src="/image_get?path=webui/public/lightSymbol.svg"
+ alt="Agent Zero Logo"
+ class="welcome-logo"
+ />
+ </div>
+
+ <!-- Welcome Title -->
+ <h1 class="welcome-title">Welcome to Agent Zero</h1>
+ <p class="welcome-subtitle">
+ Start a new conversation or explore the features below.
+ </p>
+
+ <!-- Action Cards -->
+ <div class="welcome-actions">
+ <div
+ class="welcome-action-card"
+ @click="executeAction('new-chat')"
+ >
+ <span
+ class="material-symbols-outlined welcome-action-icon"
+ >add_circle</span
+ >
+ <h3 class="welcome-action-title">New Chat</h3>
+ <p class="welcome-action-description">
+ Start a new conversation
+ </p>
+ </div>
+ <div
+ class="welcome-action-card"
+ @click="executeAction('settings')"
+ >
+ <span
+ class="material-symbols-outlined welcome-action-icon"
+ >settings</span
+ >
+ <h3 class="welcome-action-title">Settings</h3>
+ <p class="welcome-action-description">
+ Configure Agent Zero
+ </p>
+ </div>
+ <div
+ class="welcome-action-card"
+ @click="executeAction('website')"
+ >
+ <span
+ class="material-symbols-outlined welcome-action-icon"
+ >language</span
+ >
+ <h3 class="welcome-action-title">Visit Website</h3>
+ <p class="welcome-action-description">
+ Learn more about Agent Zero
+ </p>
+ </div>
+ <div
+ class="welcome-action-card"
+ @click="executeAction('github')"
+ >
+ <span
+ class="material-symbols-outlined welcome-action-icon"
+ >code</span
+ >
+ <h3 class="welcome-action-title">Visit GitHub</h3>
+ <p class="welcome-action-description">
+ View source code and documentation
+ </p>
+ </div>
+ </div>
+
+ <!-- Footer Info -->
+ <div class="welcome-footer">
+ <p>Agent Zero Framework • Open Source AI Assistant</p>
+ </div>
+ </div>
+ </template>
+ </div>
+
+ <script>
+ document.addEventListener("alpine:init", () => {
+ const s = Alpine.store("welcomeStore");
+ if (s && typeof s.init === "function") s.init();
+ });
+ </script>
+
+ <style>
+ /* Welcome Screen Styles */
+ .welcome-container {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ padding: 2rem;
+ text-align: center;
+ background: var(--color-background);
+ color: var(--color-text);
+ min-height: 400px;
+ }
+
+ .welcome-logo-container {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin-bottom: 1.5rem;
+ }
+
+ .welcome-logo {
+ width: 120px;
+ height: 120px;
+ filter: brightness(1);
+ }
+
+ /* Dark mode adjustments for logo */
+ .dark-mode .welcome-logo {
+ filter: brightness(1.2);
+ }
+
+ .welcome-title {
+ font-size: 2rem;
+ font-weight: 300;
+ margin-bottom: 0.8rem;
+ color: var(--color-text);
+ }
+
+ .welcome-subtitle {
+ font-size: 1rem;
+ margin-bottom: 2rem;
+ color: var(--color-secondary);
+ max-width: 600px;
+ line-height: 1.5;
+ }
+
+ .welcome-actions {
+ display: grid;
+ grid-template-columns: repeat(2, 1fr);
+ gap: 1.2rem;
+ max-width: 520px;
+ width: 100%;
+ margin: 1.5rem 0;
+ }
+
+ .welcome-action-card {
+ background: var(--color-panel);
+ border: 1px solid var(--color-border);
+ border-radius: 12px;
+ padding: 1.5rem;
+ transition: all 0.3s ease;
+ cursor: pointer;
+ text-decoration: none;
+ color: inherit;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ text-align: center;
+ min-height: 120px;
+ justify-content: center;
+ }
+
+ .welcome-action-card:hover {
+ border-color: var(--color-accent);
+ background: var(--color-message-bg);
+ transform: translateY(-2px);
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
+ }
+
+ .dark-mode .welcome-action-card:hover {
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
+ }
+
+ .welcome-action-icon {
+ font-size: 2rem;
+ margin-bottom: 0.8rem;
+ color: var(--color-accent);
+ }
+
+ .welcome-action-title {
+ font-size: 1.1rem;
+ font-weight: 500;
+ margin-bottom: 0.4rem;
+ color: var(--color-text);
+ }
+
+ .welcome-action-description {
+ font-size: 0.8rem;
+ color: var(--color-secondary);
+ line-height: 1.3;
+ }
+
+ .welcome-footer {
+ margin-top: 1.5rem;
+ opacity: 0.7;
+ font-size: 0.8rem;
+ }
+
+ /* Light mode adjustments */
+ .light-mode .welcome-title {
+ color: #2d2d2d;
+ }
+
+ .light-mode .welcome-subtitle {
+ color: #666;
+ }
+
+ .light-mode .welcome-action-title {
+ color: #2d2d2d;
+ }
+
+ .light-mode .welcome-action-description {
+ color: #666;
+ }
+
+ .light-mode .welcome-footer {
+ color: #666;
+ }
+
+ /* Responsive design */
+ @media (max-width: 768px) {
+ .welcome-container {
+ padding: 1rem;
+ }
+
+ .welcome-title {
+ font-size: 2rem;
+ }
+
+ .welcome-subtitle {
+ font-size: 1rem;
+ margin-bottom: 2rem;
+ }
+
+ .welcome-actions {
+ grid-template-columns: 1fr;
+ gap: 1rem;
+ margin-bottom: 2rem;
+ }
+
+ .welcome-action-card {
+ padding: 1.5rem;
+ min-height: 120px;
+ }
+
+ .welcome-action-icon {
+ font-size: 2rem;
+ }
+
+ .welcome-action-title {
+ font-size: 1.1rem;
+ }
+ }
+ </style>
+ </body>
+</html>
diff --git a/webui/components/welcome/welcome-store.js b/webui/components/welcome/welcome-store.js
new file mode 100644
index 000000000..f706de89e
--- /dev/null
+++ b/webui/components/welcome/welcome-store.js
@@ -0,0 +1,61 @@
+import { createStore } from "/js/AlpineStore.js";
+import { store as contextStore } from "/components/chat/context/context-store.js";
+
+const model = {
+ // State
+ isVisible: true,
+
+ init() {
+ // Initialize visibility based on current context
+ this.updateVisibility();
+
+ // Watch for context changes with faster polling for immediate response
+ setInterval(() => {
+ this.updateVisibility();
+ }, 50); // 50ms for very responsive updates
+ },
+
+ // Update visibility based on current context
+ updateVisibility() {
+ const hasContext = !!(globalThis.getContext && globalThis.getContext());
+ this.isVisible = !hasContext;
+ },
+
+ // Hide welcome screen
+ hide() {
+ this.isVisible = false;
+ },
+
+ // Show welcome screen
+ show() {
+ this.isVisible = true;
+ },
+
+ // Execute an action by ID
+ executeAction(actionId) {
+ switch (actionId) {
+ case "new-chat":
+ if (globalThis.newChat) {
+ globalThis.newChat();
+ }
+ break;
+ case "settings":
+ // Open settings modal
+ const settingsButton = document.getElementById("settings");
+ if (settingsButton) {
+ settingsButton.click();
+ }
+ break;
+ case "website":
+ window.open("https://agent-zero.ai", "_blank");
+ break;
+ case "github":
+ window.open("https://github.com/agent0ai/agent-zero", "_blank");
+ break;
+ }
+ },
+};
+
+// Create and export the store
+const store = createStore("welcomeStore", model);
+export { store };
diff --git a/webui/index.html b/webui/index.html
index 272ac1807..1b734dbbf 100644
--- a/webui/index.html
+++ b/webui/index.html
@@ -129,23 +129,225 @@
<script type="text/javascript" src="js/settings.js"></script>
<script type="text/javascript" src="js/file_browser.js"></script>
<script type="text/javascript" src="js/modal.js"></script>
- <script type="module" src="js/tunnel.js"></script>
- <script>
- // Expose git info for sidebar component
- globalThis.gitinfo = { version: "{{version_no}}", commit_time: "{{version_time}}" };
- </script>
</head>
<body class="dark-mode device-pointer">
<div class="container">
- <!-- Sidebar Overlay -->
- <div id="sidebar-overlay" class="sidebar-overlay" x-data :class="{'visible': $store.sidebar.isOpen && $store.sidebar.isMobile()}" @click="$store.sidebar.close()"></div>
- <!-- Left Sidebar (Header Icons, Quick Actions, Tabs, Chats, Tasks) -->
- <x-component path="sidebar/left-sidebar.html"></x-component>
-
- <!-- Right Panel (Message History and Input Section) -->
- <div id="right-panel" class="panel" :class="{'expanded': !$store.sidebar.isOpen}">
- <!-- Time and Date -->
+ <div id="sidebar-overlay" class="sidebar-overlay hidden"></div>
+ <div class="icons-section" id="hide-button" x-data="{ connected: true }">
+ <!--Sidebar-->
+ <!-- Sidebar Toggle Button -->
+ <button id="toggle-sidebar" class="toggle-sidebar-button" aria-label="Toggle Sidebar" aria-expanded="false">
+ <span aria-hidden="true">
+ <!-- Hamburger Icon -->
+ <svg id="sidebar-hamburger-svg" xmlns="http://www.w3.org/2000/svg" width="22" height="22"
+ viewBox="0 0 24 24" fill="CurrentColor">
+ <path d="M3 13h18v-2H3v2zm0 4h18v-2H3v2zm0-8h18V7H3v2z"></path>
+ </svg>
+ </span>
+ </button>
+
+ <div id="logo-container">
+ <a href="https://github.com/agent0ai/agent-zero" target="_blank" rel="noopener noreferrer">
+ <img src="./public/splash.jpg" alt="a0" width="22" height="22">
+ </a>
+ </div>
+ </div>
+
+ <div id="left-panel" class="panel">
+ <!--Sidebar upper elements-->
+ <div class="left-panel-top">
+ <div class="config-section" x-data="{ showQuickActions: true }">
+ <button class="config-button" id="resetChat" @click="resetChat()">Reset Chat</button>
+ <button class="config-button" id="newChat" @click="newChat()">New Chat</button>
+ <button class="config-button" id="loadChats" @click="loadChats()">Load Chat</button>
+ <button class="config-button" id="loadChat" @click="saveChat()">Save Chat</button>
+ <button class="config-button" id="restart" @click="restart()">Restart</button>
+ <button class="config-button" id="settings" @click="settingsModalProxy.openModal()"><svg
+ xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="-5.0 -17.0 110.0 135.0"
+ fill="currentColor" width="24" height="24">
+ <path
+ d="m52.301 90.102h-4.1016c-3 0-5 0-6.8984-1.3984-1.8984-1.3984-2.5-3.3008-3.5-6.1016l-1.1016-3.6016c-0.19922-0.60156-0.69922-1.1992-1.3984-1.6016l-1.1016-0.60156c-0.60156-0.30078-1.5-0.39844-2.3008-0.19922l-4.3008 1.1992c-3.1016 0.89844-5.1016 1.5-7.3984 0.5-2.3008-0.89844-3.3984-2.8008-5-5.6016l-1.8008-3.1016c-1.5-2.5-2.5-4.3008-2.3008-6.6992 0.19922-2.3984 1.6016-3.8008 3.6016-6.1016l3.8008-4.1992c0.19922-0.19922 0.60156-1.3984 0.60156-2.6016 0-1.1016-0.5-2.3008-0.80078-2.6992l-3.6016-4c-2-2.1992-3.3008-3.6992-3.6016-6.1016-0.19922-2.3984 0.80078-4.1992 2.3008-6.6992l1.8008-3.1016c1.6016-2.8008 2.6992-4.6016 5-5.6016 2.3008-0.89844 4.3008-0.39844 7.3984 0.5l4.3984 1.1992c0.69922 0.10156 1.5 0 2.3008-0.30078l1.1016-0.60156c0.5-0.30078 1-0.89844 1.3008-1.6992l1.1992-3.5c0.89844-2.8008 1.6016-4.6992 3.5-6.1016 1.8984-1.3984 3.8984-1.3984 6.8984-1.3984h4.1016c3 0 5 0 6.8984 1.3984 1.8984 1.3984 2.5 3.1992 3.5 6.1016l1.1992 3.6016c0.19922 0.60156 0.69922 1.1992 1.3984 1.6016l1.1016 0.60156c0.60156 0.30078 1.5 0.39844 2.3008 0.19922l4.3008-1.1992c3.1016-0.89844 5.1016-1.5 7.3984-0.5 2.3008 0.89844 3.3984 2.8008 5 5.5l1.8008 3.1016c1.3984 2.5 2.5 4.3008 2.3008 6.6992-0.19922 2.3984-1.6016 3.8008-3.6016 6.1016l-3.9961 4.4062c-0.19922 0.19922-0.60156 1.3984-0.60156 2.6016 0 1.1016 0.5 2.3008 0.80078 2.6992l3.6016 4c2 2.1992 3.3008 3.6992 3.6016 6.1016 0.19922 2.3984-0.80078 4.1992-2.3008 6.6992l-1.8008 3.1016c-1.6016 2.8008-2.6992 4.6016-5 5.6016-2.3008 0.89844-4.3984 0.39844-7.3984-0.5l-4.3984-1.1992c-0.69922-0.10156-1.5 0-2.3008 0.30078l-1.1016 0.60156c-0.5 0.30078-1 0.89844-1.3008 1.6992l-1.1992 3.5c-0.89844 2.8008-1.6016 4.6992-3.5 6.1016-1.8008 1.293-3.8008 1.293-6.8008 1.293zm-6.6016-7.3008c0.5 0.10156 1.6016 0.10156 2.6016 0.10156h4.1016c1 0 2 0 2.6016-0.10156 0.19922-0.5 0.60156-1.5 0.89844-2.3984l1.1992-3.6016c0.89844-2.3008 2.3984-4.1992 4.3984-5.3984l1.3984-0.80078c2.3984-1.3008 5.1016-1.6016 7.6016-1l4.6016 1.3008c1 0.30078 2.1016 0.60156 2.6992 0.69922 0.30078-0.5 0.89844-1.5 1.3984-2.3984l1.8008-3.1016c0.5-0.80078 1-1.8008 1.1992-2.3008-0.30078-0.39844-1-1.1992-1.6992-2l-3.8008-4.1992c-1.6016-2-2.5-4.8008-2.5-7.3984 0-2.6016 0.89844-5.3984 2.3008-7.3008l3.8984-4.3984c0.69922-0.69922 1.3984-1.5 1.6992-2-0.19922-0.5-0.80078-1.3984-1.1992-2.3008l-1.8984-3.1016c-0.5-0.89844-1.1016-1.8984-1.3984-2.3984-0.60156 0.10156-1.6992 0.39844-2.6992 0.69922l-4.3984 1.3008c-2.6992 0.60156-5.3008 0.30078-7.6016-0.89844l-1.4023-0.80469c-2.1016-1.3984-3.6016-3.1992-4.3984-5.3984l-1.3008-3.8008c-0.30078-0.89844-0.60156-1.8984-0.89844-2.3984-0.5-0.10156-1.6016-0.10156-2.6016-0.10156h-4.1016c-1 0-2 0-2.6016 0.10156-0.19922 0.5-0.60156 1.5-0.89844 2.3984l-1.1992 3.6016c-0.89844 2.3008-2.3984 4.1992-4.3984 5.3984l-1.3984 0.80078c-2.3984 1.3008-5.1016 1.6016-7.6016 1l-4.6016-1.3008c-1-0.30078-2.1016-0.60156-2.6992-0.69922-0.30078 0.5-0.89844 1.5-1.3984 2.3984l-1.8008 3.1016c-0.5 0.80078-1 1.8008-1.1992 2.3008 0.30078 0.39844 1 1.1992 1.6992 2l3.8008 4.1992c1.6016 2 2.5 4.8008 2.5 7.3984 0 2.6016-0.89844 5.3984-2.3008 7.3008l-3.8984 4.3984c-0.69922 0.69922-1.3984 1.5-1.6992 2 0.19922 0.5 0.80078 1.3984 1.1992 2.3008l1.8008 3.1016c0.5 0.89844 1.1016 1.8984 1.3984 2.3984 0.60156-0.10156 1.6992-0.39844 2.6992-0.69922l4.3984-1.1992c2.6992-0.60156 5.3008-0.30078 7.6016 0.89844l1.3984 0.80078c2.1016 1.3008 3.6016 3.1992 4.3984 5.3984l1.3008 3.8008c0.5 0.80078 0.80078 1.8008 1 2.3008z">
+ </path>
+ <path
+ d="m50.301 66.5c-9 0-16.398-7.3008-16.398-16.398 0-9.1016 7.3008-16.398 16.398-16.398 9.1016 0 16.398 7.3008 16.398 16.398 0 9.0977-7.3984 16.398-16.398 16.398zm0-25.5c-5 0-9.1016 4.1016-9.1016 9.1016s4.1016 9.1016 9.1016 9.1016 9.1016-4.1016 9.1016-9.1016c-0.003906-5-4.1016-9.1016-9.1016-9.1016z">
+ </path>
+ </svg>Settings</button>
+ <button class="config-button" id="memory-dash"
+ @click="openModal('settings/memory/memory-dashboard.html');">Memory</button>
+ <button class="config-button" id="dashboard" @click="deselectChat()">Dashboard</button>
+
+ </div>
+
+ <!-- Tabs container -->
+ <div class="tabs-container">
+ <div class="tabs">
+ <div class="tab active" id="chats-tab">Chats</div>
+ <div class="tab" id="tasks-tab">Tasks</div>
+ </div>
+ </div>
+
+ <!-- Chats List -->
+ <div class="config-section" id="chats-section" x-data="{ contexts: [], selected: '' }"
+ x-show="contexts.length > 0 || true">
+ <div class="chats-list-container">
+ <ul class="config-list" x-show="contexts.length > 0">
+ <template x-for="context in contexts">
+ <li>
+ <div :class="{'chat-list-button': true, 'font-bold': context.id === selected}"
+ @click="selected = context.id; selectChat(context.id)">
+ <span class="chat-name"
+ :title="context.name ? context.name : 'Chat #' + context.no"
+ x-text="context.name ? context.name : 'Chat #' + context.no"></span>
+ </div>
+ <button class="edit-button" @click="killChat(context.id)">X</button>
+ </li>
+ </template>
+ </ul>
+ <div class="empty-list-message" x-show="contexts.length === 0">
+ <p><i>No chats to list.</i></p>
+ </div>
+ </div>
+ </div>
+
+ <!-- Tasks List -->
+ <div class="config-section" id="tasks-section" x-data="{
+ tasks: [],
+ selected: '',
+ openTaskDetail(taskId) {
+ globalThis.openTaskDetail(taskId);
+ }
+ }" style="display: none;">
+ <div class="tasks-list-container">
+ <ul class="config-list" x-show="tasks.length > 0">
+ <template x-for="task in tasks">
+ <li>
+ <div :class="{'chat-list-button': true, 'font-bold': task.id === selected, 'has-task-container': true}"
+ @click="selected = task.id; selectChat(task.id)">
+ <!-- Task container with a vertical layout -->
+ <div class="task-container task-container-vertical">
+ <!-- Task name on its own line with full width -->
+ <span class="task-name"
+ :title="(task.task_name || `Task #${task.no}`) + ' (' + (task.name || `Chat #${task.no}`) + ')'"
+ x-text="(task.task_name || `Task #${task.no}`) + ' (' + (task.name || `Chat #${task.no}`) + ')'"
+ :data-task-id="task.id"></span>
+ <!-- Second line with status badge and action button -->
+ <div class="task-info-line">
+ <!-- Status badge (reusing scheduler styling) -->
+ <span class="scheduler-status-badge scheduler-status-badge-small"
+ :class="task.state ? `scheduler-status-${task.state}` : 'scheduler-status-idle'"
+ x-text="task.state || 'idle'"></span>
+ <!-- Action buttons -->
+ <button class="edit-button" @click.stop="openTaskDetail(task.id)"
+ title="View task details"
+ style="margin-left: auto; margin-right: 5px;">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
+ viewBox="0 0 512 512" fill="var(--color-primary)"
+ stroke="currentColor" stroke-width="2" stroke-linecap="round"
+ stroke-linejoin="round">
+ <path
+ d="M256 0c70.69 0 134.69 28.66 181.02 74.98C483.34 121.3 512 185.31 512 256c0 70.69-28.66 134.7-74.98 181.02C390.69 483.34 326.69 512 256 512c-70.69 0-134.69-28.66-181.02-74.98C28.66 390.69 0 326.69 0 256c0-70.69 28.66-134.69 74.98-181.02C121.31 28.66 185.31 0 256 0zm-9.96 161.03c0-4.28.76-8.26 2.27-11.91 1.5-3.63 3.77-6.94 6.79-9.91 3-2.95 6.29-5.2 9.84-6.7 3.57-1.5 7.41-2.28 11.52-2.28 4.12 0 7.96.78 11.49 2.27 3.54 1.51 6.78 3.76 9.75 6.73 2.95 2.97 5.16 6.26 6.64 9.91 1.49 3.63 2.22 7.61 2.22 11.89 0 4.17-.73 8.08-2.21 11.69-1.48 3.6-3.68 6.94-6.65 9.97-2.94 3.03-6.18 5.32-9.72 6.84-3.54 1.51-7.38 2.29-11.52 2.29-4.22 0-8.14-.76-11.75-2.26-3.58-1.51-6.86-3.79-9.83-6.79-2.94-3.02-5.16-6.34-6.63-9.97-1.48-3.62-2.21-7.54-2.21-11.77zm13.4 178.16c-1.11 3.97-3.35 11.76 3.3 11.76 1.44 0 3.27-.81 5.46-2.4 2.37-1.71 5.09-4.31 8.13-7.75 3.09-3.5 6.32-7.65 9.67-12.42 3.33-4.76 6.84-10.22 10.49-16.31.37-.65 1.23-.87 1.89-.48l12.36 9.18c.6.43.73 1.25.35 1.86-5.69 9.88-11.44 18.51-17.26 25.88-5.85 7.41-11.79 13.57-17.8 18.43l-.1.06c-6.02 4.88-12.19 8.55-18.51 11.01-17.58 6.81-45.36 5.7-53.32-14.83-5.02-12.96-.9-27.69 3.06-40.37l19.96-60.44c1.28-4.58 2.89-9.62 3.47-14.33.97-7.87-2.49-12.96-11.06-12.96h-17.45c-.76 0-1.38-.62-1.38-1.38l.08-.48 4.58-16.68c.16-.62.73-1.04 1.35-1.02l89.12-2.79c.76-.03 1.41.57 1.44 1.33l-.07.43-37.76 124.7zm158.3-244.93c-41.39-41.39-98.58-67-161.74-67-63.16 0-120.35 25.61-161.74 67-41.39 41.39-67 98.58-67 161.74 0 63.16 25.61 120.35 67 161.74 41.39 41.39 98.58 67 161.74 67 63.16 0 120.35-25.61 161.74-67 41.39-41.39 67-98.58 67-161.74 0-63.16-25.61-120.35-67-161.74z" />
+ </svg>
+ </button>
+ <button class="edit-button" @click.stop="resetChat(task.id)"
+ style="margin-right: 5px;" title="Clear task chat">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
+ viewBox="0 0 122.88 121.1" fill="var(--color-primary)"
+ stroke="currentColor" stroke-width="2" stroke-linecap="round"
+ stroke-linejoin="round">
+ <path
+ d="M62.89,56.03c1.11-0.35,2.34-0.25,3.72,0.37l10.4,7.87c2.26,1.71,4.24,3.78,2.73,6.9 c-0.51,1.06-1.4,2.1-2.38,3.49l-0.53,0.75c-1.97,2.8-2.61,2-5.71,1.83c0.56,13.37,1.75,27.82-2.64,40.88 c-0.87,2.7-3.32,3.44-6.95,2.71l-6.1-2.03c4.11-6.14,6.16-13.85,6.44-22.89c-3.46,8.58-6.8,16.96-10.68,20.86l-6.28-2.08 c0.61-3.05,1.05-5.43,0.35-6.9l-4.07,4.24l-9.33-5.77c6.36-3.36,11.62-7.87,15.6-13.73c-6.69,5.01-12.76,8.1-18.14,8.99 c-2.75,0.83-4.49,0.35-5.16-1.53c-0.48-1.34-0.05-1.77,0.81-2.86c1.11-1.41,2.61-2.67,4.35-3.79c-3.13,1.1-4.64,0.95-6.37,1.51 c-4.9,1.59-9.94-1.86-8.26-6.9c1.07-3.23,3.54-3.09,6.67-4.07l5.42-1.69c-5.19,0.28-10.32,0.45-15.02-0.25 c-5.4-0.8-5.31-0.99-8.24-5.38c-3.94-5.91-6.25-11.45,2.52-9.16c16.73,3.18,33.56,5.34,51.25-0.98c-0.76-1.32-0.9-2.57-0.5-3.73 C57.37,60.94,61.13,56.58,62.89,56.03L62.89,56.03z M113.8,2.42L74.45,51.53c-4.71,6.68,3.2,11.91,8.39,5.64l39.2-49.27 C125.12,1.86,119.13-3.16,113.8,2.42L113.8,2.42z" />
+ </svg>
+ </button>
+ <button title="Delete task" class="edit-button"
+ @click.stop="deleteTaskGlobal(task.id)">X</button>
+
+ </div>
+ </div>
+ </div>
+ </li>
+ </template>
+ </ul>
+ <div class="empty-list-message" x-show="tasks.length === 0">
+ <p><i>No tasks to list.</i></p>
+ </div>
+ </div>
+ </div>
+ </div>
+ <!--Sidebar lower elements-->
+ <div class="left-panel-bottom">
+ <!-- Preferences -->
+ <div class="pref-section" x-data="{ prefOpen: true }">
+ <span>
+ <h3 class="pref-header" @click="prefOpen = !prefOpen">
+ Preferences
+ <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
+ stroke="currentColor" stroke-width="2" width="16" height="16"
+ :class="{'rotated': !prefOpen}">
+ <path d="M8 4l8 8-8 8" />
+ </svg>
+ </h3>
+ <ul class="config-list" id="pref-list" x-show="prefOpen" x-collapse x-transition>
+ <!-- Preferences Items -->
+ <li x-data="{ autoScroll: true }">
+ <span>Autoscroll</span>
+ <label class="switch">
+ <input id="auto-scroll-switch" type="checkbox" x-model="autoScroll"
+ x-effect="globalThis.safeCall('toggleAutoScroll',autoScroll)">
+ <span class="slider"></span>
+ </label>
+ </li>
+ <li x-data="{ darkMode: localStorage.getItem('darkMode') != 'false' }"
+ x-init="$watch('darkMode', val => toggleDarkMode(val))">
+ <span class="switch-label">Dark mode</span>
+ <label class="switch">
+ <input type="checkbox" x-model="darkMode">
+ <span class="slider"></span>
+ </label>
+ </li>
+ <li x-data="{ speech: localStorage.getItem('speech') == 'true' }"
+ x-init="$watch('speech', val => toggleSpeech(val))">
+ <span class="switch-label">Speech</span>
+ <label class="switch">
+ <input type="checkbox" x-model="speech">
+ <span class="slider"></span>
+ </label>
+ </li>
+ <li x-data="{ showThoughts: true }">
+ <span>Show thoughts</span>
+ <label class="switch">
+ <input type="checkbox" x-model="showThoughts"
+ x-effect="globalThis.safeCall('toggleThoughts',showThoughts)">
+ <span class="slider"></span>
+ </label>
+ </li>
+ <li x-data="{ showJson: false }">
+ <span>Show JSON</span>
+ <label class="switch">
+ <input type="checkbox" x-model="showJson"
+ x-effect="globalThis.safeCall('toggleJson',showJson)">
+ <span class="slider"></span>
+ </label>
+ </li>
+ <li x-data="{ showUtils: false }">
+ <span>Show utility messages</span>
+ <label class="switch">
+ <input type="checkbox" x-model="showUtils"
+ x-effect="globalThis.safeCall('toggleUtils',showUtils)">
+ <span class="slider"></span>
+ </label>
+ </li>
+ </ul>
+ </span>
+ </div>
+ <!-- Version Info -->
+ <div class="version-info">
+ <span id="a0version">Version {{version_no}} {{version_time}}</span>
+ </div>
+ </div>
+ </div>
+ <div id="right-panel" class="panel">
+ <!--Chat-->
<div id="time-date-container">
<div id="time-date"></div>
<div class="status-icon" x-data="{ connected: true }">
@@ -162,28 +364,187 @@
<!-- Notification Toggle positioned next to time-date -->
<x-component path="notifications/notification-icons.html"></x-component>
</div>
- <!-- Message History (actual messages) -->
- <div id="chat-history">
- </div>
- <!-- NEW: Toast Stack Component -->
- <div style="position: relative; height: 0;">
- <x-component path="notifications/notification-toast-stack.html"></x-component>
+ <!-- Welcome Screen Component -->
+ <div x-data x-show="$store.welcomeStore && $store.welcomeStore.isVisible">
+ <x-component path="welcome/welcome-screen.html"></x-component>
</div>
- <div id="toast" class="toast">
- <div class="toast__content">
- <div class="toast__title"></div>
- <div class="toast__separator"></div>
- <div class="toast__message"></div>
+ <!-- Chat History -->
+ <div id="chat-history" x-data x-show="!$store.welcomeStore || !$store.welcomeStore.isVisible"></div>
+
+ <!-- NEW: Toast Stack Component -->
+ <div style="position: relative; height: 0;">
+ <x-component path="notifications/notification-toast-stack.html"></x-component>
+ </div>
+
+ <div id="toast" class="toast">
+ <div class="toast__content">
+ <div class="toast__title"></div>
+ <div class="toast__separator"></div>
+ <div class="toast__message"></div>
+ </div>
+ <button class="toast__copy" style="display: none;">Copy</button>
+ <button class="toast__close">Close</button>
+ </div>
+
+ <div id="input-section" x-data="{
+ paused: false
+ }">
+
+ <div id="progress-bar-box">
+ <h4 id="progress-bar-h">
+ <span id="progress-bar-i">|></span><span id="progress-bar"></span>
+ </h4>
+ <h4 id="progress-bar-stop-speech" x-data x-cloak x-show="$store.speech.isSpeaking">
+ <span id="stop-speech" @click="$store.speech.stop()" style="cursor: pointer">Stop Speech</span>
+ </h4>
+ </div>
+
+ <!-- Attachment Preview section -->
+ <div>
+ <x-component path="/chat/attachments/inputPreview.html" />
+ </div>
+
+ <!-- Top row with input and buttons -->
+ <div class="input-row">
+ <!-- Attachment icon with tooltip -->
+ <div class="attachment-wrapper" x-data="{ showTooltip: false }">
+ <label for="file-input" class="attachment-icon" @mouseover="showTooltip = true"
+ @mouseleave="showTooltip = false">
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
+ fill="currentColor">
+ <path
+ d="M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5c0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z" />
+ </svg>
+ </label>
+ <input type="file" id="file-input" accept="*" multiple style="display: none"
+ @change="$store.chatAttachments.handleFileUpload($event)">
+
+ <div x-show="showTooltip" class="tooltip">
+ Add attachments to the message
+ </div>
+ </div>
+
+ <!-- Container for textarea and button -->
+ <div id="chat-input-container" style="position: relative;">
+ <textarea id="chat-input" placeholder="Type your message here..." rows="1"></textarea>
+
+
+ <!-- Expand button inside the textarea container -->
+ <button id="expand-button" @click="$store.fullScreenInputModal.openModal()"
+ aria-label="Expand input">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
+ <path
+ d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" />
+ </svg>
+ </button>
+ </div>
+
+ <div id="chat-buttons-wrapper">
+
+ <!-- Send button -->
+ <button class="chat-button" id="send-button" aria-label="Send message">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
+ <path d="M25 20 L75 50 L25 80" fill="none" stroke="currentColor" stroke-width="15">
+ </path>
+ </svg>
+ </button>
+
+ <!-- Microphone button -->
+ <button class="chat-button mic-inactive" id="microphone-button"
+ aria-label="Start/Stop recording" @click="$store.speech.handleMicrophoneClick()"
+ x-effect="$store.speech.updateMicrophoneButtonUI()">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 18" fill="currentColor">
+ <path
+ d="m8,12c1.66,0,3-1.34,3-3V3c0-1.66-1.34-3-3-3s-3,1.34-3,3v6c0,1.66,1.34,3,3,3Zm-1,1.9c-2.7-.4-4.8-2.6-5-5.4H0c.2,3.8,3.1,6.9,7,7.5v2h2v-2c3.9-.6,6.8-3.7,7-7.5h-2c-.2,2.8-2.3,5-5,5.4h-2Z" />
+ </svg>
+
+ </button>
+
+ </div>
+ </div>
+
+ <!-- Bottom row with text buttons -->
+ <div class="text-buttons-row">
+
+ <button class="text-button" @click="pauseAgent(!paused)">
+ <!-- Dynamic path that switches between pause and play icons -->
+ <template x-if="!paused">
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24"
+ stroke-width="1.5" stroke="currentColor" width="14" height="14">
+ <path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"></path>
+ </svg>
+ </template>
+ <template x-if="paused">
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24"
+ stroke-width="1.8" stroke="currentColor" width="14" height="14">
+ <path d="M8 5v14l11-7z"></path>
+ </svg>
+ </template>
+ </svg>
+ <span x-text="paused ? 'Resume Agent' : 'Pause Agent'"></span>
+ </button>
+
+ <button class="text-button" @click="loadKnowledge()"><svg xmlns="http://www.w3.org/2000/svg"
+ fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round"
+ d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5">
+ </path>
+ </svg>
+ <p>Import knowledge</p>
+ </button>
+ <button class="text-button" id="work_dir_browser" @click="fileBrowserModalProxy.openModal()">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 123.37 92.59">
+ <path
+ d="m5.72,11.5l-3.93,8.73h119.77s-3.96-8.73-3.96-8.73h-60.03c-1.59,0-2.88-1.29-2.88-2.88V1.75H13.72v6.87c0,1.59-1.29,2.88-2.88,2.88h-5.12Z"
+ fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="7"></path>
+ <path
+ d="m6.38,20.23H1.75l7.03,67.03c.11,1.07.55,2.02,1.2,2.69.55.55,1.28.89,2.11.89h97.1c.82,0,1.51-.33,2.05-.87.68-.68,1.13-1.67,1.28-2.79l9.1-66.94H6.38Z"
+ fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="8"></path>
+ </svg>
+ <p>Files</p>
+ </button>
+
+ <button class="text-button" id="history_inspect" @click="globalThis.openHistoryModal()">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="5 10 85 85">
+ <path fill="currentColor"
+ d="m59.572,57.949c-.41,0-.826-.105-1.207-.325l-9.574-5.528c-.749-.432-1.21-1.231-1.21-2.095v-14.923c0-1.336,1.083-2.419,2.419-2.419s2.419,1.083,2.419,2.419v13.526l8.364,4.829c1.157.668,1.554,2.148.886,3.305-.448.776-1.261,1.21-2.097,1.21Zm30.427-7.947c0,10.684-4.161,20.728-11.716,28.283-6.593,6.59-15.325,10.69-24.59,11.544-1.223.113-2.448.169-3.669.169-7.492,0-14.878-2.102-21.22-6.068l-15.356,5.733c-.888.331-1.887.114-2.557-.556s-.887-1.669-.556-2.557l5.733-15.351c-4.613-7.377-6.704-16.165-5.899-24.891.854-9.266,4.954-17.998,11.544-24.588,7.555-7.555,17.6-11.716,28.285-11.716s20.73,4.161,28.285,11.716c7.555,7.555,11.716,17.599,11.716,28.283Zm-15.137-24.861c-13.71-13.71-36.018-13.71-49.728,0-11.846,11.846-13.682,30.526-4.365,44.417.434.647.53,1.464.257,2.194l-4.303,11.523,11.528-4.304c.274-.102.561-.153.846-.153.474,0,.944.139,1.348.41,13.888,9.315,32.568,7.479,44.417-4.365,13.707-13.708,13.706-36.014,0-49.723Zm-24.861-4.13c-15.989,0-28.996,13.006-28.996,28.992s13.008,28.992,28.996,28.992c1.336,0,2.419-1.083,2.419-2.419s-1.083-2.419-2.419-2.419c-13.32,0-24.157-10.835-24.157-24.153s10.837-24.153,24.157-24.153,24.153,10.835,24.153,24.153c0,1.336,1.083,2.419,2.419,2.419s2.419-1.083,2.419-2.419c0-15.986-13.006-28.992-28.992-28.992Zm25.041,33.531c-1.294.347-2.057,1.673-1.71,2.963.343,1.289,1.669,2.057,2.963,1.71,1.289-.343,2.053-1.669,1.71-2.963-.347-1.289-1.673-2.057-2.963-1.71Zm-2.03,6.328c-1.335,0-2.419,1.084-2.419,2.419s1.084,2.419,2.419,2.419,2.419-1.084,2.419-2.419-1.084-2.419-2.419-2.419Zm-3.598,5.587c-1.289-.347-2.615.416-2.963,1.71-.343,1.289.421,2.615,1.71,2.963,1.294.347,2.62-.421,2.963-1.71.347-1.294-.416-2.62-1.71-2.963Zm-4.919,4.462c-1.157-.667-2.638-.27-3.306.887-.667,1.157-.27,2.638.887,3.305,1.157.668,2.638.27,3.306-.887.667-1.157.27-2.638-.887-3.306Zm-9.327,3.04c-.946.946-.946,2.478,0,3.42.942.946,2.473.946,3.42,0,.946-.942.946-2.473,0-3.42-.946-.946-2.478-.946-3.42,0Z">
+ </path>
+ </svg>
+ <p>History</p>
+ </button>
+
+ <button class="text-button" id="ctx_window" @click="globalThis.openCtxWindowModal()">
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="17 15 70 70" fill="currentColor">
+ <path
+ d="m63 25c1.1016 0 2-0.89844 2-2s-0.89844-2-2-2h-26c-1.1016 0-2 0.89844-2 2s0.89844 2 2 2z">
+ </path>
+ <path
+ d="m63 79c1.1016 0 2-0.89844 2-2s-0.89844-2-2-2h-26c-1.1016 0-2 0.89844-2 2s0.89844 2 2 2z">
+ </path>
+ <path
+ d="m68 39h-36c-6.0703 0-11 4.9297-11 11s4.9297 11 11 11h36c6.0703 0 11-4.9297 11-11s-4.9297-11-11-11zm0 18h-36c-3.8594 0-7-3.1406-7-7s3.1406-7 7-7h36c3.8594 0 7 3.1406 7 7s-3.1406 7-7 7z">
+ </path>
+ </svg>
+ <p>Context</p>
+ </button>
+
+ <button class="text-button" id="nudges_window" @click="nudge()">
+ <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 49 58"
+ fill="currentColor">
+ <path
+ d="m11.97,16.32c-.46,0-.91-.25-1.15-.68-.9-1.63-1.36-3.34-1.36-5.1C9.45,4.73,14.18,0,20,0s10.55,4.73,10.55,10.55c0,.87-.13,1.75-.41,2.76-.19.7-.9,1.13-1.62.93-.7-.19-1.12-.92-.93-1.62.21-.79.31-1.44.31-2.07,0-4.36-3.55-7.91-7.91-7.91s-7.91,3.55-7.91,7.91c0,1.3.35,2.59,1.03,3.82.36.64.13,1.44-.51,1.79-.21.11-.42.17-.64.17Z"
+ stroke-width="0.5" stroke="currentColor" />
+ <path
+ d="m34.5,58h-6.18c-3.17,0-6.15-1.23-8.39-3.47L1.16,35.75c-1.54-1.54-1.54-4.05,0-5.59,2.4-2.4,6.27-2.68,8.99-.64l4.58,3.44V10.55c0-2.91,2.36-5.27,5.27-5.27s5.27,2.36,5.27,5.27v8.62c.78-.45,1.68-.71,2.64-.71,2.3,0,4.26,1.48,4.98,3.53.84-.56,1.85-.89,2.93-.89,2.3,0,4.26,1.48,4.98,3.53.84-.56,1.85-.89,2.93-.89,2.91,0,5.27,2.36,5.27,5.27v14.5c0,8-6.51,14.5-14.5,14.5ZM6.03,30.79c-1.1,0-2.19.42-3.01,1.23-.51.51-.51,1.35,0,1.86l18.77,18.78c1.74,1.74,4.06,2.7,6.53,2.7h6.18c6.54,0,11.86-5.32,11.86-11.86v-14.5c0-1.45-1.18-2.64-2.64-2.64s-2.64,1.18-2.64,2.64v1.32c0,.73-.59,1.32-1.32,1.32s-1.32-.59-1.32-1.32v-3.95c0-1.45-1.18-2.64-2.64-2.64s-2.64,1.18-2.64,2.64v3.95c0,.73-.59,1.32-1.32,1.32s-1.32-.59-1.32-1.32v-6.59c0-1.45-1.18-2.64-2.64-2.64s-2.64,1.18-2.64,2.64v6.59c0,.73-.59,1.32-1.32,1.32s-1.32-.59-1.32-1.32V10.55c0-1.45-1.18-2.64-2.64-2.64s-2.64,1.18-2.64,2.64v25.05c0,.5-.28.95-.73,1.18s-.98.18-1.38-.12l-6.69-5.02c-.75-.56-1.65-.84-2.54-.84Z"
+ stroke-width="0.5" stroke="currentColor" />
+ </svg>
+ <p>Nudge</p>
+ </button>
+
</div>
- <button class="toast__copy" style="display: none;">Copy</button>
- <button class="toast__close">Close</button>
</div>
- <!-- Progress Bar -->
- <x-component path="chat/input/progress.html"></x-component>
- <!-- Input Section -->
- <x-component path="chat/input/chat-bar.html"></x-component>
</div>
</div>
<div id="settingsModal" x-data="settingsModalProxy">
@@ -1330,13 +1691,77 @@
</div>
<!-- Full Screen Input Modal -->
- <x-component path="modals/full-screen-input.html"></x-component>
+ <div id="fullScreenInputModal" x-data="fullScreenInputModalProxy">
+ <template x-teleport="body">
+ <div x-show="isOpen" class="modal-overlay" @click.self="handleClose()"
+ @keydown.escape.window="handleClose()" x-transition>
+ <div class="modal-container full-screen-input-modal">
+ <div class="modal-content">
+ <button class="modal-close" @click="handleClose()">&times;</button>
+
+ <!-- Add toolbar -->
+ <div class="editor-toolbar">
+ <div class="toolbar-group">
+ <button class="toolbar-button" @click="undo()" :disabled="!canUndo"
+ title="Undo (Ctrl+Z)">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
+ stroke="currentColor" stroke-width="2">
+ <path d="M3 7v6h6"></path>
+ <path d="M21 17a9 9 0 00-9-9 9 9 0 00-6 2.3L3 13"></path>
+ </svg>
+ </button>
+ <button class="toolbar-button" @click="redo()" :disabled="!canRedo"
+ title="Redo (Ctrl+Shift+Z)">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
+ stroke="currentColor" stroke-width="2">
+ <path d="M21 7v6h-6"></path>
+ <path d="M3 17a9 9 0 019-9 9 9 0 016 2.3l3 2.7"></path>
+ </svg>
+ </button>
+ </div>
+ <div class="toolbar-group">
+ <button class="toolbar-button" @click="clearText()" title="Clear Text">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
+ stroke="currentColor" stroke-width="2">
+ <path
+ d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2">
+ </path>
+ <line x1="10" y1="11" x2="10" y2="17"></line>
+ <line x1="14" y1="11" x2="14" y2="17"></line>
+ </svg>
+ </button>
+ <button class="toolbar-button" @click="toggleWrap()" :class="{ active: wordWrap }"
+ title="Toggle Word Wrap">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
+ stroke="currentColor" stroke-width="2">
+ <path d="M3 6h18M3 12h15l3 3-3 3M3 18h18"></path>
+ </svg>
+ </button>
+ </div>
+ </div>
+
+ <textarea id="full-screen-input" x-model="inputText" placeholder="Type your message here..."
+ @keydown.ctrl.enter="handleClose()" @keydown.ctrl.z.prevent="undo()"
+ @keydown.ctrl.shift.z.prevent="redo()"
+ :style="{ 'white-space': wordWrap ? 'pre-wrap' : 'pre' }"
+ @input="updateHistory()"></textarea>
+ </div>
+ <div class="modal-footer">
+ <div id="buttons-container">
+ <button class="btn btn-ok" @click="handleClose()">Done (Ctrl+Enter)</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </template>
+ </div>
<!-- Drag and Drop Overlay Component -->
<x-component path="chat/attachments/dragDropOverlay.html"></x-component>
<!-- Register Service Worker for offline support and caching -->
<script>
+<<<<<<< HEAD
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('js/sw.js').then(registration => {
@@ -1346,6 +1771,17 @@
});
});
}
+=======
+ if ('serviceWorker' in navigator) {
+ window.addEventListener('load', () => {
+ navigator.serviceWorker.register('js/sw.js').then(registration => {
+ console.log('SW registered: ', registration);
+ }).catch(registrationError => {
+ console.log('SW registration failed: ', registrationError);
+ });
+ });
+ }
+>>>>>>> ad28629 ( Add welcome screen component with dashboard functionality)
</script>
</body>
diff --git a/webui/index.js b/webui/index.js
index abe05ca9e..25f7eaeb5 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -5,45 +5,112 @@ import { sleep } from "/js/sleep.js";
import { store as attachmentsStore } from "/components/chat/attachments/attachmentsStore.js";
import { store as speechStore } from "/components/chat/speech/speech-store.js";
import { store as notificationStore } from "/components/notifications/notification-store.js";
-import { store as preferencesStore } from "/components/sidebar/bottom/preferences/preferences-store.js";
-import { store as inputStore } from "/components/chat/input/input-store.js";
-import { store as chatsStore } from "/components/sidebar/chats/chats-store.js";
-import { store as tasksStore } from "/components/sidebar/tasks/tasks-store.js";
+import { store as contextStore } from "/components/chat/context/context-store.js";
globalThis.fetchApi = api.fetchApi; // TODO - backward compatibility for non-modular scripts, remove once refactored to alpine
-// Declare variables for DOM elements, they will be assigned on DOMContentLoaded
-let leftPanel, rightPanel, container, chatInput, chatHistory, sendButton, inputSection, statusSection, progressBar, autoScrollSwitch, timeDate;
+const chatInput = document.getElementById("chat-input");
+const chatHistory = document.getElementById("chat-history");
+const sendButton = document.getElementById("send-button");
+const inputSection = document.getElementById("input-section");
+const chatsSection = document.getElementById("chats-section");
+const tasksSection = document.getElementById("tasks-section");
+const progressBar = document.getElementById("progress-bar");
+const autoScrollSwitch = document.getElementById("auto-scroll-switch");
+const timeDate = document.getElementById("time-date-container");
let autoScroll = true;
-let context = "";
-globalThis.resetCounter = 0; // Used by stores and getChatBasedId
+let context = null;
+let resetCounter = 0;
let skipOneSpeech = false;
let connectionStatus = undefined; // undefined = not checked yet, true = connected, false = disconnected
+// Initialize the toggle button
+setupSidebarToggle();
+// Initialize tabs
+setupTabs();
+
export function getAutoScroll() {
return autoScroll;
}
-// Sidebar toggle logic is now handled by sidebar-store.js
+function isMobile() {
+ return window.innerWidth <= 768;
+}
-export async function sendMessage() {
- const chatInputEl = document.getElementById("chat-input");
- if (!chatInputEl) {
- console.warn("chatInput not available, cannot send message");
- return;
+function toggleSidebar(show) {
+ const overlay = document.getElementById("sidebar-overlay");
+ if (typeof show === "boolean") {
+ leftPanel.classList.toggle("hidden", !show);
+ rightPanel.classList.toggle("expanded", !show);
+ overlay.classList.toggle("visible", show);
+ } else {
+ leftPanel.classList.toggle("hidden");
+ rightPanel.classList.toggle("expanded");
+ overlay.classList.toggle(
+ "visible",
+ !leftPanel.classList.contains("hidden"),
+ );
+ }
+}
+
+function handleResize() {
+ const leftPanel = document.getElementById("left-panel");
+ const rightPanel = document.getElementById("right-panel");
+ const overlay = document.getElementById("sidebar-overlay");
+ if (isMobile()) {
+ leftPanel.classList.add("hidden");
+ rightPanel.classList.add("expanded");
+ overlay.classList.remove("visible");
+ } else {
+ leftPanel.classList.remove("hidden");
+ rightPanel.classList.remove("expanded");
+ overlay.classList.remove("visible");
+ }
+}
+
+globalThis.addEventListener("load", handleResize);
+globalThis.addEventListener("resize", handleResize);
+
+document.addEventListener("DOMContentLoaded", () => {
+ const overlay = document.getElementById("sidebar-overlay");
+ overlay.addEventListener("click", () => {
+ if (isMobile()) {
+ toggleSidebar(false);
+ }
+ });
+});
+
+function setupSidebarToggle() {
+ const leftPanel = document.getElementById("left-panel");
+ const rightPanel = document.getElementById("right-panel");
+ const toggleSidebarButton = document.getElementById("toggle-sidebar");
+ if (toggleSidebarButton) {
+ toggleSidebarButton.addEventListener("click", toggleSidebar);
+ } else {
+ console.error("Toggle sidebar button not found");
+ setTimeout(setupSidebarToggle, 100);
}
+}
+document.addEventListener("DOMContentLoaded", setupSidebarToggle);
+
+export async function sendMessage() {
try {
- const message = chatInputEl.value.trim();
+ const message = chatInput.value.trim();
const attachmentsWithUrls = attachmentsStore.getAttachmentsForSending();
const hasAttachments = attachmentsWithUrls.length > 0;
if (message || hasAttachments) {
+ // Create new context if none exists (e.g., sending from welcome screen)
+ if (!context) {
+ newContext();
+ }
+
let response;
const messageId = generateGUID();
// Clear input and attachments
- chatInputEl.value = "";
+ chatInput.value = "";
attachmentsStore.clearAttachments();
adjustTextareaHeight();
@@ -103,7 +170,6 @@ export async function sendMessage() {
toastFetchError("Error sending message", e); // Will use new notification system
}
}
-globalThis.sendMessage = sendMessage;
function toastFetchError(text, error) {
console.error(text, error);
@@ -113,38 +179,41 @@ function toastFetchError(text, error) {
if (getConnectionStatus()) {
// Backend is connected, just show the error
toastFrontendError(`${text}: ${errorMessage}`).catch((e) =>
- console.error("Failed to show error toast:", e)
+ console.error("Failed to show error toast:", e),
);
} else {
// Backend is disconnected, show connection error
toastFrontendError(
`${text} (backend appears to be disconnected): ${errorMessage}`,
- "Connection Error"
+ "Connection Error",
).catch((e) => console.error("Failed to show connection error toast:", e));
}
}
globalThis.toastFetchError = toastFetchError;
-// Event listeners will be set up in DOMContentLoaded
-
-export function updateChatInput(text) {
- const chatInputEl = document.getElementById("chat-input");
- if (!chatInputEl) {
- console.warn("`chatInput` element not found, cannot update.");
- return;
+chatInput.addEventListener("keydown", (e) => {
+ if (
+ e.key === "Enter" &&
+ !e.shiftKey &&
+ !e.isComposing &&
+ e.key !== "Process"
+ ) {
+ e.preventDefault();
+ sendMessage();
}
- console.log("updateChatInput called with:", text);
+});
+
+sendButton.addEventListener("click", sendMessage);
+export function updateChatInput(text) {
// Append text with proper spacing
- const currentValue = chatInputEl.value;
+ const currentValue = chatInput.value;
const needsSpace = currentValue.length > 0 && !currentValue.endsWith(" ");
- chatInputEl.value = currentValue + (needsSpace ? " " : "") + text + " ";
+ chatInput.value = currentValue + (needsSpace ? " " : "") + text + " ";
// Adjust height and trigger input event
adjustTextareaHeight();
- chatInputEl.dispatchEvent(new Event("input"));
-
- console.log("Updated chat input value:", chatInputEl.value);
+ chatInput.dispatchEvent(new Event("input"));
}
function updateUserTime() {
@@ -174,23 +243,50 @@ setInterval(updateUserTime, 1000);
function setMessage(id, type, heading, content, temp, kvps = null) {
const result = msgs.setMessage(id, type, heading, content, temp, kvps);
- const chatHistoryEl = document.getElementById("chat-history");
- if (autoScroll && chatHistoryEl) {
- chatHistoryEl.scrollTop = chatHistoryEl.scrollHeight;
- }
+ if (autoScroll) chatHistory.scrollTop = chatHistory.scrollHeight;
return result;
}
globalThis.loadKnowledge = async function () {
- await inputStore.loadKnowledge();
+ const input = document.createElement("input");
+ input.type = "file";
+ input.accept = ".txt,.pdf,.csv,.html,.json,.md";
+ input.multiple = true;
+
+ input.onchange = async () => {
+ try {
+ const formData = new FormData();
+ for (let file of input.files) {
+ formData.append("files[]", file);
+ }
+
+ formData.append("ctxid", getContext());
+
+ const response = await api.fetchApi("/import_knowledge", {
+ method: "POST",
+ body: formData,
+ });
+
+ if (!response.ok) {
+ toast(await response.text(), "error");
+ } else {
+ const data = await response.json();
+ toast(
+ "Knowledge files imported: " + data.filenames.join(", "),
+ "success",
+ );
+ }
+ } catch (e) {
+ toastFetchError("Error loading knowledge", e);
+ }
+ };
+
+ input.click();
};
function adjustTextareaHeight() {
- const chatInputEl = document.getElementById("chat-input");
- if (chatInputEl) {
- chatInputEl.style.height = "auto";
- chatInputEl.style.height = chatInputEl.scrollHeight + "px";
- }
+ chatInput.style.height = "auto";
+ chatInput.style.height = chatInput.scrollHeight + "px";
}
export const sendJsonData = async function (url, data) {
@@ -223,21 +319,22 @@ function generateGUID() {
function getConnectionStatus() {
return connectionStatus;
}
-globalThis.getConnectionStatus = getConnectionStatus;
function setConnectionStatus(connected) {
connectionStatus = connected;
- // Broadcast connection status without touching Alpine directly
- try {
- window.dispatchEvent(new CustomEvent("connection-status", { detail: { connected } }));
- } catch (_e) {
- // no-op
+ if (globalThis.Alpine && timeDate) {
+ const statusIconEl = timeDate.querySelector(".status-icon");
+ if (statusIconEl) {
+ const statusIcon = Alpine.$data(statusIconEl);
+ if (statusIcon) {
+ statusIcon.connected = connected;
+ }
+ }
}
}
let lastLogVersion = 0;
let lastLogGuid = "";
-let lastSpokenNo = 0;
async function poll() {
let updated = false;
@@ -259,13 +356,18 @@ async function poll() {
return false;
}
- if (!context) setContext(response.context);
- if (response.context != context) return; //skip late polls after context change
+ // Skip late polls after context change, but allow polls when both are null or when current context is null (initial load)
+ if (
+ response.context != context &&
+ !(response.context === null && context === null) &&
+ context !== null
+ ) {
+ return;
+ }
// if the chat has been reset, restart this poll as it may have been called with incorrect log_from
if (lastLogGuid != response.log_guid) {
- const chatHistoryEl = document.getElementById("chat-history");
- if (chatHistoryEl) chatHistoryEl.innerHTML = "";
+ chatHistory.innerHTML = "";
lastLogVersion = 0;
lastLogGuid = response.log_guid;
await poll();
@@ -282,7 +384,7 @@ async function poll() {
log.heading,
log.content,
log.temp,
- log.kvps
+ log.kvps,
);
}
afterMessagesUpdate(response.logs);
@@ -297,46 +399,139 @@ async function poll() {
notificationStore.updateFromPoll(response);
//set ui model vars from backend
- inputStore.paused = response.paused;
+ if (globalThis.Alpine && inputSection) {
+ const inputAD = Alpine.$data(inputSection);
+ if (inputAD) {
+ inputAD.paused = response.paused;
+ }
+ }
// Update status icon state
setConnectionStatus(true);
- // Update chats list using store
+ // Update chats list and sort by created_at time (newer first)
+ let chatsAD = null;
let contexts = response.contexts || [];
- chatsStore.applyContexts(contexts);
- // Update tasks list using store
- let tasks = response.tasks || [];
- tasksStore.applyTasks(tasks);
+ // Get chatsSection fresh each time to ensure it exists
+ const currentChatsSection = document.getElementById("chats-section");
+
+ if (globalThis.Alpine && currentChatsSection) {
+ try {
+ chatsAD = Alpine.$data(currentChatsSection);
+ if (chatsAD) {
+ const sortedContexts = contexts.sort(
+ (a, b) => (b.created_at || 0) - (a.created_at || 0),
+ );
+ chatsAD.contexts = sortedContexts;
+ } else {
+ console.warn("chatsAD is null - Alpine data not available yet");
+ }
+ } catch (error) {
+ console.error("Error updating chats data:", error);
+ }
+ } else {
+ console.warn(
+ "Missing requirements - Alpine:",
+ !!globalThis.Alpine,
+ "chatsSection:",
+ !!currentChatsSection,
+ );
+ }
+
+ // Update tasks list and sort by creation time (newer first)
+ const tasksSection = document.getElementById("tasks-section");
+ if (globalThis.Alpine && tasksSection) {
+ const tasksAD = Alpine.$data(tasksSection);
+ if (tasksAD) {
+ let tasks = response.tasks || [];
+
+ // Always update tasks to ensure state changes are reflected
+ if (tasks.length > 0) {
+ // Sort the tasks by creation time
+ const sortedTasks = [...tasks].sort(
+ (a, b) => (b.created_at || 0) - (a.created_at || 0),
+ );
+
+ // Assign the sorted tasks to the Alpine data
+ tasksAD.tasks = sortedTasks;
+ } else {
+ // Make sure to use a new empty array instance
+ tasksAD.tasks = [];
+ }
+ }
+ }
// Make sure the active context is properly selected in both lists
if (context) {
- // Update selection in both stores
- chatsStore.setSelected(context);
-
- // Check if this context exists in the chats list
- const contextExists = chatsStore.contains(context);
-
- // If it doesn't exist in the chats list, try to select the first chat
- if (!contextExists && chatsStore.contexts.length > 0) {
- const firstChatId = chatsStore.firstId();
- if (firstChatId) {
+ // Update selection in the active tab
+ const activeTab = localStorage.getItem("activeTab") || "chats";
+
+ if (activeTab === "chats" && chatsAD) {
+ chatsAD.selected = context;
+ localStorage.setItem("lastSelectedChat", context);
+
+ // Check if this context exists in the chats list
+ const contextExists = contexts.some((ctx) => ctx.id === context);
+
+ // If it doesn't exist in the chats list but we're in chats tab, try to select the first chat
+ // Only do this if there was already a context set (not on initial page load)
+ if (!contextExists && contexts.length > 0 && context !== null) {
+ const firstChatId = contexts[0].id;
setContext(firstChatId);
- chatsStore.setSelected(firstChatId);
+ chatsAD.selected = firstChatId;
+ localStorage.setItem("lastSelectedChat", firstChatId);
+ }
+ } else if (activeTab === "tasks" && tasksSection) {
+ const tasksAD = Alpine.$data(tasksSection);
+ tasksAD.selected = context;
+ localStorage.setItem("lastSelectedTask", context);
+
+ // Check if this context exists in the tasks list
+ const taskExists = response.tasks?.some((task) => task.id === context);
+
+ // If it doesn't exist in the tasks list but we're in tasks tab, try to select the first task
+ // Only do this if there was already a context set (not on initial page load)
+ if (!taskExists && response.tasks?.length > 0 && context !== null) {
+ const firstTaskId = response.tasks[0].id;
+ setContext(firstTaskId);
+ tasksAD.selected = firstTaskId;
+ localStorage.setItem("lastSelectedTask", firstTaskId);
}
}
-
- tasksStore.setSelected(context);
- } else {
- // No context selected, try to select the first available item
- if (contexts.length > 0) {
- const firstChatId = chatsStore.firstId();
- if (firstChatId) {
- setContext(firstChatId);
- chatsStore.setSelected(firstChatId);
+ } else if (
+ response.tasks &&
+ response.tasks.length > 0 &&
+ localStorage.getItem("activeTab") === "tasks" &&
+ localStorage.getItem("lastSelectedTask")
+ ) {
+ // Only auto-select tasks if we have a previously selected task ID
+ const lastSelectedTask = localStorage.getItem("lastSelectedTask");
+ const taskExists = response.tasks.some(
+ (task) => task.id === lastSelectedTask,
+ );
+ if (taskExists) {
+ setContext(lastSelectedTask);
+ if (tasksSection) {
+ const tasksAD = Alpine.$data(tasksSection);
+ tasksAD.selected = lastSelectedTask;
}
}
+ } else if (
+ contexts.length > 0 &&
+ localStorage.getItem("activeTab") === "chats" &&
+ chatsAD &&
+ localStorage.getItem("lastSelectedChat")
+ ) {
+ // Only auto-select chats if we have a previously selected chat ID
+ const lastSelectedChat = localStorage.getItem("lastSelectedChat");
+ const chatExists = contexts.some((ctx) => ctx.id === lastSelectedChat);
+
+ // Don't auto-select - let user manually select or start from welcome screen
+ if (chatExists && !context) {
+ setContext(lastSelectedChat);
+ chatsAD.selected = lastSelectedChat;
+ }
}
lastLogVersion = response.log_version;
@@ -348,7 +543,6 @@ async function poll() {
return updated;
}
-globalThis.poll = poll;
function afterMessagesUpdate(logs) {
if (localStorage.getItem("speech") == "true") {
@@ -374,7 +568,7 @@ function speakMessages(logs) {
speechStore.speakStream(
getChatBasedId(log.no),
log.content,
- log.kvps?.finished
+ log.kvps?.finished,
);
return;
@@ -394,46 +588,178 @@ function speakMessages(logs) {
}
function updateProgress(progress, active) {
- const progressBarEl = document.getElementById("progress-bar");
- if (!progressBarEl) return;
if (!progress) progress = "";
if (!active) {
- removeClassFromElement(progressBarEl, "shiny-text");
+ removeClassFromElement(progressBar, "shiny-text");
} else {
- addClassToElement(progressBarEl, "shiny-text");
+ addClassToElement(progressBar, "shiny-text");
}
progress = msgs.convertIcons(progress);
- if (progressBarEl.innerHTML != progress) {
- progressBarEl.innerHTML = progress;
+ if (progressBar.innerHTML != progress) {
+ progressBar.innerHTML = progress;
}
}
globalThis.pauseAgent = async function (paused) {
- await inputStore.pauseAgent(paused);
+ try {
+ await sendJsonData("/pause", { paused: paused, context });
+ } catch (e) {
+ globalThis.toastFetchError("Error pausing agent", e);
+ }
};
globalThis.resetChat = async function (ctxid = null) {
- await chatsStore.resetChat(ctxid);
+ try {
+ await sendJsonData("/chat_reset", {
+ context: ctxid === null ? context : ctxid,
+ });
+ resetCounter++;
+ if (ctxid === null) updateAfterScroll();
+ } catch (e) {
+ globalThis.toastFetchError("Error resetting chat", e);
+ }
};
globalThis.newChat = async function () {
- await chatsStore.newChat();
+ try {
+ newContext();
+ updateAfterScroll();
+ } catch (e) {
+ globalThis.toastFetchError("Error creating new chat", e);
+ }
};
globalThis.killChat = async function (id) {
- await chatsStore.killChat(id);
+ if (!id) {
+ console.error("No chat ID provided for deletion");
+ return;
+ }
+
+ try {
+ const chatsAD = Alpine.$data(chatsSection);
+
+ // switch to another context if deleting current
+ switchFromContext(id);
+
+ // Delete the chat on the server
+ await sendJsonData("/chat_remove", { context: id });
+
+ // Update the UI manually to ensure the correct chat is removed
+ // Deep clone the contexts array to prevent reference issues
+ const updatedContexts = chatsAD.contexts.filter((ctx) => ctx.id !== id);
+
+ // Force UI update by creating a new array
+ chatsAD.contexts = [...updatedContexts];
+
+ updateAfterScroll();
+
+ justToast("Chat deleted successfully", "success", 1000, "chat-removal");
+ } catch (e) {
+ console.error("Error deleting chat:", e);
+ globalThis.toastFetchError("Error deleting chat", e);
+ }
};
+export function switchFromContext(id) {
+ // If we're deleting the currently selected chat, switch to another one first
+ if (context === id) {
+ const chatsAD = Alpine.$data(chatsSection);
+
+ // Find an alternate chat to switch to if we're deleting the current one
+ let alternateChat = null;
+ for (let i = 0; i < chatsAD.contexts.length; i++) {
+ if (chatsAD.contexts[i].id !== id) {
+ alternateChat = chatsAD.contexts[i];
+ break;
+ }
+ }
+
+ if (alternateChat) {
+ setContext(alternateChat.id);
+ } else {
+ // If no other chats, show welcome screen instead of creating new context
+ deselectChat();
+ }
+ }
+}
+
+// Function to ensure proper UI state when switching contexts
+function ensureProperTabSelection(contextId) {
+ // Get current active tab
+ const activeTab = localStorage.getItem("activeTab") || "chats";
+
+ // First attempt to determine if this is a task or chat based on the task list
+ const tasksSection = document.getElementById("tasks-section");
+ let isTask = false;
+
+ if (tasksSection) {
+ const tasksAD = Alpine.$data(tasksSection);
+ if (tasksAD && tasksAD.tasks) {
+ isTask = tasksAD.tasks.some((task) => task.id === contextId);
+ }
+ }
+
+ // If we're selecting a task but are in the chats tab, switch to tasks tab
+ if (isTask && activeTab === "chats") {
+ // Store this as the last selected task before switching
+ localStorage.setItem("lastSelectedTask", contextId);
+ activateTab("tasks");
+ return true;
+ }
+
+ // If we're selecting a chat but are in the tasks tab, switch to chats tab
+ if (!isTask && activeTab === "tasks") {
+ // Store this as the last selected chat before switching
+ localStorage.setItem("lastSelectedChat", contextId);
+ activateTab("chats");
+ return true;
+ }
+
+ return false;
+}
+
globalThis.selectChat = async function (id) {
- await chatsStore.selectChat(id);
+ if (id === context) return; //already selected
+
+ // Check if we need to switch tabs based on the context type
+ const tabSwitched = ensureProperTabSelection(id);
+
+ // If we didn't switch tabs, proceed with normal selection
+ if (!tabSwitched) {
+ // Switch to the new context - this will clear chat history and reset tracking variables
+ setContext(id);
+
+ // Update both contexts and tasks lists to reflect the selected item
+ const chatsAD = Alpine.$data(chatsSection);
+ const tasksSection = document.getElementById("tasks-section");
+ if (tasksSection) {
+ const tasksAD = Alpine.$data(tasksSection);
+ tasksAD.selected = id;
+ }
+ chatsAD.selected = id;
+
+ // Store this selection in the appropriate localStorage key
+ const activeTab = localStorage.getItem("activeTab") || "chats";
+ if (activeTab === "chats") {
+ localStorage.setItem("lastSelectedChat", id);
+ } else if (activeTab === "tasks") {
+ localStorage.setItem("lastSelectedTask", id);
+ }
+
+ // Trigger an immediate poll to fetch content
+ poll();
+ }
+
+ updateAfterScroll();
};
function generateShortId() {
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- let result = '';
+ const chars =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ let result = "";
for (let i = 0; i < 8; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
@@ -443,28 +769,39 @@ function generateShortId() {
export const newContext = function () {
context = generateShortId();
setContext(context);
-}
-globalThis.newContext = newContext;
+};
export const setContext = function (id) {
if (id == context) return;
context = id;
+ // Update the reactive stores
+ contextStore.setContext(id);
+ contextStore.context = id;
// Always reset the log tracking variables when switching contexts
// This ensures we get fresh data from the backend
lastLogGuid = "";
lastLogVersion = 0;
- lastSpokenNo = 0;
// Stop speech when switching chats
speechStore.stopAudio();
- // Clear the chat history immediately to avoid showing stale content
- const chatHistoryEl = document.getElementById("chat-history");
- if (chatHistoryEl) chatHistoryEl.innerHTML = "";
+ if (id) {
+ chatHistory.innerHTML = "";
+ }
- // Update both selected states using stores
- chatsStore.setSelected(id);
- tasksStore.setSelected(id);
+ // Update both selected states
+ if (globalThis.Alpine) {
+ if (chatsSection) {
+ const chatsAD = Alpine.$data(chatsSection);
+ if (chatsAD) chatsAD.selected = id || "";
+ }
+ if (tasksSection) {
+ const tasksAD = Alpine.$data(tasksSection);
+ if (tasksAD) tasksAD.selected = id || "";
+ }
+
+ // Alpine store reactivity will handle the UI updates automatically
+ }
//skip one speech if enabled when switching context
if (localStorage.getItem("speech") == "true") skipOneSpeech = true;
@@ -472,12 +809,23 @@ export const setContext = function (id) {
export const getContext = function () {
return context;
-}
+};
globalThis.getContext = getContext;
-globalThis.setContext = setContext;
+
+export const deselectChat = function () {
+ // Clear current context to show welcome screen
+ setContext(null);
+
+ // Clear localStorage selections so we don't auto-restore
+ localStorage.removeItem("lastSelectedChat");
+ localStorage.removeItem("lastSelectedTask");
+
+ // Clear the chat history
+ chatHistory.innerHTML = "";
+};
export const getChatBasedId = function (id) {
- return context + "-" + globalThis.resetCounter + "-" + id;
+ return context + "-" + resetCounter + "-" + id;
};
globalThis.toggleAutoScroll = async function (_autoScroll) {
@@ -492,7 +840,7 @@ globalThis.toggleThoughts = async function (showThoughts) {
css.toggleCssProperty(
".msg-thoughts",
"display",
- showThoughts ? undefined : "none"
+ showThoughts ? undefined : "none",
);
};
@@ -500,7 +848,7 @@ globalThis.toggleUtils = async function (showUtils) {
css.toggleCssProperty(
".message-util",
"display",
- showUtils ? undefined : "none"
+ showUtils ? undefined : "none",
);
};
@@ -512,7 +860,6 @@ globalThis.toggleDarkMode = function (isDark) {
document.body.classList.remove("dark-mode");
document.body.classList.add("light-mode");
}
- console.log("Dark mode:", isDark);
localStorage.setItem("darkMode", isDark);
};
@@ -523,11 +870,53 @@ globalThis.toggleSpeech = function (isOn) {
};
globalThis.nudge = async function () {
- await inputStore.nudge();
+ try {
+ await sendJsonData("/nudge", { ctxid: getContext() });
+ } catch (e) {
+ toastFetchError("Error nudging agent", e);
+ }
};
globalThis.restart = async function () {
- await chatsStore.restart();
+ try {
+ if (!getConnectionStatus()) {
+ await toastFrontendError(
+ "Backend disconnected, cannot restart.",
+ "Restart Error",
+ );
+ return;
+ }
+ // First try to initiate restart
+ await sendJsonData("/restart", {});
+ } catch (e) {
+ // Show restarting message with no timeout and restart group
+ await toastFrontendInfo("Restarting...", "System Restart", 9999, "restart");
+
+ let retries = 0;
+ const maxRetries = 240; // Maximum number of retries (60 seconds with 250ms interval)
+
+ while (retries < maxRetries) {
+ try {
+ await sendJsonData("/health", {});
+ // Server is back up, show success message that replaces the restarting message
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ await toastFrontendSuccess("Restarted", "System Restart", 5, "restart");
+ return;
+ } catch (e) {
+ // Server still down, keep waiting
+ retries++;
+ await new Promise((resolve) => setTimeout(resolve, 250));
+ }
+ }
+
+ // If we get here, restart failed or took too long
+ await toastFrontendError(
+ "Restart timed out or failed",
+ "Restart Error",
+ 8,
+ "restart",
+ );
+ }
};
// Modify this part
@@ -537,13 +926,113 @@ document.addEventListener("DOMContentLoaded", () => {
});
globalThis.loadChats = async function () {
- await chatsStore.loadChats();
+ try {
+ const fileContents = await readJsonFiles();
+ const response = await sendJsonData("/chat_load", { chats: fileContents });
+
+ if (!response) {
+ toast("No response returned.", "error");
+ }
+ // else if (!response.ok) {
+ // if (response.message) {
+ // toast(response.message, "error")
+ // } else {
+ // toast("Undefined error.", "error")
+ // }
+ // }
+ else {
+ setContext(response.ctxids[0]);
+ toast("Chats loaded.", "success");
+ }
+ } catch (e) {
+ toastFetchError("Error loading chats", e);
+ }
};
globalThis.saveChat = async function () {
- await chatsStore.saveChat();
+ try {
+ const response = await sendJsonData("/chat_export", { ctxid: context });
+
+ if (!response) {
+ toast("No response returned.", "error");
+ }
+ // else if (!response.ok) {
+ // if (response.message) {
+ // toast(response.message, "error")
+ // } else {
+ // toast("Undefined error.", "error")
+ // }
+ // }
+ else {
+ downloadFile(response.ctxid + ".json", response.content);
+ toast("Chat file downloaded.", "success");
+ }
+ } catch (e) {
+ toastFetchError("Error saving chat", e);
+ }
};
+function downloadFile(filename, content) {
+ // Create a Blob with the content to save
+ const blob = new Blob([content], { type: "application/json" });
+
+ // Create a link element
+ const link = document.createElement("a");
+
+ // Create a URL for the Blob
+ const url = URL.createObjectURL(blob);
+ link.href = url;
+
+ // Set the file name for download
+ link.download = filename;
+
+ // Programmatically click the link to trigger the download
+ link.click();
+
+ // Clean up by revoking the object URL
+ setTimeout(() => {
+ URL.revokeObjectURL(url);
+ }, 0);
+}
+
+function readJsonFiles() {
+ return new Promise((resolve, reject) => {
+ // Create an input element of type 'file'
+ const input = document.createElement("input");
+ input.type = "file";
+ input.accept = ".json"; // Only accept JSON files
+ input.multiple = true; // Allow multiple file selection
+
+ // Trigger the file dialog
+ input.click();
+
+ // When files are selected
+ input.onchange = async () => {
+ const files = input.files;
+ if (!files.length) {
+ resolve([]); // Return an empty array if no files are selected
+ return;
+ }
+
+ // Read each file as a string and store in an array
+ const filePromises = Array.from(files).map((file) => {
+ return new Promise((fileResolve, fileReject) => {
+ const reader = new FileReader();
+ reader.onload = () => fileResolve(reader.result);
+ reader.onerror = fileReject;
+ reader.readAsText(file);
+ });
+ });
+
+ try {
+ const fileContents = await Promise.all(filePromises);
+ resolve(fileContents);
+ } catch (error) {
+ reject(error); // In case of any file reading error
+ }
+ };
+ });
+}
function addClassToElement(element, className) {
element.classList.add(className);
@@ -554,42 +1043,38 @@ function removeClassFromElement(element, className) {
}
function justToast(text, type = "info", timeout = 5000, group = "") {
- notificationStore.addFrontendToastOnly(
- type,
- text,
- "",
- timeout / 1000,
- group
- )
+ notificationStore.addFrontendToastOnly(type, text, "", timeout / 1000, group);
}
-globalThis.justToast = justToast;
-
function toast(text, type = "info", timeout = 5000) {
// Convert timeout from milliseconds to seconds for new notification system
const display_time = Math.max(timeout / 1000, 1); // Minimum 1 second
// Use new frontend notification system based on type
- switch (type.toLowerCase()) {
- case "error":
- return notificationStore.frontendError(text, "Error", display_time);
- case "success":
- return notificationStore.frontendInfo(text, "Success", display_time);
- case "warning":
- return notificationStore.frontendWarning(text, "Warning", display_time);
- case "info":
- default:
- return notificationStore.frontendInfo(text, "Info", display_time);
- }
-
+ switch (type.toLowerCase()) {
+ case "error":
+ return notificationStore.frontendError(text, "Error", display_time);
+ case "success":
+ return notificationStore.frontendInfo(text, "Success", display_time);
+ case "warning":
+ return notificationStore.frontendWarning(text, "Warning", display_time);
+ case "info":
+ default:
+ return notificationStore.frontendInfo(text, "Info", display_time);
+ }
}
globalThis.toast = toast;
// OLD: hideToast function removed - now using new notification system
function scrollChanged(isAtBottom) {
- // Reflect scroll state into preferences store; UI is bound via x-model
- preferencesStore.autoScroll = isAtBottom;
+ if (globalThis.Alpine && autoScrollSwitch) {
+ const inputAS = Alpine.$data(autoScrollSwitch);
+ if (inputAS) {
+ inputAS.autoScroll = isAtBottom;
+ }
+ }
+ // autoScrollSwitch.checked = isAtBottom
}
function updateAfterScroll() {
@@ -597,15 +1082,16 @@ function updateAfterScroll() {
// const tolerancePx = toleranceEm * parseFloat(getComputedStyle(document.documentElement).fontSize); // Convert em to pixels
const tolerancePx = 10;
const chatHistory = document.getElementById("chat-history");
- if (!chatHistory) return;
-
const isAtBottom =
chatHistory.scrollHeight - chatHistory.scrollTop <=
chatHistory.clientHeight + tolerancePx;
scrollChanged(isAtBottom);
}
-globalThis.updateAfterScroll = updateAfterScroll;
+
+chatHistory.addEventListener("scroll", updateAfterScroll);
+
+chatInput.addEventListener("input", adjustTextareaHeight);
// setInterval(poll, 250);
@@ -615,6 +1101,15 @@ async function startPolling() {
const shortIntervalPeriod = 100;
let shortIntervalCount = 0;
+ // Call poll immediately to load chats on page load
+ try {
+ // Wait a bit for Alpine to be fully ready
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ await poll();
+ } catch (error) {
+ console.error("Error in initial poll:", error);
+ }
+
async function _doPoll() {
let nextInterval = longInterval;
@@ -631,41 +1126,165 @@ async function startPolling() {
setTimeout(_doPoll.bind(this), nextInterval);
}
- _doPoll();
+ // Start the polling loop after the initial poll
+ setTimeout(_doPoll, longInterval);
}
-// All initializations and event listeners are now consolidated here
+document.addEventListener("DOMContentLoaded", startPolling);
+
+// Setup event handlers once the DOM is fully loaded
document.addEventListener("DOMContentLoaded", function () {
- // Assign DOM elements to variables now that the DOM is ready
- leftPanel = document.getElementById("left-panel");
- rightPanel = document.getElementById("right-panel");
- container = document.querySelector(".container");
- chatInput = document.getElementById("chat-input");
- chatHistory = document.getElementById("chat-history");
- sendButton = document.getElementById("send-button");
- inputSection = document.getElementById("input-section");
- statusSection = document.getElementById("status-section");
- progressBar = document.getElementById("progress-bar");
- autoScrollSwitch = document.getElementById("auto-scroll-switch");
- timeDate = document.getElementById("time-date-container");
-
- // Sidebar and input event listeners are now handled by their respective stores
-
- if (chatHistory) {
- chatHistory.addEventListener("scroll", updateAfterScroll);
- }
-
- // Start polling for updates
- startPolling();
+ setupSidebarToggle();
+ setupTabs();
+ initializeActiveTab();
});
+// Setup tabs functionality
+function setupTabs() {
+ const chatsTab = document.getElementById("chats-tab");
+ const tasksTab = document.getElementById("tasks-tab");
+
+ if (chatsTab && tasksTab) {
+ chatsTab.addEventListener("click", function () {
+ activateTab("chats");
+ });
+
+ tasksTab.addEventListener("click", function () {
+ activateTab("tasks");
+ });
+ } else {
+ console.error("Tab elements not found");
+ setTimeout(setupTabs, 100); // Retry setup
+ }
+}
+
+function activateTab(tabName) {
+ const chatsTab = document.getElementById("chats-tab");
+ const tasksTab = document.getElementById("tasks-tab");
+ const chatsSection = document.getElementById("chats-section");
+ const tasksSection = document.getElementById("tasks-section");
+
+ // Get current context to preserve before switching
+ const currentContext = context;
+
+ // Store the current selection for the active tab before switching
+ const previousTab = localStorage.getItem("activeTab");
+ if (previousTab === "chats") {
+ localStorage.setItem("lastSelectedChat", currentContext);
+ } else if (previousTab === "tasks") {
+ localStorage.setItem("lastSelectedTask", currentContext);
+ }
+
+ // Reset all tabs and sections
+ chatsTab.classList.remove("active");
+ tasksTab.classList.remove("active");
+ chatsSection.style.display = "none";
+ tasksSection.style.display = "none";
+
+ // Remember the last active tab in localStorage
+ localStorage.setItem("activeTab", tabName);
+
+ // Activate selected tab and section
+ if (tabName === "chats") {
+ chatsTab.classList.add("active");
+ chatsSection.style.display = "";
+
+ // Get the available contexts from Alpine.js data
+ const chatsAD = globalThis.Alpine ? Alpine.$data(chatsSection) : null;
+ const availableContexts = chatsAD?.contexts || [];
+
+ // Restore previous chat selection
+ const lastSelectedChat = localStorage.getItem("lastSelectedChat");
+
+ // Only switch if:
+ // 1. lastSelectedChat exists AND
+ // 2. It's different from current context AND
+ // 3. The context actually exists in our contexts list OR there are no contexts yet
+ if (
+ lastSelectedChat &&
+ lastSelectedChat !== currentContext &&
+ (availableContexts.some((ctx) => ctx.id === lastSelectedChat) ||
+ availableContexts.length === 0)
+ ) {
+ setContext(lastSelectedChat);
+ }
+ } else if (tabName === "tasks") {
+ tasksTab.classList.add("active");
+ tasksSection.style.display = "flex";
+ tasksSection.style.flexDirection = "column";
+
+ // Get the available tasks from Alpine.js data
+ const tasksAD = globalThis.Alpine ? Alpine.$data(tasksSection) : null;
+ const availableTasks = tasksAD?.tasks || [];
+
+ // Restore previous task selection
+ const lastSelectedTask = localStorage.getItem("lastSelectedTask");
+
+ // Only switch if:
+ // 1. lastSelectedTask exists AND
+ // 2. It's different from current context AND
+ // 3. The task actually exists in our tasks list
+ if (
+ lastSelectedTask &&
+ lastSelectedTask !== currentContext &&
+ availableTasks.some((task) => task.id === lastSelectedTask)
+ ) {
+ setContext(lastSelectedTask);
+ }
+ }
+
+ // Request a poll update
+ poll();
+}
+
+// Add function to initialize active tab and selections from localStorage
+function initializeActiveTab() {
+ // Initialize selection storage if not present
+ if (!localStorage.getItem("lastSelectedChat")) {
+ localStorage.setItem("lastSelectedChat", "");
+ }
+ if (!localStorage.getItem("lastSelectedTask")) {
+ localStorage.setItem("lastSelectedTask", "");
+ }
+
+ const activeTab = localStorage.getItem("activeTab") || "chats";
+
+ // Only activate tab if we have a context - otherwise show welcome screen
+ if (context) {
+ activateTab(activeTab);
+ } else {
+ // Just set the active tab UI without auto-selecting contexts
+ const chatsTab = document.getElementById("chats-tab");
+ const tasksTab = document.getElementById("tasks-tab");
+ const chatsSection = document.getElementById("chats-section");
+ const tasksSection = document.getElementById("tasks-section");
+
+ if (activeTab === "chats") {
+ if (chatsTab) chatsTab.classList.add("active");
+ if (tasksTab) tasksTab.classList.remove("active");
+ if (chatsSection) chatsSection.style.display = "flex";
+ if (tasksSection) tasksSection.style.display = "none";
+ } else {
+ if (tasksTab) tasksTab.classList.add("active");
+ if (chatsTab) chatsTab.classList.remove("active");
+ if (tasksSection) tasksSection.style.display = "flex";
+ if (chatsSection) chatsSection.style.display = "none";
+ }
+ }
+
+ // Alpine store will handle the initial state automatically
+}
+
/*
* A0 Chat UI
*
- * Unified sidebar layout:
- * - Both Chats and Tasks lists are always visible in a vertical layout
+ * Tasks tab functionality:
+ * - Tasks are displayed in the Tasks tab with the same mechanics as chats
* - Both lists are sorted by creation time (newest first)
+ * - Selection state is preserved across tab switches
+ * - The active tab is remembered across sessions
* - Tasks use the same context system as chats for communication with the backend
+ * - Future support for renaming and deletion will be implemented later
*/
// Open the scheduler detail view for a specific task
@@ -697,7 +1316,7 @@ function openTaskDetail(taskId) {
setTimeout(() => {
// Get the scheduler component
const schedulerComponent = document.querySelector(
- '[x-data="schedulerSettings"]'
+ '[x-data="schedulerSettings"]',
);
if (!schedulerComponent) {
console.error("Scheduler component not found");
@@ -725,3 +1344,4 @@ function openTaskDetail(taskId) {
// Make the function available globally
globalThis.openTaskDetail = openTaskDetail;
+globalThis.deselectChat = deselectChat;