refactor(server): adopt uv and modular typed FastAPI structure

This commit is contained in:
2026-10-06 18:18:36 -03:00
parent 34f0d1b125
commit 92c53dc7ca
38 changed files with 8363 additions and 6622 deletions
+54
View File
@@ -0,0 +1,54 @@
from __future__ import annotations
from typing import Any
from fastapi import APIRouter, Request
from s2s_client.core import config as settings
from s2s_client.core import logging as app_logging
from s2s_client.core import urls as core_urls
router = APIRouter()
def _effective_s2s_url(request: Request) -> str:
return settings.SPEECH_TO_SPEECH_URL or core_urls._proxy_public_url(request)
@router.get("/api/config")
async def config(request: Request) -> dict[str, Any]:
"""Client bootstrap: whether web search is available, whether the deploy runs
behind a load balancer (so the browser uses the /api/session proxy),
and whether the user may instead set a direct
s2s server URL. The LB address itself is intentionally NOT included.
2026-09-24: new top-level `apipilot` flag. When True the deploy exposes the
new `/api/apipilot/tools` and `/api/apipilot/execute` proxy endpoints (see
docs/client/tool-calling.md) that the browser may call directly instead of
hardcoding upstream tool URLs / names."""
app_logging.logger.debug(
"[INTERNAL] /api/config requested client=%s", request.client.host if request.client else "?"
)
primary_prompt = settings.S2S_PRIMARY_PROMPT
out = {
"search": bool(settings.SERPER_KEY),
"lb": bool(settings.LOAD_BALANCER_URL),
"allowDirect": not settings.LOAD_BALANCER_URL,
"s2sUrl": _effective_s2s_url(request),
"primaryPrompt": primary_prompt,
"reasoningType": settings.S2S_REASONING_TYPE,
"injectProfile": settings.S2S_INJECT_PROFILE,
"debugPrompt": settings.S2S_DEBUG_PROMPT,
"startSessionMode": settings.S2S_START_SESSION_MODE,
"theme": settings.S2S_THEME,
"apipilot": bool(settings.S2S_APIPILOT_TOOLS_URL),
}
app_logging.logger.debug(
"[INTERNAL] /api/config returned promptLen=%d reasoning=%s startSessionMode=%s theme=%s apipilot=%s",
len(primary_prompt),
settings.S2S_REASONING_TYPE,
settings.S2S_START_SESSION_MODE or "-",
settings.S2S_THEME or "-",
out["apipilot"],
)
return out