GUI-configurable agent settings + hide paused agents
This commit is contained in:
@@ -9,7 +9,7 @@ with a config dict specifying location, wiki parent, and agent ID.
|
|||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from shared import (
|
from shared import (
|
||||||
MT, WIKI_API, WIKI_COLLECTION_ID, MONTH_NAMES,
|
MT, DASHBOARD_API, WIKI_API, WIKI_COLLECTION_ID, MONTH_NAMES,
|
||||||
api_request, log_run, wiki_headers, find_child_doc, ensure_child_doc,
|
api_request, log_run, wiki_headers, find_child_doc, ensure_child_doc,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -122,6 +122,15 @@ def run(config):
|
|||||||
"""
|
"""
|
||||||
agent_id = config["agent_id"]
|
agent_id = config["agent_id"]
|
||||||
|
|
||||||
|
# Fetch live config from dashboard API, merge over defaults
|
||||||
|
try:
|
||||||
|
live_config = api_request(f"{DASHBOARD_API}/api/agents/{agent_id}/config")
|
||||||
|
if live_config.get("location"):
|
||||||
|
config["location"] = live_config["location"]
|
||||||
|
print(f"Using live config location: {config['location'].get('name', '?')}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Could not fetch live config, using defaults: {e}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(f"Collecting sub-agent data for {config['person']}...")
|
print(f"Collecting sub-agent data for {config['person']}...")
|
||||||
sections = collect_sections(config)
|
sections = collect_sections(config)
|
||||||
|
|||||||
+20
-1
@@ -80,12 +80,14 @@ class AgentCreate(BaseModel):
|
|||||||
name: str
|
name: str
|
||||||
description: str = ""
|
description: str = ""
|
||||||
schedule: str = "manual"
|
schedule: str = "manual"
|
||||||
|
config: dict = {}
|
||||||
|
|
||||||
class AgentUpdate(BaseModel):
|
class AgentUpdate(BaseModel):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
schedule: Optional[str] = None
|
schedule: Optional[str] = None
|
||||||
status: Optional[str] = None
|
status: Optional[str] = None
|
||||||
|
config: Optional[dict] = None
|
||||||
|
|
||||||
class RunCreate(BaseModel):
|
class RunCreate(BaseModel):
|
||||||
status: str = "running"
|
status: str = "running"
|
||||||
@@ -108,6 +110,15 @@ def health():
|
|||||||
return {"status": "ok", "service": "agent-command-center"}
|
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")
|
@app.get("/api/agents")
|
||||||
def list_agents(user: str = Depends(require_auth), db: Session = Depends(get_db)):
|
def list_agents(user: str = Depends(require_auth), db: Session = Depends(get_db)):
|
||||||
agents = db.query(Agent).all()
|
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,
|
"description": a.description,
|
||||||
"schedule": a.schedule,
|
"schedule": a.schedule,
|
||||||
"status": a.status,
|
"status": a.status,
|
||||||
|
"config": a.config or {},
|
||||||
"created_at": a.created_at.isoformat() if a.created_at else None,
|
"created_at": a.created_at.isoformat() if a.created_at else None,
|
||||||
"last_run": {
|
"last_run": {
|
||||||
"status": last_run.status,
|
"status": last_run.status,
|
||||||
@@ -149,6 +161,7 @@ def create_agent(agent: AgentCreate, db: Session = Depends(get_db)):
|
|||||||
name=agent.name,
|
name=agent.name,
|
||||||
description=agent.description,
|
description=agent.description,
|
||||||
schedule=agent.schedule,
|
schedule=agent.schedule,
|
||||||
|
config=agent.config,
|
||||||
)
|
)
|
||||||
db.add(new_agent)
|
db.add(new_agent)
|
||||||
db.commit()
|
db.commit()
|
||||||
@@ -167,6 +180,7 @@ def get_agent(agent_id: str, user: str = Depends(require_auth), db: Session = De
|
|||||||
"description": agent.description,
|
"description": agent.description,
|
||||||
"schedule": agent.schedule,
|
"schedule": agent.schedule,
|
||||||
"status": agent.status,
|
"status": agent.status,
|
||||||
|
"config": agent.config or {},
|
||||||
"created_at": agent.created_at.isoformat() if agent.created_at else None,
|
"created_at": agent.created_at.isoformat() if agent.created_at else None,
|
||||||
"runs": [{
|
"runs": [{
|
||||||
"id": r.id,
|
"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()
|
agent = db.query(Agent).filter(Agent.id == agent_id).first()
|
||||||
if not agent:
|
if not agent:
|
||||||
raise HTTPException(status_code=404, detail="Agent not found")
|
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)
|
setattr(agent, field, value)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"id": agent.id, "status": "updated"}
|
return {"id": agent.id, "status": "updated"}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Agent(Base):
|
|||||||
description = Column(Text, default="")
|
description = Column(Text, default="")
|
||||||
schedule = Column(String, default="manual")
|
schedule = Column(String, default="manual")
|
||||||
status = Column(String, default="active")
|
status = Column(String, default="active")
|
||||||
|
config = Column(JSON, default=dict)
|
||||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||||
|
|
||||||
runs = relationship("Run", back_populates="agent", order_by="Run.started_at.desc()")
|
runs = relationship("Run", back_populates="agent", order_by="Run.started_at.desc()")
|
||||||
|
|||||||
+206
-162
@@ -13,6 +13,7 @@
|
|||||||
--text: #e4e6ed;
|
--text: #e4e6ed;
|
||||||
--text-dim: #8b8fa3;
|
--text-dim: #8b8fa3;
|
||||||
--accent: #6c5ce7;
|
--accent: #6c5ce7;
|
||||||
|
--accent-hover: #7c6ef0;
|
||||||
--green: #00b894;
|
--green: #00b894;
|
||||||
--red: #e17055;
|
--red: #e17055;
|
||||||
--yellow: #fdcb6e;
|
--yellow: #fdcb6e;
|
||||||
@@ -33,79 +34,41 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
.header h1 {
|
.header h1 { font-size: 1.4rem; font-weight: 600; letter-spacing: -0.02em; }
|
||||||
font-size: 1.4rem;
|
|
||||||
font-weight: 600;
|
|
||||||
letter-spacing: -0.02em;
|
|
||||||
}
|
|
||||||
.header .status {
|
.header .status {
|
||||||
display: flex;
|
display: flex; align-items: center; gap: 0.5rem;
|
||||||
align-items: center;
|
font-size: 0.85rem; color: var(--text-dim);
|
||||||
gap: 0.5rem;
|
|
||||||
font-size: 0.85rem;
|
|
||||||
color: var(--text-dim);
|
|
||||||
}
|
|
||||||
.header .status .dot {
|
|
||||||
width: 8px; height: 8px;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: var(--green);
|
|
||||||
}
|
}
|
||||||
|
.header .status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
|
||||||
.logout-btn {
|
.logout-btn {
|
||||||
background: none;
|
background: none; border: 1px solid var(--border); color: var(--text-dim);
|
||||||
border: 1px solid var(--border);
|
padding: 0.35rem 0.75rem; border-radius: 6px; font-size: 0.8rem;
|
||||||
color: var(--text-dim);
|
cursor: pointer; margin-left: 1rem; transition: border-color 0.2s, color 0.2s;
|
||||||
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); }
|
.logout-btn:hover { border-color: var(--text-dim); color: var(--text); }
|
||||||
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 2rem; }
|
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 2rem; }
|
||||||
|
|
||||||
/* Agent Cards */
|
|
||||||
.agents-grid {
|
.agents-grid {
|
||||||
display: grid;
|
display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
|
||||||
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
|
gap: 1rem; margin-bottom: 0.75rem;
|
||||||
gap: 1rem;
|
|
||||||
margin-bottom: 2rem;
|
|
||||||
}
|
}
|
||||||
.agent-card {
|
.agent-card {
|
||||||
background: var(--surface);
|
background: var(--surface); border: 1px solid var(--border);
|
||||||
border: 1px solid var(--border);
|
border-radius: 10px; padding: 1.25rem; cursor: pointer;
|
||||||
border-radius: 10px;
|
|
||||||
padding: 1.25rem;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.2s, transform 0.1s;
|
transition: border-color 0.2s, transform 0.1s;
|
||||||
}
|
}
|
||||||
.agent-card:hover {
|
.agent-card:hover { border-color: var(--accent); transform: translateY(-1px); }
|
||||||
border-color: var(--accent);
|
.agent-card.dimmed { opacity: 0.45; }
|
||||||
transform: translateY(-1px);
|
.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 .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 h3 { font-size: 1.05rem; font-weight: 600; }
|
||||||
.agent-card .desc { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; }
|
.agent-card .desc { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; }
|
||||||
.agent-card .card-stats {
|
.agent-card .card-stats { display: flex; gap: 1.25rem; font-size: 0.8rem; color: var(--text-dim); }
|
||||||
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; }
|
.agent-card .card-stats span { display: flex; align-items: center; gap: 0.3rem; }
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
display: inline-block;
|
display: inline-block; padding: 0.15rem 0.6rem; border-radius: 12px;
|
||||||
padding: 0.15rem 0.6rem;
|
font-size: 0.75rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em;
|
||||||
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.active { background: rgba(0,184,148,0.15); color: var(--green); }
|
||||||
.badge.paused { background: rgba(253,203,110,0.15); color: var(--yellow); }
|
.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.failed { background: rgba(225,112,85,0.15); color: var(--red); }
|
||||||
.badge.running { background: rgba(116,185,255,0.15); color: var(--blue); }
|
.badge.running { background: rgba(116,185,255,0.15); color: var(--blue); }
|
||||||
|
|
||||||
/* Section headers */
|
.paused-toggle {
|
||||||
.section-header {
|
background: none; border: none; color: var(--text-dim); font-size: 0.8rem;
|
||||||
display: flex;
|
cursor: pointer; padding: 0.4rem 0; margin-bottom: 1.5rem; display: none;
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
}
|
||||||
|
.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; }
|
.section-header h2 { font-size: 1.1rem; font-weight: 600; }
|
||||||
|
|
||||||
/* Run History Table */
|
|
||||||
.runs-table {
|
.runs-table {
|
||||||
width: 100%;
|
width: 100%; border-collapse: collapse; background: var(--surface);
|
||||||
border-collapse: collapse;
|
border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
|
||||||
background: var(--surface);
|
|
||||||
border-radius: 10px;
|
|
||||||
overflow: hidden;
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
}
|
}
|
||||||
.runs-table th {
|
.runs-table th {
|
||||||
text-align: left;
|
text-align: left; padding: 0.75rem 1rem; font-size: 0.75rem; font-weight: 600;
|
||||||
padding: 0.75rem 1rem;
|
text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
|
||||||
font-size: 0.75rem;
|
background: var(--surface2); border-bottom: 1px solid var(--border);
|
||||||
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 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:last-child td { border-bottom: none; }
|
||||||
.runs-table tr:hover td { background: var(--surface2); }
|
.runs-table tr:hover td { background: var(--surface2); }
|
||||||
.output-preview {
|
.output-preview { max-width: 350px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
|
||||||
max-width: 350px;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
color: var(--text-dim);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detail Modal */
|
|
||||||
.modal-overlay {
|
.modal-overlay {
|
||||||
display: none;
|
display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
|
||||||
position: fixed;
|
background: rgba(0,0,0,0.6); z-index: 100; justify-content: center;
|
||||||
top: 0; left: 0; right: 0; bottom: 0;
|
align-items: flex-start; padding-top: 5vh;
|
||||||
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-overlay.open { display: flex; }
|
||||||
.modal {
|
.modal {
|
||||||
background: var(--surface);
|
background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
|
||||||
border: 1px solid var(--border);
|
width: 90%; max-width: 800px; max-height: 85vh; overflow-y: auto; padding: 1.5rem;
|
||||||
border-radius: 12px;
|
|
||||||
width: 90%;
|
|
||||||
max-width: 800px;
|
|
||||||
max-height: 85vh;
|
|
||||||
overflow-y: auto;
|
|
||||||
padding: 1.5rem;
|
|
||||||
}
|
}
|
||||||
.modal h2 { margin-bottom: 0.5rem; }
|
.modal h2 { margin-bottom: 0.5rem; }
|
||||||
.modal .meta { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1.5rem; }
|
.modal .meta { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1.5rem; }
|
||||||
.modal .close-btn {
|
.modal .close-btn {
|
||||||
float: right;
|
float: right; background: none; border: none; color: var(--text-dim);
|
||||||
background: none;
|
font-size: 1.5rem; cursor: pointer;
|
||||||
border: none;
|
|
||||||
color: var(--text-dim);
|
|
||||||
font-size: 1.5rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
.modal .close-btn:hover { color: var(--text); }
|
.modal .close-btn:hover { color: var(--text); }
|
||||||
.run-output {
|
.run-output {
|
||||||
background: var(--bg);
|
background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
|
||||||
border: 1px solid var(--border);
|
padding: 1rem; font-family: 'SF Mono', Monaco, Consolas, monospace;
|
||||||
border-radius: 6px;
|
font-size: 0.8rem; white-space: pre-wrap; max-height: 200px; overflow-y: auto;
|
||||||
padding: 1rem;
|
margin-top: 0.5rem; color: var(--text-dim);
|
||||||
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 {
|
/* Config form */
|
||||||
text-align: center;
|
.config-section {
|
||||||
padding: 3rem;
|
background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
|
||||||
color: var(--text-dim);
|
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); }
|
.empty-state h3 { margin-bottom: 0.5rem; color: var(--text); }
|
||||||
|
|
||||||
.time-ago { color: var(--text-dim); }
|
.time-ago { color: var(--text-dim); }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -227,14 +173,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="section-header">
|
<div class="section-header"><h2>Agents</h2></div>
|
||||||
<h2>Agents</h2>
|
|
||||||
</div>
|
|
||||||
<div class="agents-grid" id="agents-grid"></div>
|
<div class="agents-grid" id="agents-grid"></div>
|
||||||
|
<button class="paused-toggle" id="paused-toggle" onclick="togglePaused()"></button>
|
||||||
|
|
||||||
<div class="section-header">
|
<div class="section-header"><h2>Recent Runs</h2></div>
|
||||||
<h2>Recent Runs</h2>
|
|
||||||
</div>
|
|
||||||
<div id="runs-container"></div>
|
<div id="runs-container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -244,12 +187,13 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
const API = '';
|
const API = '';
|
||||||
|
let showPaused = false;
|
||||||
|
let allAgents = [];
|
||||||
|
|
||||||
function timeAgo(dateStr) {
|
function timeAgo(dateStr) {
|
||||||
if (!dateStr) return 'never';
|
if (!dateStr) return 'never';
|
||||||
const d = new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z'));
|
const d = new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z'));
|
||||||
const now = new Date();
|
const sec = Math.floor((new Date() - d) / 1000);
|
||||||
const sec = Math.floor((now - d) / 1000);
|
|
||||||
if (sec < 60) return 'just now';
|
if (sec < 60) return 'just now';
|
||||||
if (sec < 3600) return Math.floor(sec / 60) + 'm ago';
|
if (sec < 3600) return Math.floor(sec / 60) + 'm ago';
|
||||||
if (sec < 86400) return Math.floor(sec / 3600) + 'h ago';
|
if (sec < 86400) return Math.floor(sec / 3600) + 'h ago';
|
||||||
@@ -258,21 +202,32 @@ function timeAgo(dateStr) {
|
|||||||
|
|
||||||
function formatTime(dateStr) {
|
function formatTime(dateStr) {
|
||||||
if (!dateStr) return '-';
|
if (!dateStr) return '-';
|
||||||
const d = new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z'));
|
return new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z')).toLocaleString();
|
||||||
return d.toLocaleString();
|
}
|
||||||
|
|
||||||
|
function togglePaused() {
|
||||||
|
showPaused = !showPaused;
|
||||||
|
renderAgents(allAgents);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAgents(agents) {
|
function renderAgents(agents) {
|
||||||
|
allAgents = agents;
|
||||||
const grid = document.getElementById('agents-grid');
|
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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
grid.innerHTML = agents.map(a => `
|
const visible = showPaused ? agents : active;
|
||||||
<div class="agent-card" onclick="showAgent('${a.id}')">
|
grid.innerHTML = visible.map(a => `
|
||||||
|
<div class="agent-card ${a.status === 'paused' ? 'dimmed' : ''}" onclick="showAgent('${a.id}')">
|
||||||
<div class="card-top">
|
<div class="card-top">
|
||||||
<h3>${a.name}</h3>
|
<h3>${a.name}</h3>
|
||||||
<span class="badge ${a.status}">${a.status}</span>
|
<span class="badge ${a.status}">${a.status}</span>
|
||||||
@@ -286,6 +241,15 @@ function renderAgents(agents) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).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) {
|
function renderRuns(runs) {
|
||||||
@@ -294,19 +258,15 @@ function renderRuns(runs) {
|
|||||||
container.innerHTML = '<div class="empty-state"><p>No runs yet</p></div>';
|
container.innerHTML = '<div class="empty-state"><p>No runs yet</p></div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.innerHTML = `
|
container.innerHTML = `
|
||||||
<table class="runs-table">
|
<table class="runs-table">
|
||||||
<thead>
|
<thead><tr><th>Agent</th><th>Status</th><th>Started</th><th>Duration</th><th>Output</th></tr></thead>
|
||||||
<tr><th>Agent</th><th>Status</th><th>Started</th><th>Duration</th><th>Output</th></tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
${runs.map(r => {
|
${runs.map(r => {
|
||||||
let dur = '-';
|
let dur = '-';
|
||||||
if (r.started_at && r.finished_at) {
|
if (r.started_at && r.finished_at) {
|
||||||
const s = new Date(r.started_at + (r.started_at.endsWith('Z') ? '' : 'Z'));
|
const ms = new Date(r.finished_at + (r.finished_at.endsWith('Z') ? '' : 'Z'))
|
||||||
const e = new Date(r.finished_at + (r.finished_at.endsWith('Z') ? '' : 'Z'));
|
- new Date(r.started_at + (r.started_at.endsWith('Z') ? '' : 'Z'));
|
||||||
const ms = e - s;
|
|
||||||
dur = ms < 1000 ? ms + 'ms' : (ms / 1000).toFixed(1) + 's';
|
dur = ms < 1000 ? ms + 'ms' : (ms / 1000).toFixed(1) + 's';
|
||||||
}
|
}
|
||||||
return `<tr>
|
return `<tr>
|
||||||
@@ -318,12 +278,101 @@ function renderRuns(runs) {
|
|||||||
</tr>`;
|
</tr>`;
|
||||||
}).join('')}
|
}).join('')}
|
||||||
</tbody>
|
</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) {
|
async function showAgent(id) {
|
||||||
const res = await fetch(API + '/api/agents/' + id);
|
const res = await fetch(API + '/api/agents/' + id);
|
||||||
|
if (res.status === 401) { window.location.href = '/login'; return; }
|
||||||
const agent = await res.json();
|
const agent = await res.json();
|
||||||
const modal = document.getElementById('modal-content');
|
const modal = document.getElementById('modal-content');
|
||||||
modal.innerHTML = `
|
modal.innerHTML = `
|
||||||
@@ -334,6 +383,7 @@ async function showAgent(id) {
|
|||||||
Schedule: ${agent.schedule} Created: ${formatTime(agent.created_at)}
|
Schedule: ${agent.schedule} Created: ${formatTime(agent.created_at)}
|
||||||
</div>
|
</div>
|
||||||
<p style="margin-bottom:1.5rem;color:var(--text-dim)">${agent.description}</p>
|
<p style="margin-bottom:1.5rem;color:var(--text-dim)">${agent.description}</p>
|
||||||
|
${buildConfigForm(agent)}
|
||||||
<h3 style="margin-bottom:0.75rem">Run History</h3>
|
<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.length === 0 ? '<p style="color:var(--text-dim)">No runs yet</p>' :
|
||||||
agent.runs.map(r => `
|
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>' : ''}
|
${r.error ? '<div class="run-output" style="border-color:var(--red)">' + r.error + '</div>' : ''}
|
||||||
</div>
|
</div>
|
||||||
`).join('')
|
`).join('')
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
document.getElementById('modal-overlay').classList.add('open');
|
document.getElementById('modal-overlay').classList.add('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() { document.getElementById('modal-overlay').classList.remove('open'); }
|
||||||
document.getElementById('modal-overlay').classList.remove('open');
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('modal-overlay').addEventListener('click', e => {
|
document.getElementById('modal-overlay').addEventListener('click', e => {
|
||||||
if (e.target === e.currentTarget) closeModal();
|
if (e.target === e.currentTarget) closeModal();
|
||||||
});
|
});
|
||||||
@@ -376,9 +422,7 @@ async function refresh() {
|
|||||||
}
|
}
|
||||||
renderAgents(await agentsRes.json());
|
renderAgents(await agentsRes.json());
|
||||||
renderRuns(await runsRes.json());
|
renderRuns(await runsRes.json());
|
||||||
} catch (err) {
|
} catch (err) { console.error('Failed to fetch:', err); }
|
||||||
console.error('Failed to fetch:', err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|||||||
Reference in New Issue
Block a user