Skip to content

Commit

Permalink
Fix circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr committed Jan 20, 2025
1 parent c7f1229 commit ca399bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openhands/server/config/openhands_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def attach_middleware(self, api: FastAPI) -> None:
RateLimitMiddleware,
rate_limiter=InMemoryRateLimiter(requests=10, seconds=1),
)
api.middleware('http')(AttachConversationMiddleware)
api.middleware('http')(AttachConversationMiddleware(api))


def load_openhands_config():
Expand Down
10 changes: 6 additions & 4 deletions openhands/server/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.types import ASGIApp

from openhands.server.shared import session_manager
from openhands.server import shared
from openhands.server.types import SessionMiddlewareInterface


Expand Down Expand Up @@ -134,8 +134,8 @@ async def _attach_conversation(self, request: Request) -> JSONResponse | None:
"""
Attach the user's session based on the provided authentication token.
"""
request.state.conversation = await session_manager.attach_to_conversation(
request.state.sid
request.state.conversation = (
await shared.session_manager.attach_to_conversation(request.state.sid)
)
if not request.state.conversation:
return JSONResponse(
Expand All @@ -148,7 +148,9 @@ async def _detach_session(self, request: Request) -> None:
"""
Detach the user's session.
"""
await session_manager.detach_from_conversation(request.state.conversation)
await shared.session_manager.detach_from_conversation(
request.state.conversation
)

async def __call__(self, request: Request, call_next: Callable):
if not self._should_attach(request):
Expand Down

0 comments on commit ca399bf

Please sign in to comment.