Skip to content

Commit

Permalink
Add type annotations to server directory files
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Feb 18, 2025
1 parent d309455 commit 04873cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions openhands/server/routes/security.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any
from fastapi import (
APIRouter,
HTTPException,
Expand All @@ -8,7 +9,7 @@


@app.route('/security/{path:path}', methods=['GET', 'POST', 'PUT', 'DELETE'])
async def security_api(request: Request):
async def security_api(request: Request) -> dict[str, Any]:
"""Catch-all route for security analyzer API requests.
Each request is handled directly to the security analyzer.
Expand All @@ -17,14 +18,17 @@ async def security_api(request: Request):
request (Request): The incoming FastAPI request object.
Returns:
Any: The response from the security analyzer.
dict: The response from the security analyzer.
Raises:
HTTPException: If the security analyzer is not initialized.
"""
if not request.state.conversation.security_analyzer:
raise HTTPException(status_code=404, detail='Security analyzer not initialized')

return await request.state.conversation.security_analyzer.handle_api_request(
response = await request.state.conversation.security_analyzer.handle_api_request(
request
)
if not isinstance(response, dict):
raise HTTPException(status_code=500, detail='Invalid response from security analyzer')
return response
4 changes: 3 additions & 1 deletion openhands/server/static.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Any, MutableMapping
from fastapi.staticfiles import StaticFiles
from starlette.responses import Response


class SPAStaticFiles(StaticFiles):
async def get_response(self, path: str, scope):
async def get_response(self, path: str, scope: MutableMapping[str, Any]) -> Response:
try:
return await super().get_response(path, scope)
except Exception:
Expand Down

0 comments on commit 04873cf

Please sign in to comment.