Files
blackroad-io-site/api/server.py

45 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# api/server.py
"""
Lucidia API Server WebSocket + REST
Exposes Roadie and Guardian functions via simple endpoints
"""
from fastapi import FastAPI, WebSocket
from fastapi.responses import JSONResponse
from agents.roadie import Roadie
from agents.guardian import Guardian
import uvicorn
app = FastAPI()
roadie = Roadie()
guardian = Guardian()
@app.get("/")
def home():
return {"status": "Lucidia API online"}
@app.get("/search/{query}")
def search(query: str):
results = roadie.search(query)
return JSONResponse(content={"results": results})
@app.get("/audit")
def audit():
result = guardian.verify_integrity()
return JSONResponse(content={"audit": result})
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
await websocket.send_text("🧠 Lucidia WebSocket channel ready.")
while True:
data = await websocket.receive_text()
results = roadie.search(data)
await websocket.send_json({"query": data, "matches": results})
if __name__ == "__main__":
print("🚀 Running Lucidia API at http://localhost:8000")
uvicorn.run("api.server:app", host="0.0.0.0", port=8000, reload=True)