eigent/backend/app/controller/health_controller.py
Tong Chen 6c827a3d06
refactor: establish Brain-centered architecture and frontend/backend separation foundations (#1597)
Co-authored-by: Douglas <douglas.ym.lai@gmail.com>
Co-authored-by: Douglas Lai <115660088+Douglasymlai@users.noreply.github.com>
2026-05-01 17:03:33 +08:00

63 lines
2.2 KiB
Python

# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
import logging
import os
from fastapi import APIRouter, Query
from pydantic import BaseModel
from app.router_layer.hands_resolver import get_environment_hands
from app.utils.browser_launcher import _is_cdp_available, is_cdp_url_available
logger = logging.getLogger("health_controller")
router = APIRouter(tags=["Health"])
class HealthResponse(BaseModel):
status: str
service: str
capabilities: dict | None = None
@router.get("/health", name="health check", response_model=HealthResponse)
async def health_check(detail: bool = Query(False)):
"""Health check endpoint for verifying backend
is ready to accept requests."""
logger.debug("Health check requested")
response = HealthResponse(status="ok", service="eigent")
if detail:
hands = get_environment_hands()
capabilities = hands.get_capability_manifest()
cdp_url = os.environ.get("EIGENT_CDP_URL", "").strip()
if cdp_url:
cdp_reachable = is_cdp_url_available(cdp_url)
else:
try:
browser_port = int(os.environ.get("browser_port", "9222"))
except ValueError:
browser_port = 9222
cdp_reachable = _is_cdp_available(browser_port)
capabilities["browser_cdp_reachable"] = cdp_reachable
response.capabilities = capabilities
logger.debug(
"Health check completed",
extra={
"status": response.status,
"service": response.service,
"detail": detail,
},
)
return response