Page restyling

This commit is contained in:
Ettore Di Giacinto
2025-03-03 23:08:58 +01:00
parent 173eda4fb3
commit d714c4f80b
5 changed files with 1029 additions and 648 deletions

View File

@@ -61,6 +61,8 @@ func (a *Agent) knowledgeBaseLookup() {
} }
func (a *Agent) saveCurrentConversationInMemory() { func (a *Agent) saveCurrentConversationInMemory() {
if !a.options.enableLongTermMemory && !a.options.enableSummaryMemory { if !a.options.enableLongTermMemory && !a.options.enableSummaryMemory {
xlog.Debug("Long term memory is disabled", "agent", a.Character.Name) xlog.Debug("Long term memory is disabled", "agent", a.Character.Name)
return return

View File

@@ -5,79 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agent List</title> <title>Agent List</title>
{{template "views/partials/header"}} {{template "views/partials/header"}}
<style>
.button-container {
display: flex;
justify-content: flex-end;
margin-bottom: 8px;
}
.section-box {
background-color: rgba(30, 41, 59, 0.8);
border-radius: 8px;
padding: 20px;
margin-top: 20px;
}
.alert {
padding: 10px 15px;
border-radius: 4px;
margin: 10px 0;
display: none;
}
.alert-success {
background-color: rgba(16, 185, 129, 0.2);
border: 1px solid #10b981;
color: #10b981;
}
.alert-error {
background-color: rgba(239, 68, 68, 0.2);
border: 1px solid #ef4444;
color: #ef4444;
}
.toast {
position: fixed;
top: 20px;
right: 20px;
max-width: 350px;
padding: 15px;
border-radius: 5px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
z-index: 1000;
opacity: 0;
transition: opacity 0.3s ease;
}
.toast-success {
background-color: #10b981;
color: white;
}
.toast-error {
background-color: #ef4444;
color: white;
}
.toast-visible {
opacity: 1;
}
.action-btn {
background-color: #374151;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
.start-btn {
background-color: #10b981;
}
.start-btn:hover {
background-color: #059669;
}
.pause-btn {
background-color: #f59e0b;
}
.pause-btn:hover {
background-color: #d97706;
}
</style>
</head> </head>
<body class="bg-gray-900 p-4 text-white font-sans"> <body class="bg-gray-900 p-4 text-white font-sans">
{{template "views/partials/menu"}} {{template "views/partials/menu"}}
@@ -88,217 +15,172 @@
<div class="max-w-6xl mx-auto"> <div class="max-w-6xl mx-auto">
<header class="text-center mb-8"> <header class="text-center mb-8">
<h1 class="text-3xl md:text-5xl font-bold">Smart Agent List</h1> <h1 class="text-4xl md:text-6xl font-bold text-primary">Smart Agent List</h1>
</header> </header>
<div class="button-container"> <div class="button-container justify-center mb-6">
<a href="/create" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out"> <a href="/create" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out">
Add New Agent Add New Agent
</a> </a>
<button id="toggle-import" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out ml-4">
Import Agent
</button>
</div> </div>
<section class="flex flex-col"> <section id="import-section" class="hidden mb-8">
<div class="overflow-x-auto"> <div class="section-box">
<div class="py-2 align-middle inline-block min-w-full"> <h2 class="text-2xl font-bold mb-4">Import Agent</h2>
<div class="shadow overflow-hidden border-b border-gray-700 rounded-lg"> <!-- Response Messages Container -->
<table class="min-w-full divide-y divide-gray-700"> <div id="response-container">
<thead class="bg-gray-700"> <!-- Success Alert -->
<tr> <div id="success-alert" class="alert alert-success">
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider"> Agent imported successfully! The page will refresh in a moment.
Name </div>
</th> <!-- Error Alert -->
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider"> <div id="error-alert" class="alert alert-error">
Status <span id="error-message">Error importing agent.</span>
</th>
<th scope="col" class="px-6 py-3 text-center">
<span class="sr-only">Talk</span>
</th>
<th scope="col" class="px-6 py-3 text-center">
<span class="sr-only">Start</span>
</th>
<th scope="col" class="px-6 py-3 text-center">
<span class="sr-only">Stop</span>
</th>
<th scope="col" class="px-6 py-3 text-center">
<span class="sr-only">Settings</span>
</th>
</tr>
</thead>
<tbody class="bg-gray-800 divide-y divide-gray-700">
<!-- Dynamic agent rows go here -->
{{ $status := .Status }}
{{ range .Agents }}
<tr hx-ext="sse" data-agent-name="{{.}}">
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">
Online: {{ index $status . }}
<a href="/status/{{.}}" class="text-indigo-500 hover:text-indigo-400">
<i class="fas fa-info"></i> Status
</a>
</td>
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
<a href="/talk/{{.}}" class="text-indigo-500 hover:text-indigo-400">
<i class="fas fa-comments"></i> Talk
</a>
</td>
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
<button class="action-btn start-btn"
hx-put="/start/{{.}}"
hx-swap="none"
hx-ext="json-enc"
data-action="start"
data-agent="{{.}}">
Start
</button>
</td>
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
<button class="action-btn pause-btn"
hx-put="/pause/{{.}}"
hx-swap="none"
hx-ext="json-enc"
data-action="pause"
data-agent="{{.}}">
Pause
</button>
</td>
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
<a href="/settings/{{.}}" class="text-indigo-500 hover:text-indigo-400">
<i class="fas fa-cog"></i> Settings
</a>
</td>
</tr>
{{ end }}
<!-- Repeat for each agent -->
</tbody>
</table>
</div> </div>
</div> </div>
</section> <form id='import-form' hx-encoding='multipart/form-data' hx-post='/settings/import' hx-target="#response-container" hx-swap="none">
<footer class="mt-8 text-center"> <div class="mb-4">
<label for="file" class="block text-gray-300 mb-2">Select Agent File:</label>
<!-- File Upload Form --> <input type='file' name='file' id='file' class="bg-gray-700 text-white rounded p-2 w-full">
<div class="section-box">
<h2 class="text-2xl font-bold mb-4">Import Agent</h2>
<!-- Response Messages Container -->
<div id="response-container">
<!-- Success Alert -->
<div id="success-alert" class="alert alert-success">
Agent imported successfully! The page will refresh in a moment.
</div>
<!-- Error Alert -->
<div id="error-alert" class="alert alert-error">
<span id="error-message">Error importing agent.</span>
</div>
</div> </div>
<div class="flex items-center">
<form id='import-form' hx-encoding='multipart/form-data' hx-post='/settings/import' hx-target="#response-container" hx-swap="none"> <button id="import-button" type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out">
<div class="mb-4"> Import Agent
<label for="file" class="block text-gray-300 mb-2">Select Agent File:</label> </button>
<input type='file' name='file' id='file' class="bg-gray-700 text-white rounded p-2 w-full"> <progress id='progress' value='0' max='100' class="ml-4"></progress>
</div> </div>
<div class="flex items-center"> </form>
<button id="import-button" type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out"> </div>
Import Agent </section>
</button> <section class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<progress id='progress' value='0' max='100' class="ml-4"></progress> {{ $status := .Status }}
</div> {{ range .Agents }}
</form> <div class="card relative flex flex-col items-center text-center p-6 bg-gray-800 rounded-lg shadow-md">
<img src="/public/agent_{{.}}.png" alt="{{.}}" class="w-24 h-24 rounded-full mb-4">
<h2 class="text-xl font-bold mb-2">{{.}}</h2>
<p class="text-gray-400 mb-4">Online: {{ index $status . }}</p>
<div class="flex justify-center space-x-4">
<a href="/status/{{.}}" class="text-indigo-500 hover:text-indigo-400">
<i class="fas fa-info-circle"></i> Status
</a>
<a href="/talk/{{.}}" class="text-indigo-500 hover:text-indigo-400">
<i class="fas fa-comments"></i> Talk
</a>
<button class="action-btn start-btn" hx-put="/start/{{.}}" hx-swap="none" hx-ext="json-enc" data-action="start" data-agent="{{.}}">
Start
</button>
<button class="action-btn pause-btn" hx-put="/pause/{{.}}" hx-swap="none" hx-ext="json-enc" data-action="pause" data-agent="{{.}}">
Pause
</button>
<a href="/settings/{{.}}" class="text-indigo-500 hover:text-indigo-400">
<i class="fas fa-cog"></i> Settings
</a>
</div> </div>
</div>
</footer> {{ end }}
</div> </section>
<footer class="mt-8 text-center">
<p>&copy; 2025 Smart Agent List. All rights reserved.</p>
</footer>
</div>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
// Handle import form submission const importSection = document.getElementById('import-section');
document.getElementById('import-form').addEventListener('htmx:afterRequest', function(event) { const toggleImport = document.getElementById('toggle-import');
// Toggle import section visibility
toggleImport.addEventListener('click', function() {
importSection.classList.toggle('hidden');
});
// Handle import form submission
document.getElementById('import-form').addEventListener('htmx:afterRequest', function(event) {
const xhr = event.detail.xhr;
const successAlert = document.getElementById('success-alert');
const errorAlert = document.getElementById('error-alert');
const errorMessage = document.getElementById('error-message');
// Hide both alerts initially
successAlert.style.display = 'none';
errorAlert.style.display = 'none';
if (xhr.status === 200) {
try {
const response = JSON.parse(xhr.responseText);
if (response.status === "ok") {
// Show success message
successAlert.style.display = 'block';
// Refresh the page after a short delay
setTimeout(() => {
window.location.reload();
}, 2000);
} else if (response.error) {
// Show error message
errorMessage.textContent = response.error;
errorAlert.style.display = 'block';
}
} catch (e) {
// Handle parsing error
errorMessage.textContent = "Invalid response format";
errorAlert.style.display = 'block';
}
} else {
// Handle HTTP error
errorMessage.textContent = "Server error: " + xhr.status;
errorAlert.style.display = 'block';
}
});
// Add event listeners for Start and Pause buttons
document.querySelectorAll('.action-btn').forEach(button => {
button.addEventListener('htmx:afterRequest', function(event) {
const xhr = event.detail.xhr; const xhr = event.detail.xhr;
const successAlert = document.getElementById('success-alert'); const action = this.getAttribute('data-action');
const errorAlert = document.getElementById('error-alert'); const agent = this.getAttribute('data-agent');
const errorMessage = document.getElementById('error-message');
// Hide both alerts initially
successAlert.style.display = 'none';
errorAlert.style.display = 'none';
if (xhr.status === 200) { if (xhr.status === 200) {
try { try {
const response = JSON.parse(xhr.responseText); const response = JSON.parse(xhr.responseText);
if (response.status === "ok") { if (response.status === "ok") {
// Show success message // Show success toast
successAlert.style.display = 'block'; showToast(`Agent "${agent}" ${action === 'start' ? 'started' : 'paused'} successfully`, 'success');
// Refresh the page after a short delay // Update the status cell if needed
setTimeout(() => { updateAgentStatus(agent, action === 'start' ? true : false);
window.location.reload();
}, 2000);
} else if (response.error) { } else if (response.error) {
// Show error message // Show error toast
errorMessage.textContent = response.error; showToast(`Error: ${response.error}`, 'error');
errorAlert.style.display = 'block';
} }
} catch (e) { } catch (e) {
// Handle parsing error // Handle parsing error
errorMessage.textContent = "Invalid response format"; showToast("Invalid response format", 'error');
errorAlert.style.display = 'block';
} }
} else { } else {
// Handle HTTP error // Handle HTTP error
errorMessage.textContent = "Server error: " + xhr.status; showToast(`Server error: ${xhr.status}`, 'error');
errorAlert.style.display = 'block';
} }
}); });
// Add event listeners for Start and Pause buttons
document.querySelectorAll('.action-btn').forEach(button => {
button.addEventListener('htmx:afterRequest', function(event) {
const xhr = event.detail.xhr;
const action = this.getAttribute('data-action');
const agent = this.getAttribute('data-agent');
if (xhr.status === 200) {
try {
const response = JSON.parse(xhr.responseText);
if (response.status === "ok") {
// Show success toast
showToast(`Agent "${agent}" ${action === 'start' ? 'started' : 'paused'} successfully`, 'success');
// Update the status cell if needed
updateAgentStatus(agent, action === 'start' ? true : false);
} else if (response.error) {
// Show error toast
showToast(`Error: ${response.error}`, 'error');
}
} catch (e) {
// Handle parsing error
showToast("Invalid response format", 'error');
}
} else {
// Handle HTTP error
showToast(`Server error: ${xhr.status}`, 'error');
}
});
});
}); });
});
// Function to update agent status in the UI // Function to update agent status in the UI
function updateAgentStatus(agentName, isOnline) { function updateAgentStatus(agentName, isOnline) {
// Find the row for this agent // Find the card for this agent
const rows = document.querySelectorAll('tr[data-agent-name]'); const cards = document.querySelectorAll('.card');
rows.forEach(row => { cards.forEach(card => {
if (row.getAttribute('data-agent-name') === agentName) { const agentTitle = card.querySelector('h2').textContent;
// Find status cell (second cell in the row) if (agentTitle === agentName) {
const statusCell = row.querySelector('td:nth-child(2)'); // Update the "Online:" text
if (statusCell) { const statusText = card.querySelector('p');
// Update the "Online:" text statusText.textContent = `Online: ${isOnline}`;
const statusText = statusCell.firstChild; }
statusText.textContent = `Online: ${isOnline}`; });
} }
} </script>
}); </body>
}
</script>
</body>
</html> </html>

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +1,81 @@
<nav class="bg-gray-800 w-full"> <nav class="relative z-10 w-full" style="background-color: var(--darker-bg); border-bottom: 1px solid var(--medium-bg);">
<div class="px-4 sm:px-6 lg:px-8"> <div class="px-6 sm:px-8 lg:px-10">
<div class="flex justify-between h-16"> <div class="flex justify-between h-16 items-center">
<div class="flex"> <div class="flex items-center">
<!-- Logo container --> <!-- Logo container -->
<div class="flex-shrink-0 flex items-center"> <div class="flex-shrink-0">
<!-- Replace 'logo.png' with the actual path to your logo image --> <!-- Logo with glow effect -->
<a href="/" > <a href="/" class="flex items-center group">
<img src="/public/logo_1.png" alt="Logo" class="h-8 w-auto mr-3"> <div class="relative">
</a> <img src="/public/logo_1.png" alt="Logo" class="h-10 w-auto mr-4 transition-transform duration-300 group-hover:scale-105"
<a href="/" class="px-3 py-2 rounded-md text-sm font-medium text-white bg-gray-900 focus:outline-none focus:text-white focus:bg-gray-700"> style="filter: drop-shadow(0 0 5px var(--primary));">
<i class="fas fa-home"></i> LocalAgent <!-- Animated scan line on hover -->
</a> <div class="absolute inset-0 overflow-hidden opacity-0 group-hover:opacity-100 transition-opacity duration-300">
<a href="/agents" class="px-3 py-2 rounded-md text-sm font-medium text-gray-300 hover:text-white hover:bg-gray-700 focus:outline-none focus:text-white focus:bg-gray-700"> <div class="absolute inset-0 bg-gradient-to-b from-transparent via-var(--primary) to-transparent opacity-30"
<i class="fas fa-users"></i> Agent list style="height: 10px; animation: scanline 1.5s linear infinite;"></div>
</div>
</div>
<span class="text-xl font-bold transition-colors duration-300"
style="color: var(--primary); text-shadow: var(--neon-glow);">LocalAgent</span>
</a> </a>
</div> </div>
<div class="hidden md:block ml-10">
<div class="flex space-x-4">
<a href="/" class="px-3 py-2 rounded-md text-lg font-medium text-white hover:bg-gray-800 transition duration-300 relative overflow-hidden group">
<i class="fas fa-home mr-2"></i> Home
<!-- Underline animation -->
<span class="absolute bottom-0 left-0 w-0 h-0.5 group-hover:w-full transition-all duration-300"
style="background: linear-gradient(90deg, var(--primary), var(--secondary));"></span>
</a>
<a href="/agents" class="px-3 py-2 rounded-md text-lg font-medium text-gray-400 hover:bg-gray-800 transition duration-300 relative overflow-hidden group">
<i class="fas fa-users mr-2"></i> Agent List
<!-- Underline animation -->
<span class="absolute bottom-0 left-0 w-0 h-0.5 group-hover:w-full transition-all duration-300"
style="background: linear-gradient(90deg, var(--secondary), var(--tertiary));"></span>
</a>
</div>
</div>
</div> </div>
<div class="flex items-center space-x-4">
<!-- Status badge -->
<div class="hidden md:flex items-center">
<span class="flex items-center text-sm">
<span class="w-2 h-2 rounded-full mr-2"
style="background-color: var(--primary); box-shadow: 0 0 5px var(--primary); animation: pulse 2s infinite;"></span>
<span>State: <span style="color: var(--secondary); text-shadow: var(--pink-glow);">active</span></span>
</span>
</div>
</div>
<div class="md:hidden flex items-center">
<button class="text-gray-400 hover:text-white focus:outline-none focus:text-white transition duration-300"
style="text-shadow: var(--neon-glow);"
onclick="toggleMobileMenu()">
<i class="fas fa-bars fa-lg"></i>
</button>
</div>
</div>
</div>
<!-- Mobile menu, toggle based on menu state -->
<div id="mobile-menu" class="md:hidden hidden"
style="background-color: var(--darker-bg); border-top: 1px solid var(--medium-bg);">
<div class="px-2 pt-2 pb-3 space-y-1">
<a href="/" class="block px-3 py-2 rounded-md text-base font-medium text-white hover:bg-gray-800 transition duration-300"
style="border-left: 3px solid var(--primary);">
<i class="fas fa-home mr-2"></i> Home
</a>
<a href="/agents" class="block px-3 py-2 rounded-md text-base font-medium text-gray-400 hover:bg-gray-800 transition duration-300"
style="border-left: 3px solid var(--secondary);">
<i class="fas fa-users mr-2"></i> Agent List
</a>
</div> </div>
</div> </div>
</nav> </nav>
<br> <br>
<script>
function toggleMobileMenu() {
const mobileMenu = document.getElementById('mobile-menu');
mobileMenu.classList.toggle('hidden');
}
</script>

