import json
from pathlib import Path
from typing import Any
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
from environment.avigilance_env import AvigilanceEnv
from environment.models import AvigilanceAction
FRONTEND_HTML = """
AvigilanceEnv Space Console
DGCA Monitoring Space
Avigilance Mission Console
20k+ Hybrid CorpusOpenEnv ReadyReal Ingestion Plan Ready
Live Operations Deck
Run task resets, inspect payloads, and submit exact environment actions from one screen.
This Space root is entirely self-contained in app.py and now fronts a 20k-plus hybrid corpus with broader airline, airport, and incident coverage, plus a documented path for DGCA, AAIB, and AAI ingestion.
The default seed is 42, which recreates the same scenario every time. If you want different observations and different rewards, change the seed or use Randomize Seed before resetting.
Observation SnapshotNo observation loaded
Last RewardNone yet
Episode StateIdle
AccuracyNot available
ConsistencyNot available
Safety AlignmentNot available
Why This ChangesDepends on seed and action
Observation Payload
Backend response after reset or step.
Press Reset Episode to start.
Action Editor
Use typed JSON matching the task schema.
The helper can prefill a valid payload, but you can edit every field before submit.
Runtime Result
State, reward, or error output from the active request.
Waiting for actions.
Observation Interpretation
Plain-English explanation of what the latest observation is telling you.
Reset a task to see the live scenario translated into plain language.
Action Interpretation
Readable summary of the action payload currently in the editor.
Pick a task or load an example action to see what your JSON is doing.
Result Interpretation
Short explanation of reward, completion state, and backend response behavior.
Submit a step or fetch state to decode the response here.
Current Task Field Guide
Human-readable meaning of the most important fields for the selected task.
Verification Path
How This Space Should Be Reviewed
1. Reset a live task
Choose one of the three environments, seed it deterministically, and inspect the exact observation payload emitted by the backend.
2. Submit a typed action
Load the generated example or replace it with your own JSON, then submit the request against the same /step endpoint validators hit.
3. Verify contract behavior
Use the result panel and activity feed to confirm reward bounds, episode status, and endpoint availability before running repository validation scripts.