90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
"""Starlette REST Route Handlers for GCP Solution Architecture Agent.
|
|
|
|
Powered by Google ADK runner, PostgreSQL database persistence, and multi-agent orchestration.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any, Dict
|
|
from starlette.requests import Request
|
|
from starlette.responses import JSONResponse
|
|
|
|
from app.adk.evaluation import ADKEvaluator
|
|
from app.adk.runners import ADKAgentRunner
|
|
from app.adk.sessions import PostgresSessionService
|
|
from app.card import AGENT_CARD
|
|
from app.config import get_settings
|
|
from app.tools.validation_tools import validate_repository_artifacts
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def health_check(request: Request) -> JSONResponse:
|
|
"""GET /health - Operational health endpoint."""
|
|
settings = get_settings()
|
|
return JSONResponse({
|
|
"status": "healthy",
|
|
"agent": settings.AGENT_NAME,
|
|
"version": settings.AGENT_VERSION,
|
|
"adk_framework": "enabled",
|
|
"database": "postgresql",
|
|
})
|
|
|
|
|
|
async def get_card(request: Request) -> JSONResponse:
|
|
"""GET /card - Agent metadata and capability card."""
|
|
return JSONResponse(AGENT_CARD)
|
|
|
|
|
|
async def run_workflow(request: Request) -> JSONResponse:
|
|
"""POST /generate - Execute multi-agent ADK workflow with PostgreSQL persistence."""
|
|
try:
|
|
body = await request.json() if request.headers.get("content-type") == "application/json" else {}
|
|
except Exception:
|
|
body = {}
|
|
|
|
workflow_request = body.get("request", "Default event-driven HTTP architecture")
|
|
target_dir = body.get("target_dir", ".")
|
|
session_id = body.get("session_id")
|
|
|
|
runner = ADKAgentRunner()
|
|
result = runner.run_execution(
|
|
session_id=session_id,
|
|
request_summary=workflow_request,
|
|
target_dir=target_dir,
|
|
)
|
|
|
|
return JSONResponse(result)
|
|
|
|
|
|
async def get_session_route(request: Request) -> JSONResponse:
|
|
"""GET /sessions/{session_id} - Query session state from PostgreSQL database."""
|
|
session_id = request.path_params.get("session_id")
|
|
session_service = PostgresSessionService()
|
|
session = session_service.get_session(session_id)
|
|
|
|
if not session:
|
|
return JSONResponse({"error": f"Session {session_id} not found"}, status_code=404)
|
|
|
|
return JSONResponse({
|
|
"session_id": session.session_id,
|
|
"agent_name": session.agent_name,
|
|
"state": session.state,
|
|
})
|
|
|
|
|
|
async def validate_artifacts_route(request: Request) -> JSONResponse:
|
|
"""POST /validate - Run pre-deployment validation checks against target directory."""
|
|
try:
|
|
body = await request.json() if request.headers.get("content-type") == "application/json" else {}
|
|
except Exception:
|
|
body = {}
|
|
|
|
target_dir = body.get("target_dir", ".")
|
|
result = validate_repository_artifacts.invoke({"target_dir": target_dir})
|
|
|
|
status_code = 200 if result.get("valid") else 400
|
|
return JSONResponse(result, status_code=status_code)
|
|
|
|
status_code = 200 if result.get("valid") else 400
|
|
return JSONResponse(result, status_code=status_code)
|