View File

@@ -3,105 +3,6 @@
<head> <head>
<title>Agent settings {{.Name}}</title> <title>Agent settings {{.Name}}</title>
{{template "views/partials/header"}} {{template "views/partials/header"}}
<style>
.section-box {
background-color: #2a2a2a; /* Darker background for the form */
padding: 20px;
margin-bottom: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
body {
background-color: #1a1a1a; /* Lighter overall background */
color: #ffffff;
font-family: sans-serif;
padding: 20px;
}
input, button {
width: 100%;
padding: 10px;
margin-top: 5px;
border-radius: 5px;
border: none;
}
input[type="text"], input[type="file"] {
background-color: #333333;
color: white;
}
button {
background-color: #4a76a8; /* Blue color for buttons */
color: white;
cursor: pointer;
}
button:hover {
background-color: #5a86b8;
}
/* Toast notification styles */
.toast {
position: fixed;
top: 20px;
right: 20px;
max-width: 350px;
padding: 15px;
border-radius: 5px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
z-index: 1000;
opacity: 0;
transition: opacity 0.3s ease;
}
.toast-success {
background-color: #10b981;
color: white;
}
.toast-error {
background-color: #ef4444;
color: white;
}
.toast-visible {
opacity: 1;
}
/* Action button styles */
.action-button {
margin-bottom: 10px;
display: inline-block;
width: auto;
margin-right: 10px;
}
.start-button {
background-color: #10b981; /* Green */
}
.start-button:hover {
background-color: #059669;
}
.pause-button {
background-color: #f59e0b; /* Orange */
}
.pause-button:hover {
background-color: #d97706;
}
.delete-button {
background-color: #ef4444; /* Red */
color: white;
padding: 10px 15px;
border-radius: 5px;
text-decoration: none;
display: inline-block;
cursor: pointer;
}
.delete-button:hover {
background-color: #dc2626;
}
</style>
</head> </head>
<body> <body>
{{template "views/partials/menu"}} {{template "views/partials/menu"}}
@@ -111,62 +12,77 @@
<span id="toast-message"></span> <span id="toast-message"></span>
</div> </div>
<header class="text-center mb-8"> <div class="container">
<h1 class="text-3xl md:text-5xl font-bold">Agent settings - {{.Name}}</h1> <header class="text-center mb-8">
</header> <h1 class="text-3xl md:text-5xl font-bold">Agent settings - {{.Name}}</h1>
<div class="max-w-4xl mx-auto"> </header>
<div class="section-box">
<h2 class="mb-4">Agent Control</h2> <div class="max-w-4xl mx-auto">
<button <div class="section-box">
class="action-button start-button" <h2>Agent Control</h2>
hx-put="/start/{{.Name}}" <div class="button-container">
hx-swap="none" <button
data-action="start" class="action-btn start-btn"
data-agent="{{.Name}}"> hx-put="/start/{{.Name}}"
Start Agent hx-swap="none"
</button> data-action="start"
<button data-agent="{{.Name}}">
class="action-button pause-button" <i class="fas fa-play"></i> Start Agent
hx-put="/pause/{{.Name}}" </button>
hx-swap="none" <button
data-action="pause" class="action-btn pause-btn"
data-agent="{{.Name}}"> hx-put="/pause/{{.Name}}"
Pause Agent hx-swap="none"
</button> data-action="pause"
</div> data-agent="{{.Name}}">
<i class="fas fa-pause"></i> Pause Agent
</button>
</div>
</div>
<div class="section-box"> <div class="section-box">
<h2>Export</h2> <h2>Export Data</h2>
<a href="/settings/export/{{.Name}}" class="action-button">Export</a> <p class="mb-4">Export your agent configuration for backup or transfer.</p>
</div> <button
class="action-btn"
onclick="window.location.href='/settings/export/{{.Name}}'">
<i class="fas fa-file-export"></i> Export Configuration
</button>
</div>
<div class="section-box"> <div class="section-box">
<h2>Danger section</h2> <h2>Danger Zone</h2>
<button <p class="mb-4">Permanently delete this agent and all associated data. This action cannot be undone.</p>
class="delete-button" <button
hx-delete="/delete/{{.Name}}" class="action-btn"
hx-swap="none" style="background: linear-gradient(135deg, #ff4545, var(--secondary)); color: white;"
data-action="delete" hx-delete="/delete/{{.Name}}"
data-agent="{{.Name}}"> hx-swap="none"
<i class="fas fa-trash-alt"></i> Delete Agent data-action="delete"
</button> data-agent="{{.Name}}">
<i class="fas fa-trash-alt"></i> Delete Agent
</button>
</div>
<div class="user-info">
<span>Agent: {{.Name}}</span>
<span class="timestamp">Last modified: <span id="current-date"></span></span>
</div>
</div> </div>
</div> </div>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
// Add event listeners for action buttons (Start, Pause) // Add event listeners for action buttons (Start, Pause)
document.querySelectorAll('.action-button').forEach(button => { document.querySelectorAll('[data-action]').forEach(button => {
button.addEventListener('htmx:afterRequest', function(event) { button.addEventListener('htmx:afterRequest', function(event) {
handleActionResponse(event, this); handleActionResponse(event, this);
}); });
}); });
// Add event listener for delete button // Set current date for timestamp
document.querySelector('.delete-button').addEventListener('htmx:afterRequest', function(event) { const now = new Date();
handleActionResponse(event, this); document.getElementById('current-date').textContent = now.toISOString().split('T')[0];
});
}); });
// Function to handle API responses for all actions // Function to handle API responses for all actions
@@ -192,6 +108,10 @@
break; break;
case 'delete': case 'delete':
message = `Agent "${agent}" deleted successfully`; message = `Agent "${agent}" deleted successfully`;
// Redirect to agent list page after short delay for delete
setTimeout(() => {
window.location.href = "/agents";
}, 2000);
break; break;
default: default:
message = "Operation completed successfully"; message = "Operation completed successfully";
@@ -200,11 +120,6 @@
// Show success message // Show success message
showToast(message, 'success'); showToast(message, 'success');
// Redirect to agent list page after short delay
setTimeout(() => {
window.location.href = "/agents";
}, 2000);
} else if (response.error) { } else if (response.error) {
// Show error message // Show error message
showToast(`Error: ${response.error}`, 'error'); showToast(`Error: ${response.error}`, 'error');
@@ -218,8 +133,6 @@
showToast(`Server error: ${xhr.status}`, 'error'); showToast(`Server error: ${xhr.status}`, 'error');
} }
} }
</script> </script>
</body> </body>
</html> </html>