From e109f7e58edb6a564c172effc63129d8e5b4255a Mon Sep 17 00:00:00 2001 From: Dai Dao Date: Fri, 21 Feb 2025 17:14:44 -0500 Subject: [PATCH] refactor : Improve frontend setup doc and locale error (#6850) Co-authored-by: Engel Nyst --- .github/workflows/dummy-agent-test.yml | 4 ++++ .github/workflows/py-unit-tests.yml | 4 ++++ Makefile | 4 ++-- frontend/src/i18n/index.ts | 1 + openhands/server/routes/conversation.py | 8 +++++--- openhands/server/routes/feedback.py | 7 ++++--- openhands/server/routes/github.py | 18 +++++++++--------- .../server/routes/manage_conversations.py | 6 +++--- openhands/server/routes/security.py | 6 +++++- openhands/server/routes/trajectory.py | 8 +++++--- 10 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.github/workflows/dummy-agent-test.yml b/.github/workflows/dummy-agent-test.yml index ff56ef5ec1..6f98f10c95 100644 --- a/.github/workflows/dummy-agent-test.yml +++ b/.github/workflows/dummy-agent-test.yml @@ -24,6 +24,10 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Install tmux run: sudo apt-get update && sudo apt-get install -y tmux + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.x' - name: Install poetry via pipx run: pipx install poetry - name: Set up Python diff --git a/.github/workflows/py-unit-tests.yml b/.github/workflows/py-unit-tests.yml index 1e42ccc2d8..f6f6805140 100644 --- a/.github/workflows/py-unit-tests.yml +++ b/.github/workflows/py-unit-tests.yml @@ -32,6 +32,10 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Install tmux run: sudo apt-get update && sudo apt-get install -y tmux + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.x' - name: Install poetry via pipx run: pipx install poetry - name: Set up Python diff --git a/Makefile b/Makefile index 0317224d68..08ada5d64c 100644 --- a/Makefile +++ b/Makefile @@ -81,10 +81,10 @@ check-nodejs: @if command -v node > /dev/null; then \ NODE_VERSION=$(shell node --version | sed -E 's/v//g'); \ IFS='.' read -r -a NODE_VERSION_ARRAY <<< "$$NODE_VERSION"; \ - if [ "$${NODE_VERSION_ARRAY[0]}" -ge 20 ]; then \ + if [ "$${NODE_VERSION_ARRAY[0]}" -ge 22 ]; then \ echo "$(BLUE)Node.js $$NODE_VERSION is already installed.$(RESET)"; \ else \ - echo "$(RED)Node.js 20.x or later is required. Please install Node.js 20.x or later to continue.$(RESET)"; \ + echo "$(RED)Node.js 22.x or later is required. Please install Node.js 22.x or later to continue.$(RESET)"; \ exit 1; \ fi; \ else \ diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts index 52c00936d6..581bb62da1 100644 --- a/frontend/src/i18n/index.ts +++ b/frontend/src/i18n/index.ts @@ -26,6 +26,7 @@ i18n .init({ fallbackLng: "en", debug: import.meta.env.NODE_ENV === "development", + load: "languageOnly", }); export default i18n; diff --git a/openhands/server/routes/conversation.py b/openhands/server/routes/conversation.py index 3e2dfb334d..b52eb0b53e 100644 --- a/openhands/server/routes/conversation.py +++ b/openhands/server/routes/conversation.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, status from fastapi.responses import JSONResponse from openhands.core.logger import openhands_logger as logger @@ -40,11 +40,13 @@ async def get_vscode_url(request: Request): runtime: Runtime = request.state.conversation.runtime logger.debug(f'Runtime type: {type(runtime)}') logger.debug(f'Runtime VSCode URL: {runtime.vscode_url}') - return JSONResponse(status_code=200, content={'vscode_url': runtime.vscode_url}) + return JSONResponse( + status_code=status.HTTP_200_OK, content={'vscode_url': runtime.vscode_url} + ) except Exception as e: logger.error(f'Error getting VSCode URL: {e}') return JSONResponse( - status_code=500, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content={ 'vscode_url': None, 'error': f'Error getting VSCode URL: {e}', diff --git a/openhands/server/routes/feedback.py b/openhands/server/routes/feedback.py index 046b5b573e..a181315815 100644 --- a/openhands/server/routes/feedback.py +++ b/openhands/server/routes/feedback.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, status from fastapi.responses import JSONResponse from openhands.core.logger import openhands_logger as logger @@ -50,9 +50,10 @@ async def submit_feedback(request: Request, conversation_id: str): ) try: feedback_data = await call_sync_from_async(store_feedback, feedback) - return JSONResponse(status_code=200, content=feedback_data) + return JSONResponse(status_code=status.HTTP_200_OK, content=feedback_data) except Exception as e: logger.error(f'Error submitting feedback: {e}') return JSONResponse( - status_code=500, content={'error': 'Failed to submit feedback'} + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + content={'error': 'Failed to submit feedback'}, ) diff --git a/openhands/server/routes/github.py b/openhands/server/routes/github.py index 51013beff7..d4bd1c8d5a 100644 --- a/openhands/server/routes/github.py +++ b/openhands/server/routes/github.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Depends +from fastapi import APIRouter, Depends, status from fastapi.responses import JSONResponse from pydantic import SecretStr @@ -33,13 +33,13 @@ async def get_github_repositories( except GhAuthenticationError as e: return JSONResponse( content=str(e), - status_code=401, + status_code=status.HTTP_401_UNAUTHORIZED, ) except GHUnknownException as e: return JSONResponse( content=str(e), - status_code=500, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -56,13 +56,13 @@ async def get_github_user( except GhAuthenticationError as e: return JSONResponse( content=str(e), - status_code=401, + status_code=status.HTTP_401_UNAUTHORIZED, ) except GHUnknownException as e: return JSONResponse( content=str(e), - status_code=500, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -79,13 +79,13 @@ async def get_github_installation_ids( except GhAuthenticationError as e: return JSONResponse( content=str(e), - status_code=401, + status_code=status.HTTP_401_UNAUTHORIZED, ) except GHUnknownException as e: return JSONResponse( content=str(e), - status_code=500, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -108,11 +108,11 @@ async def search_github_repositories( except GhAuthenticationError as e: return JSONResponse( content=str(e), - status_code=401, + status_code=status.HTTP_401_UNAUTHORIZED, ) except GHUnknownException as e: return JSONResponse( content=str(e), - status_code=500, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) diff --git a/openhands/server/routes/manage_conversations.py b/openhands/server/routes/manage_conversations.py index 5661d21382..4ef130e49e 100644 --- a/openhands/server/routes/manage_conversations.py +++ b/openhands/server/routes/manage_conversations.py @@ -2,7 +2,7 @@ import uuid from datetime import datetime, timezone from typing import Callable -from fastapi import APIRouter, Body, Request +from fastapi import APIRouter, Body, Request, status from fastapi.responses import JSONResponse from pydantic import BaseModel, SecretStr @@ -165,7 +165,7 @@ async def new_conversation(request: Request, data: InitSessionRequest): 'message': str(e), 'msg_id': 'CONFIGURATION$SETTINGS_NOT_FOUND', }, - status_code=400, + status_code=status.HTTP_400_BAD_REQUEST, ) except LLMAuthenticationError as e: @@ -175,7 +175,7 @@ async def new_conversation(request: Request, data: InitSessionRequest): 'message': str(e), 'msg_id': 'STATUS$ERROR_LLM_AUTHENTICATION', }, - status_code=400, + status_code=status.HTTP_400_BAD_REQUEST, ) diff --git a/openhands/server/routes/security.py b/openhands/server/routes/security.py index ef1721bafb..719cfa4728 100644 --- a/openhands/server/routes/security.py +++ b/openhands/server/routes/security.py @@ -2,6 +2,7 @@ from fastapi import ( APIRouter, HTTPException, Request, + status, ) app = APIRouter(prefix='/api/conversations/{conversation_id}') @@ -23,7 +24,10 @@ async def security_api(request: Request): 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') + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail='Security analyzer not initialized', + ) return await request.state.conversation.security_analyzer.handle_api_request( request diff --git a/openhands/server/routes/trajectory.py b/openhands/server/routes/trajectory.py index 5b2e0097f2..b9732ede0c 100644 --- a/openhands/server/routes/trajectory.py +++ b/openhands/server/routes/trajectory.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, status from fastapi.responses import JSONResponse from openhands.core.logger import openhands_logger as logger @@ -28,11 +28,13 @@ async def get_trajectory(request: Request): trajectory = [] async for event in async_stream: trajectory.append(event_to_trajectory(event)) - return JSONResponse(status_code=200, content={'trajectory': trajectory}) + return JSONResponse( + status_code=status.HTTP_200_OK, content={'trajectory': trajectory} + ) except Exception as e: logger.error(f'Error getting trajectory: {e}', exc_info=True) return JSONResponse( - status_code=500, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content={ 'trajectory': None, 'error': f'Error getting trajectory: {e}',