-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
105 lines (89 loc) · 3.18 KB
/
Copy pathserver.py
File metadata and controls
105 lines (89 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import asyncio
import json
import logging
from datetime import datetime
from typing import List, Dict, Any
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, HTTPException, Depends, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from NowCurry.database import SessionLocal, init_db
from NowCurry.models import AgentStatus, Application, Job
# Global Configuration (Native Windows Pathing)
MISSION_STORAGE = os.path.join(os.getcwd(), "missions")
if not os.path.exists(MISSION_STORAGE):
os.makedirs(MISSION_STORAGE, exist_ok=True)
app = FastAPI(title="NowCurry Infinity Command Center")
# CORS for React Dashboard
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
# Mount Mission Visuals for the "Theater Mode" Dashboard
app.mount("/relay/view", StaticFiles(directory=MISSION_STORAGE), name="missions")
@app.on_event("startup")
async def startup_event():
init_db()
@app.get("/")
def read_root():
return {
"status": "online",
"platform": "NowCurry Infinity v2",
"theater_mode": "/relay/view",
"message": "Industrial Hive Control Plane is Active."
}
# --- FLEET MANAGEMENT ---
@app.get("/api/fleet")
def get_fleet_status():
db = SessionLocal()
try:
agents = db.query(AgentStatus).all()
return agents
finally:
db.close()
@app.get("/api/stats")
def get_stats():
db = SessionLocal()
try:
total_apps = db.query(Application).count()
success_apps = db.query(Application).filter(Application.status == "APPLIED").count()
failed_apps = db.query(Application).filter(Application.status == "FAILED").count()
return {
"total_applications": total_apps,
"success_rate": (success_apps / total_apps * 100) if total_apps > 0 else 0,
"failed": failed_apps
}
finally:
db.close()
# --- VISUAL RELAY (THEATER MODE) ---
@app.post("/relay/screenshot/{worker_id}")
async def relay_screenshot(worker_id: str, file: UploadFile = File(...)):
"""Receives real-time visual telemetry from worker pods."""
file_path = os.path.join(MISSION_STORAGE, f"{worker_id}_latest.png")
with open(file_path, "wb") as buffer:
buffer.write(await file.read())
return {"status": "success", "worker_id": worker_id}
# --- TELEMETRY STREAM ---
@app.websocket("/ws/logs")
async def websocket_logs(websocket: WebSocket):
await websocket.accept()
try:
while True:
# In a real environment, this would poll the DB or a Redis stream
# For the prototype, we send periodic system heartbeats
heartbeat = {
"timestamp": datetime.utcnow().isoformat(),
"agent": "SYSTEM",
"level": "INFO",
"message": "Infinity Hive Online | All nodes reporting secure."
}
await websocket.send_text(json.dumps([heartbeat]))
await asyncio.sleep(5)
except WebSocketDisconnect:
pass
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)