File size: 2,789 Bytes
4f129c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""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."
                )