Spaces:
Sleeping
Sleeping
Making changes again
Browse files- inference.py +3 -3
- pyproject.toml +1 -1
- server/app.py +3 -18
inference.py
CHANGED
|
@@ -100,9 +100,9 @@ Your goal is to investigate logs and alerts, identify the threat, and mitigate i
|
|
| 100 |
# ---------------------------------------------------------------------------
|
| 101 |
|
| 102 |
def _format_observation(obs: IncidentObservation) -> str:
|
| 103 |
-
logs_txt = "\n".join(f" [{l
|
| 104 |
-
alerts_txt = "\n".join(f" [{a
|
| 105 |
-
services_txt = "\n".join(f" {s
|
| 106 |
return (
|
| 107 |
f"=== Incident Dashboard (Step {obs.step_count}) ===\n\n"
|
| 108 |
f"LOGS:\n{logs_txt}\n\n"
|
|
|
|
| 100 |
# ---------------------------------------------------------------------------
|
| 101 |
|
| 102 |
def _format_observation(obs: IncidentObservation) -> str:
|
| 103 |
+
logs_txt = "\n".join(f" [{l['log_id']}] {l['timestamp']} β {l['message']}" for l in obs.logs)
|
| 104 |
+
alerts_txt = "\n".join(f" [{a['severity'].upper()}] {a['message']}" for a in obs.alerts)
|
| 105 |
+
services_txt = "\n".join(f" {s['name']}: {s['status']}" for s in obs.services)
|
| 106 |
return (
|
| 107 |
f"=== Incident Dashboard (Step {obs.step_count}) ===\n\n"
|
| 108 |
f"LOGS:\n{logs_txt}\n\n"
|
pyproject.toml
CHANGED
|
@@ -19,7 +19,7 @@ dependencies = [
|
|
| 19 |
"httpx>=0.27.0",
|
| 20 |
"openai>=1.30.0",
|
| 21 |
"python-dotenv>=1.0.0",
|
| 22 |
-
"openenv>=0.2.0",
|
| 23 |
]
|
| 24 |
|
| 25 |
[project.scripts]
|
|
|
|
| 19 |
"httpx>=0.27.0",
|
| 20 |
"openai>=1.30.0",
|
| 21 |
"python-dotenv>=1.0.0",
|
| 22 |
+
"openenv-core>=0.2.0",
|
| 23 |
]
|
| 24 |
|
| 25 |
[project.scripts]
|
server/app.py
CHANGED
|
@@ -1,15 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
server/app.py β FastAPI server for xsecure.
|
| 3 |
Uses openenv-core's create_fastapi_app β all endpoints generated automatically.
|
| 4 |
-
|
| 5 |
-
Endpoints provided by openenv-core:
|
| 6 |
-
GET /health β health check
|
| 7 |
-
POST /reset β reset environment (also used by prevalidation.sh)
|
| 8 |
-
POST /step β execute action
|
| 9 |
-
GET /state β current state
|
| 10 |
-
WS /ws β persistent WebSocket session
|
| 11 |
-
GET /docs β OpenAPI docs
|
| 12 |
-
GET /web β interactive web UI
|
| 13 |
"""
|
| 14 |
|
| 15 |
from __future__ import annotations
|
|
@@ -17,22 +8,16 @@ from __future__ import annotations
|
|
| 17 |
import os
|
| 18 |
|
| 19 |
try:
|
| 20 |
-
from
|
| 21 |
except ImportError:
|
| 22 |
from core.env_server import create_fastapi_app
|
| 23 |
|
| 24 |
from .environment import IncidentEnvironment
|
|
|
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
# App β openenv-core creates all routes automatically
|
| 28 |
-
# ---------------------------------------------------------------------------
|
| 29 |
-
|
| 30 |
-
env = IncidentEnvironment()
|
| 31 |
app = create_fastapi_app(IncidentEnvironment, IncidentAction, IncidentObservation)
|
| 32 |
|
| 33 |
-
# ---------------------------------------------------------------------------
|
| 34 |
-
# Entry point β required by openenv validate and pyproject.toml scripts
|
| 35 |
-
# ---------------------------------------------------------------------------
|
| 36 |
|
| 37 |
def main():
|
| 38 |
import uvicorn
|
|
|
|
| 1 |
"""
|
| 2 |
server/app.py β FastAPI server for xsecure.
|
| 3 |
Uses openenv-core's create_fastapi_app β all endpoints generated automatically.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
from __future__ import annotations
|
|
|
|
| 8 |
import os
|
| 9 |
|
| 10 |
try:
|
| 11 |
+
from openenv_core.env_server import create_fastapi_app
|
| 12 |
except ImportError:
|
| 13 |
from core.env_server import create_fastapi_app
|
| 14 |
|
| 15 |
from .environment import IncidentEnvironment
|
| 16 |
+
from models import IncidentAction, IncidentObservation # β required by create_fastapi_app
|
| 17 |
|
| 18 |
+
# Pass the CLASS (not an instance) plus action and observation classes
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
app = create_fastapi_app(IncidentEnvironment, IncidentAction, IncidentObservation)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def main():
|
| 23 |
import uvicorn
|