openenv/coding_env
21
1"""2CodingEnv3---------4Client-side wrapper for the Coding environment server.5Talks HTTP to a single base_url exposing: /reset and /step.6 7- users instantiate CodingEnv with a base_url provided by the higher-level8 vector/orchestration layer.9- Environment authors ship the Docker image that serves the HTTP API.10 11(Seeds, episode IDs, request IDs, capabilities can be added later in the payloads.)12"""13 14from __future__ import annotations15 16from typing import Optional, TYPE_CHECKING17 18from core.client_types import StepResult19 20from core.http_env_client import HTTPEnvClient21 22from .models import CodeAction, CodeObservation, CodeState23 24if TYPE_CHECKING:25 from core.containers.runtime import ContainerProvider26 27 28class CodingEnv(HTTPEnvClient[CodeAction, CodeObservation]):29 # --- HTTPEnvClient abstract hooks ---30 31 def _step_payload(self, action: CodeAction) -> dict:32 # Shape expected by the server's /step endpoint under "action"33 return {34 "code": action.code,35 }36 37 def _parse_result(self, payload: dict) -> StepResult[CodeObservation]:38 # Expecting: { "observation": {...}, "reward": <float|null>, "done": <bool>, "info": {...} }39 obs = CodeObservation(**payload["observation"])40 return StepResult(41 observation=obs,42 reward=payload.get("reward"),43 done=bool(payload.get("done", False)),44 )45 46 def _parse_state(self, payload: dict) -> CodeState:47 """48 Parse server response into CodeState object.49 50 Args:51 payload: JSON response from /state endpoint52 53 Returns:54 CodeState object with episode_id, step_count, and last_exit_code55 """56 return CodeState(57 episode_id=payload.get("episode_id"),58 step_count=payload.get("step_count", 0),59 last_exit_code=payload.get("last_exit_code", 0),60 )61 