"""HTTP routes for Alba Core.
Routes translate web requests into calls to the Python core. Keep this layer
thin so Discord, WhatsApp, or a website can reuse the same core behavior later.
"""
from __future__ import annotations
from typing import Any
from fastapi import APIRouter
from pydantic import BaseModel, Field
from app.alba_core.pipeline import AlbaCore
router = APIRouter()
[docs]
class SearchRequest(BaseModel):
"""Request body for a single Alba Core search turn.
current_requirements lets a channel wrapper continue a line-by-line
conversation without Alba Core needing to know where the message came from.
"""
message: str = Field(min_length=1)
current_requirements: dict[str, Any] | None = None
def _run_search(request: SearchRequest) -> dict[str, Any]:
"""Run extraction, matching, scoring, and lead summary for one message."""
alba_core = AlbaCore.from_environment()
return alba_core.search(
request.message,
current_requirements=request.current_requirements,
)
[docs]
@router.post("/alba-core/search")
def search(request: SearchRequest) -> dict[str, Any]:
"""Run the public Alba Core search endpoint."""
return _run_search(request)