Skip to content

Commit c4f20d7

Browse files
committed
chore: types
1 parent bbf9252 commit c4f20d7

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

src/core/env_server/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
deserialize_action_with_preprocessing,
1616
serialize_observation,
1717
)
18-
from .types import Action, Observation, State, SchemaResponse
18+
from .types import Action, Observation, State, SchemaResponse, HealthResponse
1919
from .web_interface import create_web_interface_app, WebInterfaceManager
2020

2121
__all__ = [
@@ -29,6 +29,7 @@
2929
"Observation",
3030
"State",
3131
"SchemaResponse",
32+
"HealthResponse",
3233
# Base transforms
3334
"CompositeTransform",
3435
"NullTransform",

src/core/env_server/http_server.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import inspect
1818
import os
1919
from concurrent.futures import ThreadPoolExecutor
20-
from typing import Any, Dict, Optional, Type
20+
from typing import Optional, Type
2121

2222
from fastapi import Body, FastAPI, HTTPException, status
2323
from pydantic import ValidationError
@@ -38,6 +38,7 @@
3838
StepResponse,
3939
EnvironmentMetadata,
4040
SchemaResponse,
41+
HealthResponse,
4142
)
4243

4344

@@ -109,17 +110,14 @@ def _get_valid_kwargs(self, sig, kwargs, skip_params=None):
109110

110111
return valid_kwargs
111112

112-
def register_routes(self, app: Any) -> None:
113+
def register_routes(self, app: FastAPI) -> None:
113114
"""
114115
Register HTTP routes on a FastAPI application.
115116
116117
Args:
117118
app: FastAPI application instance
118119
"""
119120

120-
if not isinstance(app, FastAPI):
121-
raise TypeError("app must be a FastAPI instance")
122-
123121
# Helper function to handle reset endpoint
124122
async def reset_handler(
125123
request: ResetRequest = Body(default_factory=ResetRequest),
@@ -283,8 +281,8 @@ async def step(request: StepRequest) -> StepResponse:
283281
),
284282
GetEndpointConfig(
285283
path="/health",
286-
handler=lambda: {"status": "healthy"},
287-
response_model=Dict[str, str],
284+
handler=lambda: HealthResponse(status="healthy"),
285+
response_model=HealthResponse,
288286
tag="Health",
289287
summary="Health check",
290288
description="Check if the environment server is running and healthy.",
@@ -347,7 +345,7 @@ def create_app(
347345
action_cls: Type[Action],
348346
observation_cls: Type[Observation],
349347
env_name: Optional[str] = None,
350-
) -> Any:
348+
) -> FastAPI:
351349
"""
352350
Create a FastAPI application with or without web interface.
353351
@@ -385,7 +383,7 @@ def create_fastapi_app(
385383
env: Environment,
386384
action_cls: Type[Action],
387385
observation_cls: Type[Observation],
388-
) -> Any:
386+
) -> FastAPI:
389387
"""Create a FastAPI application with comprehensive documentation."""
390388
try:
391389
from fastapi import FastAPI

src/core/env_server/route_config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@
1212
"""
1313

1414
from dataclasses import dataclass
15-
from typing import Callable, List, Type, TypeVar
15+
from typing import Callable, List, Type
1616

1717
from fastapi import FastAPI
1818
from pydantic import BaseModel
1919

20-
# TypeVar for generic response types
21-
T = TypeVar("T", bound=BaseModel)
22-
2320

2421
@dataclass
2522
class GetEndpointConfig:
2623
"""Configuration for a simple GET endpoint."""
2724

2825
path: str
2926
handler: Callable[[], BaseModel | dict]
30-
response_model: Type[BaseModel] | Type[dict]
27+
response_model: Type[BaseModel] | type[dict]
3128
tag: str
3229
summary: str
3330
description: str

src/core/env_server/types.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Observation(BaseModel):
4444
)
4545

4646
done: bool = Field(default=False, description="Whether the episode has terminated")
47-
reward: Union[bool, int, float, None] = Field(
47+
reward: bool | int | float | None = Field(
4848
default=None, description="Reward signal from the last action"
4949
)
5050
metadata: Dict[str, Any] = Field(
@@ -201,3 +201,14 @@ class SchemaResponse(BaseModel):
201201
state: Dict[str, Any] = Field(
202202
description="JSON schema for environment state objects"
203203
)
204+
205+
206+
class HealthResponse(BaseModel):
207+
"""Response model for health check endpoint."""
208+
209+
model_config = ConfigDict(
210+
extra="forbid",
211+
validate_assignment=True,
212+
)
213+
214+
status: str = Field(description="Health status of the environment server")

0 commit comments

Comments
 (0)