Spaces:
Sleeping
Sleeping
| from openenv.core.env_server import create_app | |
| from models import PersonaAction, PersonaObservation | |
| from .persona_env_environment import PersonaEnvironment | |
| # = create one env instance we control (for debug visibility) | |
| _env = PersonaEnvironment() | |
| # = create the OpenEnv app (keeps /reset, /step, /schema, etc working) | |
| app = create_app( | |
| PersonaEnvironment, | |
| PersonaAction, | |
| PersonaObservation, | |
| env_name="persona_env", | |
| ) | |
| # = add a debug endpoint that reflects the live env state we control | |
| def debug_state(): | |
| return _env.state | |
| # Optional: also step/reset the debug env using the same action schema | |
| def debug_reset(): | |
| obs = _env.reset() | |
| return {"observation": obs, "reward": getattr(obs, "reward", 0.0), "done": getattr(obs, "done", False)} | |
| def debug_step(payload: dict): | |
| # payload format matches your /step envelope: {"action": {...}} | |
| action_dict = payload.get("action", {}) | |
| action = PersonaAction(**action_dict) | |
| obs = _env.step(action) | |
| return {"observation": obs, "reward": getattr(obs, "reward", 0.0), "done": getattr(obs, "done", False)} | |