GUI-configurable agent settings + hide paused agents

This commit is contained in:
2026-04-13 01:48:56 +00:00
parent 1dcfc9f46e
commit b299ea701a
4 changed files with 237 additions and 164 deletions
+20 -1
View File
@@ -80,12 +80,14 @@ class AgentCreate(BaseModel):
name: str
description: str = ""
schedule: str = "manual"
config: dict = {}
class AgentUpdate(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
schedule: Optional[str] = None
status: Optional[str] = None
config: Optional[dict] = None
class RunCreate(BaseModel):
status: str = "running"
@@ -108,6 +110,15 @@ def health():
return {"status": "ok", "service": "agent-command-center"}
@app.get("/api/agents/{agent_id}/config")
def get_agent_config(agent_id: str, db: Session = Depends(get_db)):
"""Internal endpoint for agents to fetch their config. No auth required."""
agent = db.query(Agent).filter(Agent.id == agent_id).first()
if not agent:
raise HTTPException(status_code=404, detail="Agent not found")
return agent.config or {}
@app.get("/api/agents")
def list_agents(user: str = Depends(require_auth), db: Session = Depends(get_db)):
agents = db.query(Agent).all()
@@ -127,6 +138,7 @@ def list_agents(user: str = Depends(require_auth), db: Session = Depends(get_db)
"description": a.description,
"schedule": a.schedule,
"status": a.status,
"config": a.config or {},
"created_at": a.created_at.isoformat() if a.created_at else None,
"last_run": {
"status": last_run.status,
@@ -149,6 +161,7 @@ def create_agent(agent: AgentCreate, db: Session = Depends(get_db)):
name=agent.name,
description=agent.description,
schedule=agent.schedule,
config=agent.config,
)
db.add(new_agent)
db.commit()
@@ -167,6 +180,7 @@ def get_agent(agent_id: str, user: str = Depends(require_auth), db: Session = De
"description": agent.description,
"schedule": agent.schedule,
"status": agent.status,
"config": agent.config or {},
"created_at": agent.created_at.isoformat() if agent.created_at else None,
"runs": [{
"id": r.id,
@@ -185,7 +199,12 @@ def update_agent(agent_id: str, update: AgentUpdate, db: Session = Depends(get_d
agent = db.query(Agent).filter(Agent.id == agent_id).first()
if not agent:
raise HTTPException(status_code=404, detail="Agent not found")
for field, value in update.model_dump(exclude_none=True).items():
updates = update.model_dump(exclude_none=True)
if "config" in updates:
current_config = agent.config or {}
current_config.update(updates.pop("config"))
agent.config = current_config
for field, value in updates.items():
setattr(agent, field, value)
db.commit()
return {"id": agent.id, "status": "updated"}
+1
View File
@@ -12,6 +12,7 @@ class Agent(Base):
description = Column(Text, default="")
schedule = Column(String, default="manual")
status = Column(String, default="active")
config = Column(JSON, default=dict)
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
runs = relationship("Run", back_populates="agent", order_by="Run.started_at.desc()")
+206 -162
View File
@@ -13,6 +13,7 @@
--text: #e4e6ed;
--text-dim: #8b8fa3;
--accent: #6c5ce7;
--accent-hover: #7c6ef0;
--green: #00b894;
--red: #e17055;
--yellow: #fdcb6e;
@@ -33,79 +34,41 @@
align-items: center;
justify-content: space-between;
}
.header h1 {
font-size: 1.4rem;
font-weight: 600;
letter-spacing: -0.02em;
}
.header h1 { font-size: 1.4rem; font-weight: 600; letter-spacing: -0.02em; }
.header .status {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.85rem;
color: var(--text-dim);
}
.header .status .dot {
width: 8px; height: 8px;
border-radius: 50%;
background: var(--green);
display: flex; align-items: center; gap: 0.5rem;
font-size: 0.85rem; color: var(--text-dim);
}
.header .status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.logout-btn {
background: none;
border: 1px solid var(--border);
color: var(--text-dim);
padding: 0.35rem 0.75rem;
border-radius: 6px;
font-size: 0.8rem;
cursor: pointer;
margin-left: 1rem;
transition: border-color 0.2s, color 0.2s;
background: none; border: 1px solid var(--border); color: var(--text-dim);
padding: 0.35rem 0.75rem; border-radius: 6px; font-size: 0.8rem;
cursor: pointer; margin-left: 1rem; transition: border-color 0.2s, color 0.2s;
}
.logout-btn:hover { border-color: var(--text-dim); color: var(--text); }
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 2rem; }
/* Agent Cards */
.agents-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
gap: 1rem; margin-bottom: 0.75rem;
}
.agent-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 10px;
padding: 1.25rem;
cursor: pointer;
background: var(--surface); border: 1px solid var(--border);
border-radius: 10px; padding: 1.25rem; cursor: pointer;
transition: border-color 0.2s, transform 0.1s;
}
.agent-card:hover {
border-color: var(--accent);
transform: translateY(-1px);
}
.agent-card .card-top {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 0.75rem;
}
.agent-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.agent-card.dimmed { opacity: 0.45; }
.agent-card.dimmed:hover { opacity: 0.7; }
.agent-card .card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.75rem; }
.agent-card h3 { font-size: 1.05rem; font-weight: 600; }
.agent-card .desc { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; }
.agent-card .card-stats {
display: flex;
gap: 1.25rem;
font-size: 0.8rem;
color: var(--text-dim);
}
.agent-card .card-stats { display: flex; gap: 1.25rem; font-size: 0.8rem; color: var(--text-dim); }
.agent-card .card-stats span { display: flex; align-items: center; gap: 0.3rem; }
.badge {
display: inline-block;
padding: 0.15rem 0.6rem;
border-radius: 12px;
font-size: 0.75rem;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.03em;
display: inline-block; padding: 0.15rem 0.6rem; border-radius: 12px;
font-size: 0.75rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.active { background: rgba(0,184,148,0.15); color: var(--green); }
.badge.paused { background: rgba(253,203,110,0.15); color: var(--yellow); }
@@ -114,104 +77,87 @@
.badge.failed { background: rgba(225,112,85,0.15); color: var(--red); }
.badge.running { background: rgba(116,185,255,0.15); color: var(--blue); }
/* Section headers */
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
.paused-toggle {
background: none; border: none; color: var(--text-dim); font-size: 0.8rem;
cursor: pointer; padding: 0.4rem 0; margin-bottom: 1.5rem; display: none;
}
.paused-toggle:hover { color: var(--text); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-header h2 { font-size: 1.1rem; font-weight: 600; }
/* Run History Table */
.runs-table {
width: 100%;
border-collapse: collapse;
background: var(--surface);
border-radius: 10px;
overflow: hidden;
border: 1px solid var(--border);
width: 100%; border-collapse: collapse; background: var(--surface);
border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
}
.runs-table th {
text-align: left;
padding: 0.75rem 1rem;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--text-dim);
background: var(--surface2);
border-bottom: 1px solid var(--border);
}
.runs-table td {
padding: 0.65rem 1rem;
font-size: 0.85rem;
border-bottom: 1px solid var(--border);
text-align: left; padding: 0.75rem 1rem; font-size: 0.75rem; font-weight: 600;
text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
background: var(--surface2); border-bottom: 1px solid var(--border);
}
.runs-table td { padding: 0.65rem 1rem; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.runs-table tr:last-child td { border-bottom: none; }
.runs-table tr:hover td { background: var(--surface2); }
.output-preview {
max-width: 350px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: var(--text-dim);
}
.output-preview { max-width: 350px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
/* Detail Modal */
.modal-overlay {
display: none;
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.6);
z-index: 100;
justify-content: center;
align-items: flex-start;
padding-top: 5vh;
display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.6); z-index: 100; justify-content: center;
align-items: flex-start; padding-top: 5vh;
}
.modal-overlay.open { display: flex; }
.modal {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
width: 90%;
max-width: 800px;
max-height: 85vh;
overflow-y: auto;
padding: 1.5rem;
background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
width: 90%; max-width: 800px; max-height: 85vh; overflow-y: auto; padding: 1.5rem;
}
.modal h2 { margin-bottom: 0.5rem; }
.modal .meta { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1.5rem; }
.modal .close-btn {
float: right;
background: none;
border: none;
color: var(--text-dim);
font-size: 1.5rem;
cursor: pointer;
float: right; background: none; border: none; color: var(--text-dim);
font-size: 1.5rem; cursor: pointer;
}
.modal .close-btn:hover { color: var(--text); }
.run-output {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px;
padding: 1rem;
font-family: 'SF Mono', Monaco, Consolas, monospace;
font-size: 0.8rem;
white-space: pre-wrap;
max-height: 200px;
overflow-y: auto;
margin-top: 0.5rem;
color: var(--text-dim);
background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
padding: 1rem; font-family: 'SF Mono', Monaco, Consolas, monospace;
font-size: 0.8rem; white-space: pre-wrap; max-height: 200px; overflow-y: auto;
margin-top: 0.5rem; color: var(--text-dim);
}
.empty-state {
text-align: center;
padding: 3rem;
color: var(--text-dim);
/* Config form */
.config-section {
background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
padding: 1rem; margin-bottom: 1.5rem;
}
.config-section h3 { font-size: 0.95rem; margin-bottom: 1rem; }
.config-grid {
display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem;
}
.config-field label {
display: block; font-size: 0.75rem; font-weight: 500; color: var(--text-dim);
text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.3rem;
}
.config-field input, .config-field select {
width: 100%; padding: 0.5rem 0.65rem; background: var(--surface);
border: 1px solid var(--border); border-radius: 6px; color: var(--text);
font-size: 0.85rem; outline: none;
}
.config-field input:focus, .config-field select:focus { border-color: var(--accent); }
.config-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.btn-save {
padding: 0.5rem 1.25rem; background: var(--accent); color: #fff;
border: none; border-radius: 6px; font-size: 0.85rem; cursor: pointer;
}
.btn-save:hover { background: var(--accent-hover); }
.btn-secondary {
padding: 0.5rem 1.25rem; background: none; color: var(--text-dim);
border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; cursor: pointer;
}
.btn-secondary:hover { border-color: var(--text-dim); color: var(--text); }
.save-msg { font-size: 0.8rem; color: var(--green); margin-left: 0.75rem; line-height: 2; }
.empty-state { text-align: center; padding: 3rem; color: var(--text-dim); }
.empty-state h3 { margin-bottom: 0.5rem; color: var(--text); }
.time-ago { color: var(--text-dim); }
</style>
</head>
@@ -227,14 +173,11 @@
</div>
<div class="container">
<div class="section-header">
<h2>Agents</h2>
</div>
<div class="section-header"><h2>Agents</h2></div>
<div class="agents-grid" id="agents-grid"></div>
<button class="paused-toggle" id="paused-toggle" onclick="togglePaused()"></button>
<div class="section-header">
<h2>Recent Runs</h2>
</div>
<div class="section-header"><h2>Recent Runs</h2></div>
<div id="runs-container"></div>
</div>
@@ -244,12 +187,13 @@
<script>
const API = '';
let showPaused = false;
let allAgents = [];
function timeAgo(dateStr) {
if (!dateStr) return 'never';
const d = new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z'));
const now = new Date();
const sec = Math.floor((now - d) / 1000);
const sec = Math.floor((new Date() - d) / 1000);
if (sec < 60) return 'just now';
if (sec < 3600) return Math.floor(sec / 60) + 'm ago';
if (sec < 86400) return Math.floor(sec / 3600) + 'h ago';
@@ -258,21 +202,32 @@ function timeAgo(dateStr) {
function formatTime(dateStr) {
if (!dateStr) return '-';
const d = new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z'));
return d.toLocaleString();
return new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z')).toLocaleString();
}
function togglePaused() {
showPaused = !showPaused;
renderAgents(allAgents);
}
function renderAgents(agents) {
allAgents = agents;
const grid = document.getElementById('agents-grid');
document.getElementById('agent-count', agents.length + ' agent' + (agents.length !== 1 ? 's' : ''));
const toggle = document.getElementById('paused-toggle');
const active = agents.filter(a => a.status !== 'paused');
const paused = agents.filter(a => a.status === 'paused');
document.getElementById('agent-count').textContent = active.length + ' active agent' + (active.length !== 1 ? 's' : '');
if (agents.length === 0) {
grid.innerHTML = '<div class="empty-state"><h3>No agents registered</h3><p>Register your first agent via the API</p></div>';
grid.innerHTML = '<div class="empty-state"><h3>No agents registered</h3></div>';
toggle.style.display = 'none';
return;
}
grid.innerHTML = agents.map(a => `
<div class="agent-card" onclick="showAgent('${a.id}')">
const visible = showPaused ? agents : active;
grid.innerHTML = visible.map(a => `
<div class="agent-card ${a.status === 'paused' ? 'dimmed' : ''}" onclick="showAgent('${a.id}')">
<div class="card-top">
<h3>${a.name}</h3>
<span class="badge ${a.status}">${a.status}</span>
@@ -286,6 +241,15 @@ function renderAgents(agents) {
</div>
</div>
`).join('');
if (paused.length > 0) {
toggle.style.display = 'block';
toggle.textContent = showPaused
? 'Hide paused agents (' + paused.length + ')'
: 'Show paused agents (' + paused.length + ')';
} else {
toggle.style.display = 'none';
}
}
function renderRuns(runs) {
@@ -294,19 +258,15 @@ function renderRuns(runs) {
container.innerHTML = '<div class="empty-state"><p>No runs yet</p></div>';
return;
}
container.innerHTML = `
<table class="runs-table">
<thead>
<tr><th>Agent</th><th>Status</th><th>Started</th><th>Duration</th><th>Output</th></tr>
</thead>
<thead><tr><th>Agent</th><th>Status</th><th>Started</th><th>Duration</th><th>Output</th></tr></thead>
<tbody>
${runs.map(r => {
let dur = '-';
if (r.started_at && r.finished_at) {
const s = new Date(r.started_at + (r.started_at.endsWith('Z') ? '' : 'Z'));
const e = new Date(r.finished_at + (r.finished_at.endsWith('Z') ? '' : 'Z'));
const ms = e - s;
const ms = new Date(r.finished_at + (r.finished_at.endsWith('Z') ? '' : 'Z'))
- new Date(r.started_at + (r.started_at.endsWith('Z') ? '' : 'Z'));
dur = ms < 1000 ? ms + 'ms' : (ms / 1000).toFixed(1) + 's';
}
return `<tr>
@@ -318,12 +278,101 @@ function renderRuns(runs) {
</tr>`;
}).join('')}
</tbody>
</table>
`;
</table>`;
}
function buildConfigForm(agent) {
const cfg = agent.config || {};
const loc = cfg.location || {};
const hasLocation = !!cfg.location || agent.id.includes('briefing');
let html = `<div class="config-section">
<h3>Settings</h3>
<div class="config-grid">
<div class="config-field">
<label>Schedule</label>
<input type="text" id="cfg-schedule" value="${agent.schedule}" placeholder="0 5 * * * or manual">
</div>
<div class="config-field">
<label>Status</label>
<select id="cfg-status">
<option value="active" ${agent.status === 'active' ? 'selected' : ''}>Active</option>
<option value="paused" ${agent.status === 'paused' ? 'selected' : ''}>Paused</option>
</select>
</div>`;
if (hasLocation) {
html += `
<div class="config-field">
<label>City</label>
<input type="text" id="cfg-loc-name" value="${loc.name || ''}" placeholder="Providence">
</div>
<div class="config-field">
<label>State</label>
<input type="text" id="cfg-loc-state" value="${loc.state || ''}" placeholder="Utah">
</div>
<div class="config-field">
<label>Country</label>
<input type="text" id="cfg-loc-country" value="${loc.country || 'US'}" placeholder="US">
</div>
<div class="config-field">
<label>Latitude</label>
<input type="number" step="0.0001" id="cfg-loc-lat" value="${loc.lat || ''}" placeholder="41.7064">
</div>
<div class="config-field">
<label>Longitude</label>
<input type="number" step="0.0001" id="cfg-loc-lon" value="${loc.lon || ''}" placeholder="-111.8133">
</div>`;
}
html += `</div>
<div class="config-actions">
<button class="btn-save" onclick="saveConfig('${agent.id}', ${hasLocation})">Save</button>
<span class="save-msg" id="save-msg"></span>
</div>
</div>`;
return html;
}
async function saveConfig(agentId, hasLocation) {
const body = {
schedule: document.getElementById('cfg-schedule').value,
status: document.getElementById('cfg-status').value,
};
if (hasLocation) {
body.config = {
location: {
name: document.getElementById('cfg-loc-name').value,
state: document.getElementById('cfg-loc-state').value,
country: document.getElementById('cfg-loc-country').value || 'US',
lat: parseFloat(document.getElementById('cfg-loc-lat').value) || 0,
lon: parseFloat(document.getElementById('cfg-loc-lon').value) || 0,
}
};
}
const res = await fetch(API + '/api/agents/' + agentId, {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(body),
});
const msg = document.getElementById('save-msg');
if (res.ok) {
msg.textContent = 'Saved';
msg.style.color = 'var(--green)';
setTimeout(() => { msg.textContent = ''; }, 2000);
refresh();
} else {
msg.textContent = 'Error saving';
msg.style.color = 'var(--red)';
}
}
async function showAgent(id) {
const res = await fetch(API + '/api/agents/' + id);
if (res.status === 401) { window.location.href = '/login'; return; }
const agent = await res.json();
const modal = document.getElementById('modal-content');
modal.innerHTML = `
@@ -334,6 +383,7 @@ async function showAgent(id) {
&nbsp; Schedule: ${agent.schedule} &nbsp; Created: ${formatTime(agent.created_at)}
</div>
<p style="margin-bottom:1.5rem;color:var(--text-dim)">${agent.description}</p>
${buildConfigForm(agent)}
<h3 style="margin-bottom:0.75rem">Run History</h3>
${agent.runs.length === 0 ? '<p style="color:var(--text-dim)">No runs yet</p>' :
agent.runs.map(r => `
@@ -346,15 +396,11 @@ async function showAgent(id) {
${r.error ? '<div class="run-output" style="border-color:var(--red)">' + r.error + '</div>' : ''}
</div>
`).join('')
}
`;
}`;
document.getElementById('modal-overlay').classList.add('open');
}
function closeModal() {
document.getElementById('modal-overlay').classList.remove('open');
}
function closeModal() { document.getElementById('modal-overlay').classList.remove('open'); }
document.getElementById('modal-overlay').addEventListener('click', e => {
if (e.target === e.currentTarget) closeModal();
});
@@ -376,9 +422,7 @@ async function refresh() {
}
renderAgents(await agentsRes.json());
renderRuns(await runsRes.json());
} catch (err) {
console.error('Failed to fetch:', err);
}
} catch (err) { console.error('Failed to fetch:', err); }
}
refresh();