LordXido commited on
Commit
f32fc57
·
verified ·
1 Parent(s): 88a67b0

Update api_gateway.py

Browse files
Files changed (1) hide show
  1. api_gateway.py +54 -4
api_gateway.py CHANGED
@@ -1,4 +1,5 @@
1
  from fastapi import FastAPI, HTTPException
 
2
  from datetime import datetime
3
  import uuid
4
 
@@ -14,23 +15,63 @@ app = FastAPI(
14
  description="Sovereign orchestration gateway for Codex Spaces",
15
  )
16
 
17
- # ✅ ADD THIS BLOCK
18
- @app.get("/")
 
 
19
  def root():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  return {
21
  "service": "CodexHF API Gateway",
22
  "status": "running",
23
- "message": "API gateway online",
24
  "endpoints": {
25
  "health": "/health",
 
26
  "capabilities": "/capabilities",
27
  "invoke": "/invoke",
28
  "wake": "/wake",
29
  "docs": "/docs"
30
  }
31
  }
32
- # ✅ END ADD
33
 
 
 
 
34
  @app.get("/health")
35
  def health():
36
  return {
@@ -38,12 +79,18 @@ def health():
38
  "timestamp": datetime.utcnow().isoformat()
39
  }
40
 
 
 
 
41
  @app.get("/capabilities")
42
  def capabilities():
43
  return {
44
  "capabilities": list_capabilities()
45
  }
46
 
 
 
 
47
  @app.post("/invoke")
48
  async def invoke(request: dict):
49
  trace_id = request.get("trace_id", str(uuid.uuid4()))
@@ -67,6 +114,9 @@ async def invoke(request: dict):
67
  "duration_ms": duration
68
  }
69
 
 
 
 
70
  @app.post("/wake")
71
  async def wake(request: dict):
72
  module = request.get("module")
 
1
  from fastapi import FastAPI, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
  from datetime import datetime
4
  import uuid
5
 
 
15
  description="Sovereign orchestration gateway for Codex Spaces",
16
  )
17
 
18
+ # -------------------------
19
+ # Human-facing landing page
20
+ # -------------------------
21
+ @app.get("/", response_class=HTMLResponse)
22
  def root():
23
+ return """
24
+ <!DOCTYPE html>
25
+ <html>
26
+ <head>
27
+ <title>CodexHF Sovereign API Gateway</title>
28
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
29
+ </head>
30
+ <body style="
31
+ background-color:#000;
32
+ color:#00ff00;
33
+ font-family:monospace;
34
+ display:flex;
35
+ align-items:center;
36
+ justify-content:center;
37
+ height:100vh;
38
+ margin:0;
39
+ text-align:center;
40
+ ">
41
+ <div>
42
+ <h1>🧠 CodexHF Sovereign API Gateway</h1>
43
+ <p>✅ Status: Running</p>
44
+ <p>Use <code>/invoke</code> via POST</p>
45
+ <p>
46
+ <a href="/docs" style="color:#00ff00;">View API Documentation</a>
47
+ </p>
48
+ </div>
49
+ </body>
50
+ </html>
51
+ """
52
+
53
+ # -------------------------
54
+ # Machine-readable status
55
+ # -------------------------
56
+ @app.get("/status")
57
+ def status():
58
  return {
59
  "service": "CodexHF API Gateway",
60
  "status": "running",
61
+ "timestamp": datetime.utcnow().isoformat(),
62
  "endpoints": {
63
  "health": "/health",
64
+ "status": "/status",
65
  "capabilities": "/capabilities",
66
  "invoke": "/invoke",
67
  "wake": "/wake",
68
  "docs": "/docs"
69
  }
70
  }
 
71
 
72
+ # -------------------------
73
+ # Health check
74
+ # -------------------------
75
  @app.get("/health")
76
  def health():
77
  return {
 
79
  "timestamp": datetime.utcnow().isoformat()
80
  }
81
 
82
+ # -------------------------
83
+ # Capability registry
84
+ # -------------------------
85
  @app.get("/capabilities")
86
  def capabilities():
87
  return {
88
  "capabilities": list_capabilities()
89
  }
90
 
91
+ # -------------------------
92
+ # Invocation endpoint
93
+ # -------------------------
94
  @app.post("/invoke")
95
  async def invoke(request: dict):
96
  trace_id = request.get("trace_id", str(uuid.uuid4()))
 
114
  "duration_ms": duration
115
  }
116
 
117
+ # -------------------------
118
+ # Wake a downstream Space
119
+ # -------------------------
120
  @app.post("/wake")
121
  async def wake(request: dict):
122
  module = request.get("module")