Agent Zero AI framework
refactor: file-browser component
Alessandroe7684b007cdb
diff --git a/webui/components/chat/input/bottom-actions.html b/webui/components/chat/input/bottom-actions.htmlindex 6ba32533c..8c2d5260b 100644--- a/webui/components/chat/input/bottom-actions.html+++ b/webui/components/chat/input/bottom-actions.html@@ -2,6 +2,9 @@<head><script type="module">import { store } from "/components/chat/input/input-store.js";+ import { store as historyStore } from "/components/modals/history-store.js";+ import { store as contextStore } from "/components/modals/context-store.js";+ import { store as fileBrowserStore } from "/components/modals/file-browser-store.js";</script></head><body>@@ -29,7 +32,7 @@<p>Import knowledge</p></button>- <button class="text-button" id="work_dir_browser" @click="fileBrowserModalProxy.openModal()">+ <button class="text-button" id="work_dir_browser" @click="$store.fileBrowser.open()"><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>diff --git a/webui/components/modals/file-browser-store.js b/webui/components/modals/file-browser-store.jsnew file mode 100644index 000000000..301082d22--- /dev/null+++ b/webui/components/modals/file-browser-store.js@@ -0,0 +1,244 @@+import { createStore } from "/js/AlpineStore.js";+import { fetchApi } from "/js/api.js";++// Model migrated from legacy file_browser.js (lift-and-shift)+const model = {+ // Reactive state+ isLoading: false,+ browser: {+ title: "File Browser",+ currentPath: "",+ entries: [],+ parentPath: "",+ sortBy: "name",+ sortDirection: "asc",+ },+ history: [], // navigation stack+ initialPath: "", // Store path for open() call+ closePromise: null,+ error: null,++ // --- Lifecycle -----------------------------------------------------------+ init() {+ // Nothing special to do here; all methods available immediately+ },++ // --- Public API (called from button/link) --------------------------------+ async open() {+ if (this.isLoading) return; // Prevent double-open++ this.isLoading = true;+ this.error = null;+ this.history = [];++ try {+ // Open modal FIRST (immediate UI feedback)+ this.closePromise = window.openModal('modals/file-browser.html');++ // Setup cleanup on modal close+ if (this.closePromise && typeof this.closePromise.then === 'function') {+ this.closePromise.then(() => {+ this.destroy();+ });+ }++ // Use stored initial path or default+ const path = this.initialPath || this.browser.currentPath || "$WORK_DIR";+ this.browser.currentPath = path;++ // Fetch files+ await this.fetchFiles(this.browser.currentPath);++ } catch (error) {+ console.error("File browser error:", error);+ this.error = error?.message || "Failed to load files";+ this.isLoading = false;+ }+ },++ handleClose() {+ // Close the modal manually+ window.closeModal();+ },++ destroy() {+ // Reset state when modal closes+ this.isLoading = false;+ this.history = [];+ this.initialPath = "";+ this.browser.entries = [];+ },++ // --- Helpers -------------------------------------------------------------+ isArchive(filename) {+ const archiveExts = ["zip", "tar", "gz", "rar", "7z"];+ const ext = filename.split(".").pop().toLowerCase();+ return archiveExts.includes(ext);+ },++ formatFileSize(size) {+ if (size === 0) return "0 Bytes";+ const k = 1024;+ const sizes = ["Bytes", "KB", "MB", "GB", "TB"];+ const i = Math.floor(Math.log(size) / Math.log(k));+ return parseFloat((size / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];+ },++ formatDate(dateString) {+ const options = {+ year: "numeric",+ month: "short",+ day: "numeric",+ hour: "2-digit",+ minute: "2-digit",+ };+ return new Date(dateString).toLocaleDateString(undefined, options);+ },++ // --- Sorting -------------------------------------------------------------+ toggleSort(column) {+ if (this.browser.sortBy === column) {+ this.browser.sortDirection =+ this.browser.sortDirection === "asc" ? "desc" : "asc";+ } else {+ this.browser.sortBy = column;+ this.browser.sortDirection = "asc";+ }+ },++ sortFiles(entries) {+ return [...entries].sort((a, b) => {+ // Folders first+ if (a.is_dir !== b.is_dir) return a.is_dir ? -1 : 1;+ const dir = this.browser.sortDirection === "asc" ? 1 : -1;+ switch (this.browser.sortBy) {+ case "name":+ return dir * a.name.localeCompare(b.name);+ case "size":+ return dir * (a.size - b.size);+ case "date":+ return dir * (new Date(a.modified) - new Date(b.modified));+ default:+ return 0;+ }+ });+ },++ // --- Navigation ----------------------------------------------------------+ async fetchFiles(path = "") {+ this.isLoading = true;+ try {+ const response = await fetchApi(`/get_work_dir_files?path=${encodeURIComponent(path)}`);+ if (response.ok) {+ const data = await response.json();+ this.browser.entries = data.data.entries;+ this.browser.currentPath = data.data.current_path;+ this.browser.parentPath = data.data.parent_path;+ } else {+ console.error("Error fetching files:", await response.text());+ this.browser.entries = [];+ }+ } catch (e) {+ window.toastFrontendError("Error fetching files: " + e.message, "File Browser Error");+ this.browser.entries = [];+ } finally {+ this.isLoading = false;+ }+ },++ async navigateToFolder(path) {+ if (this.browser.currentPath !== path) this.history.push(this.browser.currentPath);+ await this.fetchFiles(path);+ },++ async navigateUp() {+ if (this.browser.parentPath) {+ this.history.push(this.browser.currentPath);+ await this.fetchFiles(this.browser.parentPath);+ }+ },++ // --- File actions --------------------------------------------------------+ async deleteFile(file) {+ if (!confirm(`Are you sure you want to delete ${file.name}?`)) return;+ try {+ const resp = await fetchApi("/delete_work_dir_file", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ path: file.path, currentPath: this.browser.currentPath }),+ });+ if (resp.ok) {+ this.browser.entries = this.browser.entries.filter((e) => e.path !== file.path);+ alert("File deleted successfully.");+ } else {+ alert(`Error deleting file: ${await resp.text()}`);+ }+ } catch (e) {+ window.toastFrontendError("Error deleting file: " + e.message, "File Delete Error");+ }+ },++ async handleFileUpload(event) {+ try {+ const files = event.target.files;+ if (!files.length) return;+ const formData = new FormData();+ formData.append("path", this.browser.currentPath);+ for (let f of files) {+ const ext = f.name.split(".").pop().toLowerCase();+ if (!["zip", "tar", "gz", "rar", "7z"].includes(ext) && f.size > 100 * 1024 * 1024) {+ alert(`File ${f.name} exceeds 100MB limit.`);+ continue;+ }+ formData.append("files[]", f);+ }+ const resp = await fetchApi("/upload_work_dir_files", { method: "POST", body: formData });+ if (resp.ok) {+ const data = await resp.json();+ this.browser.entries = data.data.entries;+ this.browser.currentPath = data.data.current_path;+ this.browser.parentPath = data.data.parent_path;+ if (data.failed && data.failed.length) {+ const msg = data.failed.map((f) => `${f.name}: ${f.error}`).join("\n");+ alert(`Some files failed to upload:\n${msg}`);+ }+ } else {+ alert(await resp.text());+ }+ } catch (e) {+ window.toastFrontendError("Error uploading files: " + e.message, "File Upload Error");+ } finally {+ event.target.value = ""; // reset input so same file can be reselected+ }+ },++ downloadFile(file) {+ const link = document.createElement("a");+ link.href = `/download_work_dir_file?path=${encodeURIComponent(file.path)}`;+ link.download = file.name;+ document.body.appendChild(link);+ link.click();+ document.body.removeChild(link);+ },+};++export const store = createStore("fileBrowser", model);++window.openFileLink = async function (path) {+ try {+ const resp = await window.sendJsonData("/file_info", { path });+ if (!resp.exists) {+ window.toastFrontendError("File does not exist.", "File Error");+ return;+ }+ if (resp.is_dir) {+ // Set initial path and open via store+ store.initialPath = resp.abs_path;+ await store.open();+ } else {+ store.downloadFile({ path: resp.abs_path, name: resp.file_name });+ }+ } catch (e) {+ window.toastFrontendError("Error opening file: " + e.message, "File Open Error");+ }+};diff --git a/webui/components/modals/file-browser.html b/webui/components/modals/file-browser.htmlnew file mode 100644index 000000000..531031531--- /dev/null+++ b/webui/components/modals/file-browser.html@@ -0,0 +1,347 @@+<html>+<head>+ <title>File Browser</title>+ <script type="module">+ import { store } from "/components/modals/file-browser-store.js";+ </script>+</head>+<body>+ <div x-data>+ <template x-if="$store.fileBrowser">+ <div class="file-browser-root">++ <!-- Loading State -->+ <div x-show="$store.fileBrowser.isLoading" class="loading-state">+ <div class="loading-spinner"></div>+ <p>Loading files...</p>+ </div>++ <!-- File Browser Content -->+ <div x-show="!$store.fileBrowser.isLoading" class="file-browser-content">+ <!-- Path navigator -->+ <div class="path-navigator">+ <button class="text-button back-button" @click="$store.fileBrowser.navigateUp()" aria-label="Navigate Up">+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10.5 15">+ <path d="m.75,5.25L5.25.75m0,0l4.5,4.5M5.25.75v13.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" />+ </svg>+ Up+ </button>+ <div id="current-path"><span id="path-text" x-text="$store.fileBrowser.browser.currentPath"></span></div>+ </div>++ <!-- Files list -->+ <div class="files-list">+ <div class="file-header">+ <div class="file-cell" @click="$store.fileBrowser.toggleSort('name')">Name <span x-show="$store.fileBrowser.browser.sortBy === 'name'" x-text="$store.fileBrowser.browser.sortDirection === 'asc' ? '↑' : '↓'"></span></div>+ <div class="file-cell-size" @click="$store.fileBrowser.toggleSort('size')">Size <span x-show="$store.fileBrowser.browser.sortBy === 'size'" x-text="$store.fileBrowser.browser.sortDirection === 'asc' ? '↑' : '↓'"></span></div>+ <div class="file-cell-date" @click="$store.fileBrowser.toggleSort('date')">Modified <span x-show="$store.fileBrowser.browser.sortBy === 'date'" x-text="$store.fileBrowser.browser.sortDirection === 'asc' ? '↑' : '↓'"></span></div>+ </div>++ <!-- File list entries -->+ <template x-if="$store.fileBrowser.browser.entries.length">+ <template x-for="file in $store.fileBrowser.sortFiles($store.fileBrowser.browser.entries)" :key="file.path">+ <div class="file-item" :data-is-dir="file.is_dir">+ <div class="file-name" @click="file.is_dir ? $store.fileBrowser.navigateToFolder(file.path) : $store.fileBrowser.downloadFile(file)">+ <img :src="'/public/' + (file.type === 'unknown' ? 'file' : ($store.fileBrowser.isArchive(file.name) ? 'archive' : file.type)) + '.svg'" class="file-icon" :alt="file.type" />+ <span x-text="file.name"></span>+ </div>+ <div class="file-size" x-text="$store.fileBrowser.formatFileSize(file.size)"></div>+ <div class="file-date" x-text="$store.fileBrowser.formatDate(file.modified)"></div>+ <div class="file-actions">+ <button class="action-button download-button" @click.stop="$store.fileBrowser.downloadFile(file)">+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.5 19.5"><path d="m.75,14.25v2.25c0,1.24,1.01,2.25,2.25,2.25h13.5c1.24,0,2.25-1.01,2.25-2.25v-2.25m-4.5-4.5l-4.5,4.5m0,0l-4.5-4.5m4.5,4.5V.75" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"/></svg>+ </button>+ <button class="delete-button" @click.stop="$store.fileBrowser.deleteFile(file)">+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15.03 22.53" fill="currentColor"><path d="m14.55,7.82H4.68L14.09,3.19c.83-.41,1.17-1.42.77-2.25-.41-.83-1.42-1.17-2.25-.77l-3.16,1.55-.15-.31c-.22-.44-.59-.76-1.05-.92-.46-.16-.96-.13-1.39.09l-2.08,1.02c-.9.44-1.28,1.54-.83,2.44l.15.31-3.16,1.55c-.83.41-1.17,1.42-.77,2.25.29.59.89.94,1.51.94.25,0,.5-.06.74-.17l.38-.19s.09.03.14.03h11.14v11.43c0,.76-.62,1.38-1.38,1.38h-.46v-11.28c0-.26-.21-.47-.47-.47s-.47.21-.47.47v11.28h-2.39v-11.28c0-.26-.21-.47-.47-.47s-.47.21-.47.47v11.28h-2.39v-11.28c0-.26-.21-.47-.47-.47s-.47.21-.47.47v11.28h-.46c-.76,0-1.38-.62-1.38-1.38v-9.9c0-.26-.21-.47-.47-.47s-.47.21-.47.47v9.9c0,1.28,1.04,2.32,2.32,2.32h8.55c1.28,0,2.32-1.04,2.32-2.32v-11.91c0-.26-.21-.47-.47-.47Z" stroke-width="0"/></svg>+ </button>+ </div>+ </div>+ </template>+ </template>++ <!-- Empty state -->+ <template x-if="!$store.fileBrowser.browser.entries.length">+ <div class="no-files">No files found</div>+ </template>+ </div>+ </div>+ </div>++ </div>+ </template>++ <!-- Modal Footer (outside template x-if so it exists immediately) -->+ <template x-if="$store.fileBrowser">+ <div class="modal-footer" data-modal-footer>+ <label class="btn btn-upload">+ <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"/></svg>+ Upload Files+ <input type="file" multiple accept="*" @change="$store.fileBrowser.handleFileUpload" style="display:none;" />+ </label>+ <button class="btn btn-cancel" @click="$store.fileBrowser.handleClose()">Close Browser</button>+ </div>+ </template>+ </div>++ <style>+ /* File Browser Root */+ .file-browser-root {+ display: flex;+ flex-direction: column;+ width: 100%;+ height: 100%;+ min-height: 400px;+ }++ /* Loading State */+ .loading-state {+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ padding: var(--spacing-lg);+ min-height: 200px;+ }++ .loading-spinner {+ width: 40px;+ height: 40px;+ border: 3px solid var(--color-border);+ border-top: 3px solid var(--color-primary);+ border-radius: 50%;+ animation: spin 1s linear infinite;+ margin-bottom: var(--spacing-md);+ }++ @keyframes spin {+ 0% { transform: rotate(0deg); }+ 100% { transform: rotate(360deg); }+ }++ .loading-state p {+ color: var(--color-text-secondary);+ margin: 0;+ }++ /* File Browser Content */+ .file-browser-content {+ display: flex;+ flex-direction: column;+ padding: var(--spacing-sm) var(--spacing-sm);+ }++ /* File Browser Styles */+ .files-list,+ .file-header,+ .file-item {+ width: 100%;+ border-radius: 4px;+ overflow: hidden;+ }++ /* Header Styles */+ .file-header {+ display: grid;+ grid-template-columns: 2fr 0.6fr 1fr 80px;+ background: var(--secondary-bg);+ padding: 8px 0;+ font-weight: bold;+ border-bottom: 1px solid var(--border-color);+ color: var(--color-primary);+ }+ .file-cell,+ .file-cell-size,+ .file-cell-date {+ color: var(--color-primary);+ padding: 4px;+ cursor: pointer;+ }++ /* File Item Styles */+ .file-item {+ display: grid;+ grid-template-columns: 2fr 0.6fr 1fr 80px;+ align-items: center;+ padding: 8px 0;+ font-size: 0.875rem;+ border-top: 1px solid var(--color-border);+ transition: background-color 0.2s;+ white-space: nowrap;+ overflow: hidden;+ color: var(--color-text);+ }+ .file-item:hover {+ background-color: var(--color-secondary);+ }++ /* File Icon and Name */+ .file-icon {+ width: 1.8rem;+ height: 1.8rem;+ margin: 0 1rem 0 0.7rem;+ vertical-align: middle;+ font-size: var(--font-size-sm);+ }+ .file-name {+ display: flex;+ align-items: center;+ font-weight: 500;+ margin-right: var(--spacing-sm);+ overflow: hidden;+ }+ .file-name > span {+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ }+ .file-size,+ .file-date {+ color: var(--text-secondary);+ }+ /* No Files Message */+ .no-files {+ padding: 32px;+ text-align: center;+ color: var(--text-secondary);+ }+ /* Light Mode Adjustments */+ .light-mode .file-item:hover {+ background-color: var(--color-secondary-light);+ }++ /* Path Navigator Styles */+ .path-navigator {+ display: flex;+ align-items: center;+ gap: 24px;+ background-color: var(--color-message-bg);+ padding: 0.5rem var(--spacing-sm);+ margin: 0 0 var(--spacing-sm) 0;+ border: 1px solid var(--color-border);+ border-radius: 8px;+ }+ .nav-button {+ padding: 4px 12px;+ border: 1px solid var(--color-border);+ border-radius: 4px;+ background: var(--color-background);+ color: var(--color-text);+ cursor: pointer;+ transition: background-color 0.2s;+ }+ .nav-button:hover {+ background: var(--hover-bg);+ }+ .nav-button.back-button {+ background-color: var(--color-secondary);+ color: var(--color-text);+ }+ .nav-button.back-button:hover {+ background-color: var(--color-secondary-dark);+ }+ #current-path {+ opacity: 0.9;+ }+ #path-text {+ font-family: 'Roboto Mono', monospace;+ -webkit-font-optical-sizing: auto;+ font-optical-sizing: auto;+ opacity: 0.9;+ }++ /* Folder Specific Styles */+ .file-item[data-is-dir="true"] {+ cursor: pointer;+ }+ .file-item[data-is-dir="true"]:hover {+ background-color: var(--color-secondary);+ }++ /* Upload Button Styles */+ .btn-upload {+ display: inline-flex;+ align-items: center;+ padding: 8px 16px;+ background: #4248f1;+ gap: 0.5rem;+ color: white;+ border-radius: 4px;+ cursor: pointer;+ transition: background-color 0.3s ease-in-out;+ }+ .btn-upload > svg {+ width: 20px;+ }+ .btn-upload:hover {+ background-color: #353bc5;+ }+ .btn-upload:active {+ background-color: #2b309c;+ }+ /* Delete Button Styles */+ .delete-button {+ background: none;+ border: none;+ color: var(--color-primary);+ cursor: pointer;+ width: 32px;+ padding: 4px 8px;+ border-radius: 4px;+ transition: opacity 0.2s, background-color 0.2s;+ }+ .delete-button:hover {+ color: #ff7878;+ }+ .delete-button:active {+ opacity: 0.6;+ }++ /* File Actions */+ .file-actions {+ display: flex;+ gap: var(--spacing-xs);+ }+ .action-button {+ background: none;+ border: none;+ cursor: pointer;+ width: 32px;+ padding: 6px 8px;+ border-radius: 4px;+ transition: background-color 0.2s;+ }+ .download-button {+ color: var(--color-primary);+ }+ .download-button:hover {+ background-color: var(--color-border);+ }+ .light-mode .download-button:hover {+ background-color: #c6d4de;+ }+ /* Responsive Design */+ @media (max-width: 768px) {+ .file-header,+ .file-item {+ grid-template-columns: 1fr 0.5fr 80px;+ }+ .file-cell-date,+ .file-date {+ display: none;+ }+ }+ @media (max-width: 540px) {+ .file-header,+ .file-item {+ grid-template-columns: 1fr 80px;+ }+ .file-cell-size,+ .file-size,+ .file-cell-date,+ .file-date {+ display: none;+ }+ }+ </style>+</body>+</html>diff --git a/webui/css/file_browser.css b/webui/css/file_browser.cssdeleted file mode 100644index 4ed42877a..000000000--- a/webui/css/file_browser.css+++ /dev/null@@ -1,249 +0,0 @@-/* File Browser Styles */--.files-list,-.file-header,-.file-item {- width: 100%;- border-radius: 4px;- overflow: hidden;-}--/* Header Styles */-.file-header {- display: grid;- grid-template-columns: 2fr 0.6fr 1fr 80px;- background: var(--secondary-bg);- padding: 8px 0;- font-weight: bold;- border-bottom: 1px solid var(--border-color);- color: var(--color-primary);-}--.file-cell,-.file-cell-size,-.file-cell-date {- color: var(--color-primary);- padding: 4px;- cursor: pointer;-}--/* File Item Styles */-.file-item {- display: grid;- grid-template-columns: 2fr 0.6fr 1fr 80px;- align-items: center;- padding: 8px 0;- font-size: 0.875rem;- border-top: 1px solid var(--color-border);- transition: background-color 0.2s;- white-space: nowrap;- overflow: hidden;- color: var(--color-text);-}--.file-item:hover {- background-color: var(--color-secondary);-}--/* File Icon and Name */-.file-icon {- width: 1.8rem;- height: 1.8rem;- margin: 0 1rem 0 0.7rem;- vertical-align: middle;- font-size: var(--font-size-sm);-}--.file-name {- display: flex;- align-items: center;- font-weight: 500;- margin-right: var(--spacing-sm);- overflow: hidden;-}--.file-name > span {- white-space: nowrap;- overflow: hidden;- text-overflow: ellipsis;-}--.file-size,-.file-date {- color: var(--text-secondary);-}--/* No Files Message */-.no-files {- padding: 32px;- text-align: center;- color: var(--text-secondary);-}--/* Light Mode Adjustments */-.light-mode .file-item:hover {- background-color: var(--color-secondary-light);-}--/* Path Navigator Styles */-.path-navigator {- display: flex;- align-items: center;- gap: 24px;- background-color: var(--color-message-bg);- padding: 0.5rem var(--spacing-sm);- margin-bottom: 0.3rem;- border: 1px solid var(--color-border);- border-radius: 8px;-}--.nav-button {- padding: 4px 12px;- border: 1px solid var(--color-border);- border-radius: 4px;- background: var(--color-background);- color: var(--color-text);- cursor: pointer;- transition: background-color 0.2s;-}--.nav-button:hover {- background: var(--hover-bg);-}--.nav-button.back-button {- background-color: var(--color-secondary);- color: var(--color-text);-}--.nav-button.back-button:hover {- background-color: var(--color-secondary-dark);-}--#current-path {- opacity: 0.9;-}--#path-text {- font-family: 'Roboto Mono', monospace;- font-optical-sizing: auto;- -webkit-font-optical-sizing: auto;- opacity: 0.9;-}--/* Folder Specific Styles */-.file-item[data-is-dir="true"] {- cursor: pointer;-}--.file-item[data-is-dir="true"]:hover {- background-color: var(--color-secondary);-}--/* Upload Button Styles */-.upload-button,-.btn-upload {- display: inline-flex;- align-items: center;- padding: 8px 16px;- background-color: var(--color-primary);- color: white;- border-radius: 4px;- cursor: pointer;- transition: background-color 0.3s ease-in-out;-}--.btn-upload {- background: #4248f1;- gap: 0.5rem;- margin: 0 auto;-}--.btn-upload > svg {- width: 20px;-}--.upload-button:hover,-.btn-upload:hover {- background-color: #353bc5;-}--.upload-button:active,-.btn-upload:active {- background-color: #2b309c;-}--/* Delete Button Styles */-.delete-button {- background: none;- border: none;- color: var(--color-primary);- cursor: pointer;- width: 32px;- padding: 4px 8px;- border-radius: 4px;- transition: opacity 0.2s, background-color 0.2s;-}--.delete-button:hover {- color: #ff7878;-}--.delete-button:active {- opacity: 0.6;-}--/* File Actions */-.file-actions {- display: flex;- gap: var(--spacing-xs);-}--.action-button {- background: none;- border: none;- cursor: pointer;- width: 32px;- padding: 6px 8px;- border-radius: 4px;- transition: background-color 0.2s;-}--.download-button {- color: var(--color-primary);-}--.download-button:hover {- background-color: var(--color-border);-}--.light-mode .download-button:hover {- background-color: #c6d4de;-}--/* Responsive Design */-@media (max-width: 768px) {- .file-header,- .file-item {- grid-template-columns: 1fr 0.5fr 80px;- }-- .file-cell-date,- .file-date {- display: none;- }-}--@media (max-width: 540px) {- .file-header,- .file-item {- grid-template-columns: 1fr 80px;- }-- .file-cell-size,- .file-size,- .file-cell-date,- .file-date {- display: none;- }-}diff --git a/webui/css/modals2.css b/webui/css/modals2.cssindex 804df88ec..864c672db 100644--- a/webui/css/modals2.css+++ b/webui/css/modals2.css@@ -66,6 +66,24 @@ display: flex;padding: 0 1rem 1rem 1rem;}+/* Modal with footer support */+.modal-inner.modal-with-footer {+ display: flex;+ flex-direction: column;+}++.modal-inner.modal-with-footer .modal-scroll {+ flex: 1;+ min-height: 0;+ overflow-y: auto;+}++.modal-footer-slot {+ flex-shrink: 0;+ border-top: 1px solid var(--color-border);+ background: var(--color-background);+}+.modal-x {position: absolute;top: 1rem;diff --git a/webui/index.html b/webui/index.htmlindex 272ac1807..a76a637b4 100644--- a/webui/index.html+++ b/webui/index.html@@ -11,7 +11,6 @@<link rel="stylesheet" href="components/messages/action-buttons/simple-action-buttons.css"><link rel="stylesheet" href="css/toast.css"><link rel="stylesheet" href="css/settings.css">- <link rel="stylesheet" href="css/file_browser.css"><link rel="stylesheet" href="css/modals.css"><link rel="stylesheet" href="css/modals2.css"><link rel="stylesheet" href="css/speech.css">@@ -1185,150 +1184,6 @@</template></div>- <!-- work_dir Browser Modal -->-- <div id="fileBrowserModal" x-data="fileBrowserModalProxy">- <template x-teleport="body">- <div x-show="isOpen" class="modal-overlay" @click.self="handleClose()"- @keydown.escape.window="handleClose()" x-transition>- <div class="modal-container">- <div class="modal-header">- <h2 class="modal-title" x-text="browser.title"></h2>- <button class="modal-close" @click="handleClose()">×</button>- </div>- <div class="modal-content">- <div x-show="isLoading" class="loading-spinner">- Loading...- </div>- <div x-show="!isLoading">- <div class="path-navigator">- <!-- Up Button -->- <button class="text-button back-button" @click="navigateUp()" aria-label="Navigate Up">- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10.5 15">- <path d="m.75,5.25L5.25.75m0,0l4.5,4.5M5.25.75v13.5" fill="none"- stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"- stroke-width="1.5"></path>- </svg>- Up- </button>-- <div id="current-path">- <span id="path-text" x-text="browser.currentPath"></span>- </div>- </div>-- <div class="files-list">- <!-- Header -->- <div class="file-header">- <div class="file-cell" @click="toggleSort('name')">- Name- <span x-show="browser.sortBy === 'name'"- x-text="browser.sortDirection === 'asc' ? '↑' : '↓'">- </span>- </div>- <div class="file-cell-size" @click="toggleSort('size')">- Size- <span x-show="browser.sortBy === 'size'"- x-text="browser.sortDirection === 'asc' ? '↑' : '↓'">- </span>- </div>- <div class="file-cell-date" @click="toggleSort('date')">- Modified- <span x-show="browser.sortBy === 'date'"- x-text="browser.sortDirection === 'asc' ? '↑' : '↓'">- </span>- </div>- </div>-- <!-- File List -->- <template x-if="browser.entries.length">- <template x-for="file in sortFiles(browser.entries)" :key="file.path">- <div class="file-item" :data-is-dir="file.is_dir">- <div class="file-name"- @click="file.is_dir ? navigateToFolder(file.path) : downloadFile(file)">- <img :src="'/public/' + (file.type === 'unknown' ? 'file' : (isArchive(file.name) ? 'archive' : file.type)) + '.svg'"- class="file-icon" :alt="file.type">- <span x-text="file.name"></span>- </div>- <div class="file-size" x-text="formatFileSize(file.size)"></div>- <div class="file-date" x-text="formatDate(file.modified)"></div>-- <div class="file-actions">- <button class="action-button download-button"- @click.stop="downloadFile(file)">- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.5 19.5">- <path- d="m.75,14.25v2.25c0,1.24,1.01,2.25,2.25,2.25h13.5c1.24,0,2.25-1.01,2.25-2.25v-2.25m-4.5-4.5l-4.5,4.5m0,0l-4.5-4.5m4.5,4.5V.75"- fill="none" stroke="currentColor" stroke-linecap="round"- stroke-linejoin="round" stroke-width="1.5"></path>- </svg>- </button>- <button class="delete-button" @click.stop="deleteFile(file)">- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15.03 22.53"- fill="currentColor">- <path- d="m14.55,7.82H4.68L14.09,3.19c.83-.41,1.17-1.42.77-2.25-.41-.83-1.42-1.17-2.25-.77l-3.16,1.55-.15-.31c-.22-.44-.59-.76-1.05-.92-.46-.16-.96-.13-1.39.09l-2.08,1.02c-.9.44-1.28,1.54-.83,2.44l.15.31-3.16,1.55c-.83.41-1.17,1.42-.77,2.25.29.59.89.94,1.51.94.25,0,.5-.06.74-.17l.38-.19s.09.03.14.03h11.14v11.43c0,.76-.62,1.38-1.38,1.38h-.46v-11.28c0-.26-.21-.47-.47-.47s-.47.21-.47.47v11.28h-2.39v-11.28c0-.26-.21-.47-.47-.47s-.47.21-.47.47v11.28h-2.39v-11.28c0-.26-.21-.47-.47-.47s-.47.21-.47.47v11.28h-.46c-.76,0-1.38-.62-1.38-1.38v-9.9c0-.26-.21-.47-.47-.47s-.47.21-.47.47v9.9c0,1.28,1.04,2.32,2.32,2.32h8.55c1.28,0,2.32-1.04,2.32-2.32v-11.91c0-.26-.21-.47-.47-.47ZM5.19,2.46l2.08-1.02c.12-.06.25-.09.39-.09.09,0,.19.02.28.05.22.08.4.23.5.44l.15.31-.19.09-3.46,1.7-.15-.31c-.21-.43-.03-.96.4-1.17Zm-3.19,5.62c-.36.18-.8.03-.98-.33-.18-.36-.03-.8.33-.98l5.8-2.85,2.72-1.34,3.16-1.55c.1-.05.21-.07.32-.07.27,0,.53.15.66.41.09.17.1.37.04.56-.06.18-.19.33-.37.42L2,8.08Z"- stroke-width="0"></path>- </svg>- </button>- </div>- </div>- </template>- </template>-- <!-- Empty State -->- <template x-if="!browser.entries.length">- <div class="no-files">- No files found- </div>- </template>- </div>- </div>- </div>- <div class="modal-footer">- <div id="buttons-container">- <label class="btn btn-upload"><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>- Upload Files- <input type="file" multiple="" accept="all" @change="handleFileUpload"- style="display: none;">- </label>- <button class="btn btn-cancel" @click="handleClose()">Close Browser</button>- </div>- </div>- </div>- </div>- </template>- </div>-- <!-- generic modal -->-- <div id="genericModal" x-data="genericModalProxy">- <template x-teleport="body">- <div x-show="isOpen" class="modal-overlay" @click.self="handleClose()"- @keydown.escape.window="handleClose()" x-transition>- <div class="modal-container">- <div class="modal-header">- <h2 class="modal-title" x-text="title"></h2>- <button class="modal-close" @click="handleClose()">×</button>- </div>- <div class="modal-description" x-text="description"></div>- <div class="modal-content" id="viewer">- <div class="html-pre" x-html="html"></div>- </div>- <!-- <div class="modal-footer">- <div id="buttons-container">- <button class="btn btn-cancel" @click="handleClose()">Close</button>- </div>- </div> -->- </div>- </template>- </div>-<!-- Full Screen Input Modal --><x-component path="modals/full-screen-input.html"></x-component>diff --git a/webui/js/file_browser.js b/webui/js/file_browser.jsdeleted file mode 100644index 350feeefd..000000000--- a/webui/js/file_browser.js+++ /dev/null@@ -1,268 +0,0 @@-const fileBrowserModalProxy = {- isOpen: false,- isLoading: false,-- browser: {- title: "File Browser",- currentPath: "",- entries: [],- parentPath: "",- sortBy: "name",- sortDirection: "asc",- },-- // Initialize navigation history- history: [],-- async openModal(path) {- const modalEl = document.getElementById("fileBrowserModal");- const modalAD = Alpine.$data(modalEl);-- modalAD.isOpen = true;- modalAD.isLoading = true;- modalAD.history = []; // reset history when opening modal-- // Initialize currentPath to root if it's empty- if (path) modalAD.browser.currentPath = path;- else if (!modalAD.browser.currentPath)- modalAD.browser.currentPath = "$WORK_DIR";-- await modalAD.fetchFiles(modalAD.browser.currentPath);- },-- isArchive(filename) {- const archiveExts = ["zip", "tar", "gz", "rar", "7z"];- const ext = filename.split(".").pop().toLowerCase();- return archiveExts.includes(ext);- },-- async fetchFiles(path = "") {- this.isLoading = true;- try {- const response = await fetchApi(- `/get_work_dir_files?path=${encodeURIComponent(path)}`- );-- if (response.ok) {- const data = await response.json();- this.browser.entries = data.data.entries;- this.browser.currentPath = data.data.current_path;- this.browser.parentPath = data.data.parent_path;- } else {- console.error("Error fetching files:", await response.text());- this.browser.entries = [];- }- } catch (error) {- window.toastFrontendError("Error fetching files: " + error.message, "File Browser Error");- this.browser.entries = [];- } finally {- this.isLoading = false;- }- },-- async navigateToFolder(path) {- // Push current path to history before navigating- if (this.browser.currentPath !== path) {- this.history.push(this.browser.currentPath);- }- await this.fetchFiles(path);- },-- async navigateUp() {- if (this.browser.parentPath !== "") {- // Push current path to history before navigating up- this.history.push(this.browser.currentPath);- await this.fetchFiles(this.browser.parentPath);- }- },-- sortFiles(entries) {- return [...entries].sort((a, b) => {- // Folders always come first- if (a.is_dir !== b.is_dir) {- return a.is_dir ? -1 : 1;- }-- const direction = this.browser.sortDirection === "asc" ? 1 : -1;- switch (this.browser.sortBy) {- case "name":- return direction * a.name.localeCompare(b.name);- case "size":- return direction * (a.size - b.size);- case "date":- return direction * (new Date(a.modified) - new Date(b.modified));- default:- return 0;- }- });- },-- toggleSort(column) {- if (this.browser.sortBy === column) {- this.browser.sortDirection =- this.browser.sortDirection === "asc" ? "desc" : "asc";- } else {- this.browser.sortBy = column;- this.browser.sortDirection = "asc";- }- },-- async deleteFile(file) {- if (!confirm(`Are you sure you want to delete ${file.name}?`)) {- return;- }-- try {- const response = await fetchApi("/delete_work_dir_file", {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- path: file.path,- currentPath: this.browser.currentPath,- }),- });-- if (response.ok) {- const data = await response.json();- this.browser.entries = this.browser.entries.filter(- (entry) => entry.path !== file.path- );- alert("File deleted successfully.");- } else {- alert(`Error deleting file: ${await response.text()}`);- }- } catch (error) {- window.toastFrontendError("Error deleting file: " + error.message, "File Delete Error");- alert("Error deleting file");- }- },-- async handleFileUpload(event) {- try {- const files = event.target.files;- if (!files.length) return;-- const formData = new FormData();- formData.append("path", this.browser.currentPath);-- for (let i = 0; i < files.length; i++) {- const ext = files[i].name.split(".").pop().toLowerCase();- if (!["zip", "tar", "gz", "rar", "7z"].includes(ext)) {- if (files[i].size > 100 * 1024 * 1024) {- // 100MB- alert(- `File ${files[i].name} exceeds the maximum allowed size of 100MB.`- );- continue;- }- }- formData.append("files[]", files[i]);- }-- // Proceed with upload after validation- const response = await fetchApi("/upload_work_dir_files", {- method: "POST",- body: formData,- });-- if (response.ok) {- const data = await response.json();- // Update the file list with new data- this.browser.entries = data.data.entries.map((entry) => ({- ...entry,- uploadStatus: data.failed.includes(entry.name) ? "failed" : "success",- }));- this.browser.currentPath = data.data.current_path;- this.browser.parentPath = data.data.parent_path;-- // Show success message- if (data.failed && data.failed.length > 0) {- const failedFiles = data.failed- .map((file) => `${file.name}: ${file.error}`)- .join("\n");- alert(`Some files failed to upload:\n${failedFiles}`);- }- } else {- alert(data.message);- }- } catch (error) {- window.toastFrontendError("Error uploading files: " + error.message, "File Upload Error");- alert("Error uploading files");- }- },-- downloadFile(file) {- const link = document.createElement("a");- link.href = `/download_work_dir_file?path=${encodeURIComponent(file.path)}`;- link.download = file.name;- document.body.appendChild(link);- link.click();- document.body.removeChild(link);- },-- // Helper Functions- formatFileSize(size) {- if (size === 0) return "0 Bytes";- const k = 1024;- const sizes = ["Bytes", "KB", "MB", "GB", "TB"];- const i = Math.floor(Math.log(size) / Math.log(k));- return parseFloat((size / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];- },-- formatDate(dateString) {- const options = {- year: "numeric",- month: "short",- day: "numeric",- hour: "2-digit",- minute: "2-digit",- };- return new Date(dateString).toLocaleDateString(undefined, options);- },-- handleClose() {- this.isOpen = false;- },-};--// Wait for Alpine to be ready-document.addEventListener("alpine:init", () => {- Alpine.data("fileBrowserModalProxy", () => ({- init() {- Object.assign(this, fileBrowserModalProxy);- // Ensure immediate file fetch when modal opens- this.$watch("isOpen", async (value) => {- if (value) {- await this.fetchFiles(this.browser.currentPath);- }- });- },- }));-});--// Keep the global assignment for backward compatibility-window.fileBrowserModalProxy = fileBrowserModalProxy;--openFileLink = async function (path) {- try {- const resp = await window.sendJsonData("/file_info", { path });- if (!resp.exists) {- window.toastFrontendError("File does not exist.", "File Error");- return;- }-- if (resp.is_dir) {- fileBrowserModalProxy.openModal(resp.abs_path);- } else {- fileBrowserModalProxy.downloadFile({- path: resp.abs_path,- name: resp.file_name,- });- }- } catch (e) {- window.toastFrontendError("Error opening file: " + e.message, "File Open Error");- }-};-window.openFileLink = openFileLink;diff --git a/webui/js/modals.js b/webui/js/modals.jsindex 6c1372882..9688ff5c8 100644--- a/webui/js/modals.js+++ b/webui/js/modals.js@@ -74,6 +74,7 @@ function createModalElement(name) {<div class="modal-scroll"><div class="modal-bd"></div></div>+ <div class="modal-footer-slot" style="display: none;"></div></div>`;@@ -96,6 +97,8 @@ function createModalElement(name) {title: newModal.querySelector(".modal-title"),body: newModal.querySelector(".modal-bd"),close: close_button,+ footerSlot: newModal.querySelector(".modal-footer-slot"),+ inner: newModal.querySelector(".modal-inner"),styles: [],scripts: [],};@@ -135,6 +138,18 @@ export function openModal(modalPath) {if (doc.body && doc.body.classList) {modal.body.classList.add(...doc.body.classList);}++ // Some modals have a footer. Check if it exists and move it to footer slot+ // Use requestAnimationFrame to let Alpine mount the component first+ requestAnimationFrame(() => {+ const componentFooter = modal.body.querySelector('[data-modal-footer]');+ if (componentFooter && modal.footerSlot) {+ // Move footer outside modal-scroll scrollable area+ modal.footerSlot.appendChild(componentFooter);+ modal.footerSlot.style.display = 'block';+ modal.inner.classList.add('modal-with-footer');+ }+ });}).catch((error) => {console.error("Error loading modal content:", error);