"""Compatibility helpers for environments where openenv-core is not installed.""" from __future__ import annotations from dataclasses import dataclass, field from typing import Any, Generic, TypeVar from pydantic import BaseModel A = TypeVar("A") O = TypeVar("O") S = TypeVar("S") OPENENV_AVAILABLE = True try: from openenv.core.client_types import StepResult # type: ignore from openenv.core.env_client import EnvClient # type: ignore from openenv.core.env_server.interfaces import Environment # type: ignore from openenv.core.env_server.types import Action, Observation, State # type: ignore from openenv.core.env_server.types import EnvironmentMetadata # type: ignore except ImportError: try: from openenv_core.client_types import StepResult # type: ignore from openenv_core.http_env_client import HTTPEnvClient as EnvClient # type: ignore from openenv_core.env_server.interfaces import Environment # type: ignore from openenv_core.env_server.types import Action, Observation, State # type: ignore from openenv_core.env_server.types import EnvironmentMetadata # type: ignore except ImportError: OPENENV_AVAILABLE = False class Action(BaseModel): """Fallback Action base type for local import-only workflows.""" class Observation(BaseModel): """Fallback Observation base type for local import-only workflows.""" reward: float = 0.0 done: bool = False class State(BaseModel): """Fallback State base type for local import-only workflows.""" class Environment(Generic[A, O, S]): """Minimal base class used for local unit tests and import-based demos.""" def __init__(self) -> None: super().__init__() class EnvironmentMetadata(BaseModel): """Fallback metadata model used when OpenEnv is absent.""" name: str description: str readme_content: str | None = None version: str | None = None author: str | None = None @dataclass class StepResult(Generic[O]): """Fallback step result for local-only client compatibility.""" observation: O reward: float done: bool info: dict[str, Any] = field(default_factory=dict) class EnvClient(Generic[A, O, S]): """Placeholder client that fails only when actually used.""" def __init__(self, *args, **kwargs) -> None: raise ImportError( "SupportDeskEnv requires openenv-core to be installed. " "Run `py -3 -m pip install openenv-core` to use the HTTP client." )