"""HTTP/WebSocket client for the PhysiX-Live environment. Subclasses :class:`openenv.core.EnvClient` to provide PhysiX-specific serialisation and parsing. The base class handles WebSocket connection, session management, and the OpenEnv wire protocol. """ from __future__ import annotations from typing import Any from openenv.core import EnvClient from openenv.core.client_types import StepResult from physix.models import PhysiXAction, PhysiXObservation, PhysiXState class PhysiXEnv(EnvClient[PhysiXAction, PhysiXObservation, PhysiXState]): """Client for the PhysiX-Live OpenEnv environment. Example:: >>> async with PhysiXEnv(base_url="http://localhost:8000") as env: ... result = await env.reset() ... while not result.done: ... action = agent.predict(result.observation) ... result = await env.step(action) """ def _step_payload(self, action: PhysiXAction) -> dict[str, Any]: return action.model_dump(exclude_none=False) def _parse_result(self, payload: dict[str, Any]) -> StepResult[PhysiXObservation]: observation_data = payload.get("observation", {}) or {} observation = PhysiXObservation(**observation_data) return StepResult( observation=observation, reward=payload.get("reward"), done=payload.get("done", False), ) def _parse_state(self, payload: dict[str, Any]) -> PhysiXState: return PhysiXState(**payload)