Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Pytest marks warnings as errors; update fixtures or add targeted `filterwarnings
## WhatsApp & Admin Endpoints
- **Webhook:** `POST /meta-whatsapp` (signature verification + LangGraph processing). Verification handshake uses `GET /meta-whatsapp`.
- **Progress messaging:** Status texts sourced from `bt_servant_engine.services.status_messages`.
- **Admin API:** See `bt_servant_engine.apps.api.routes.admin` for vector store maintenance (collection merges, document management) secured via bearer token headers when `ENABLE_ADMIN_AUTH=True`. Cache controls are exposed here as well:
- **Admin API:** See `bt_servant_engine.apps.api.routes.admin_datastore` for vector store maintenance (collection merges, document management) secured via bearer token headers when `ENABLE_ADMIN_AUTH=True`. Cache controls are exposed here as well:
- `POST /cache/clear` wipes every cache namespace.
- `POST /cache/{name}/clear` clears an individual cache (e.g., `passage_summary`).
- `GET /cache/stats` reports global cache settings, hit/miss counters, and disk usage.
Expand Down
4 changes: 2 additions & 2 deletions bt_servant_engine/apps/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fastapi import FastAPI

from bt_servant_engine.apps.api.middleware import CorrelationIdMiddleware
from bt_servant_engine.apps.api.routes import admin, admin_logs, health, webhooks
from bt_servant_engine.apps.api.routes import admin_datastore, admin_logs, health, webhooks
from bt_servant_engine.core.logging import get_logger
from bt_servant_engine.services.brain_orchestrator import create_brain
from bt_servant_engine.services import ServiceContainer
Expand Down Expand Up @@ -51,7 +51,7 @@ def create_app(services: ServiceContainer | None = None) -> FastAPI:

app.include_router(health.router)
app.include_router(admin_logs.router)
app.include_router(admin.router)
app.include_router(admin_datastore.router)
app.include_router(webhooks.router)
return app

Expand Down
36 changes: 33 additions & 3 deletions bt_servant_engine/apps/api/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Shared FastAPI dependencies for token validation."""
"""Shared FastAPI dependencies for token validation and service access."""

import hmac
from typing import Annotated, Optional

from fastapi import Header, HTTPException, status
from fastapi import Depends, Header, HTTPException, status

from bt_servant_engine.core.config import config
from bt_servant_engine.services import ServiceContainer, runtime
from bt_servant_engine.services.admin import AdminDatastoreService


async def _validate_token(
Expand Down Expand Up @@ -70,4 +72,32 @@ async def require_healthcheck_token(
)


__all__ = ["require_admin_token", "require_healthcheck_token"]
def get_service_container() -> ServiceContainer:
"""Resolve the globally configured service container."""
try:
return runtime.get_services()
except RuntimeError as exc:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Service container not configured",
) from exc


def get_admin_datastore_service(
container: Annotated[ServiceContainer, Depends(get_service_container)],
) -> AdminDatastoreService:
"""Return an admin datastore service bound to the active container."""
if container.chroma is None:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Chroma service is unavailable",
)
return AdminDatastoreService(container.chroma)


__all__ = [
"get_admin_datastore_service",
"get_service_container",
"require_admin_token",
"require_healthcheck_token",
]
4 changes: 2 additions & 2 deletions bt_servant_engine/apps/api/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Router namespace exports for FastAPI include hooks."""

from . import admin, health, webhooks
from . import admin_datastore, admin_logs, health, webhooks

__all__ = ["admin", "health", "webhooks"]
__all__ = ["admin_datastore", "admin_logs", "health", "webhooks"]
Loading