Spaces:
Sleeping
Sleeping
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. | |
| # | |
| # This source code is licensed under the BSD-style license found in the | |
| # LICENSE file in the root directory of this source tree. | |
| """Etl Environment Client.""" | |
| from typing import Dict | |
| from openenv.core import EnvClient | |
| from openenv.core.client_types import StepResult | |
| from openenv.core.env_server.types import State | |
| from .models import EtlAction, EtlObservation | |
| class EtlEnv( | |
| EnvClient[EtlAction, EtlObservation, State] | |
| ): | |
| """ | |
| Client for the Etl Environment. | |
| This client maintains a persistent WebSocket connection to the environment server, | |
| enabling efficient multi-step interactions with lower latency. | |
| Each client instance has its own dedicated environment session on the server. | |
| """ | |
| def _step_payload(self, action: EtlAction) -> Dict: | |
| """ | |
| Convert EtlAction to JSON payload for step message. | |
| Args: | |
| action: EtlAction instance | |
| Returns: | |
| Dictionary representation suitable for JSON encoding | |
| """ | |
| return action.model_dump(exclude_none=True) | |
| def _parse_result(self, payload: Dict) -> StepResult[EtlObservation]: | |
| """ | |
| Parse server response into StepResult[EtlObservation]. | |
| Args: | |
| payload: JSON response data from server | |
| Returns: | |
| StepResult with EtlObservation | |
| """ | |
| obs_data = payload.get("observation", {}) | |
| observation = EtlObservation( | |
| console_logs=obs_data.get("console_logs", ""), | |
| current_script_content=obs_data.get("current_script_content", ""), | |
| db_state_summary=obs_data.get("db_state_summary", ""), | |
| done=payload.get("done", False), | |
| reward=payload.get("reward", 0.0), | |
| ) | |
| return StepResult( | |
| observation=observation, | |
| reward=payload.get("reward"), | |
| done=payload.get("done", False), | |
| ) | |
| def _parse_state(self, payload: Dict) -> State: | |
| """ | |
| Parse server response into State object. | |
| Args: | |
| payload: JSON response from state request | |
| Returns: | |
| State object with episode_id and step_count | |
| """ | |
| return State( | |
| episode_id=payload.get("episode_id"), | |
| step_count=payload.get("step_count", 0), | |
| ) | |