curaflow/tools/log-viewer/public/index.html

184 lines
5.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Curio Live Logs</title>
<style>
body {
background-color: #0d1117;
color: #c9d1d9;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
}
header {
background-color: #161b22;
padding: 16px 24px;
border-bottom: 1px solid #30363d;
display: flex;
justify-content: space-between;
align-items: center;
}
h1 {
font-size: 18px;
margin: 0;
display: flex;
align-items: center;
gap: 12px;
}
.status-dot {
width: 10px;
height: 10px;
background-color: #238636;
border-radius: 50%;
box-shadow: 0 0 8px #238636;
}
.controls {
display: flex;
gap: 12px;
}
button {
background-color: #21262d;
border: 1px solid #30363d;
color: #c9d1d9;
padding: 6px 16px;
border-radius: 6px;
cursor: pointer;
font-weight: 500;
transition: all 0.2s;
}
button:hover {
background-color: #30363d;
border-color: #8b949e;
}
button.active {
background-color: #1f6feb;
border-color: #1f6feb;
color: #ffffff;
}
#terminal {
flex: 1;
padding: 16px;
overflow-y: auto;
font-family: "Fira Code", "Consolas", monospace;
font-size: 13px;
line-height: 1.5;
background-color: #010409;
}
.log-line {
margin: 0;
word-wrap: break-word;
white-space: pre-wrap;
border-bottom: 1px solid rgba(255,255,255,0.02);
padding: 2px 0;
}
.log-error {
color: #f85149;
}
.log-info {
color: #58a6ff;
}
.log-warn {
color: #d29922;
}
.log-success {
color: #3fb950;
}
.log-timestamp {
color: #8b949e;
user-select: none;
margin-right: 12px;
}
</style>
</head>
<body>
<header>
<h1><div class="status-dot"></div> Curio Live Logs</h1>
<div class="controls">
<button id="btn-curio-app" class="active" onclick="switchService('curio-app')">Node Backend</button>
<button id="btn-curaflow-agent" onclick="switchService('curaflow-agent')">Python AI Agent</button>
<button onclick="clearLogs()">Clear</button>
</div>
</header>
<div id="terminal"></div>
<script>
let eventSource = null;
const terminal = document.getElementById('terminal');
function getTimestamp() {
const now = new Date();
return now.toISOString().split('T')[1].slice(0, 8);
}
function highlightLine(text) {
if (text.includes('[ERROR]') || text.includes('Exception') || text.includes('Failed')) return 'log-error';
if (text.includes('[WARN]')) return 'log-warn';
if (text.includes('success') || text.includes('Connected') || text.includes('ready')) return 'log-success';
if (text.includes('Processing') || text.includes('Triggering')) return 'log-info';
return '';
}
function appendLog(text, isError) {
const line = document.createElement('div');
line.className = 'log-line';
const timeSpan = document.createElement('span');
timeSpan.className = 'log-timestamp';
timeSpan.textContent = `[${getTimestamp()}]`;
const textSpan = document.createElement('span');
textSpan.className = isError ? 'log-error' : highlightLine(text);
textSpan.textContent = text;
line.appendChild(timeSpan);
line.appendChild(textSpan);
terminal.appendChild(line);
// Auto-scroll
terminal.scrollTop = terminal.scrollHeight;
}
function connectSSE(service) {
if (eventSource) {
eventSource.close();
}
appendLog(`--- Connected to ${service === 'curio-app' ? 'Node Backend' : 'Python AI Agent'} Logs ---`, false);
eventSource = new EventSource(`/api/logs?service=${service}`);
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
appendLog(data.text, data.isError);
};
eventSource.onerror = (error) => {
appendLog('[SSE Error] Connection lost. Reconnecting...', true);
eventSource.close();
setTimeout(() => connectSSE(service), 3000);
};
}
function switchService(service) {
document.getElementById('btn-curio-app').classList.remove('active');
document.getElementById('btn-curaflow-agent').classList.remove('active');
document.getElementById(`btn-${service}`).classList.add('active');
terminal.innerHTML = '';
connectSSE(service);
}
function clearLogs() {
terminal.innerHTML = '';
}
// Init
connectSSE('curio-app');
</script>
</body>
</html>