Spaces:
Running
Running
| from __future__ import annotations | |
| from fastapi import APIRouter, Depends, Query | |
| from sqlalchemy.orm import Session | |
| from app.core.config import get_settings | |
| from app.core.database import get_db | |
| from app.runtime.facade import BlumRuntimeFacade | |
| from app.services.central_brain_runtime import CentralBrainRuntime, LearningHealthService, SnapshotProducerService, SnapshotWatchdogService | |
| from app.services.dashboard_snapshots import DashboardSnapshotService | |
| from app.services.learning_summary import LearningSummaryService | |
| settings = get_settings() | |
| router = APIRouter(tags=["Runtime"]) | |
| def brain_runtime_state(db: Session = Depends(get_db)) -> dict: | |
| return CentralBrainRuntime().state(db) | |
| def engine_status(db: Session = Depends(get_db)) -> dict: | |
| from app.engine.facade import BlumEngineFacade | |
| return BlumEngineFacade().status(db) | |
| def engine_contracts() -> dict: | |
| from app.engine.facade import BlumEngineFacade | |
| return BlumEngineFacade().contract() | |
| def engine_agents( | |
| agent: list[str] | None = Query(default=None), | |
| limit: int = Query(default=8, ge=1, le=20), | |
| db: Session = Depends(get_db), | |
| ) -> dict: | |
| from app.engine.facade import BlumEngineFacade | |
| return BlumEngineFacade().agent_evidence(db, agents=agent, limit=limit) | |
| def runtime_status(db: Session = Depends(get_db)) -> dict: | |
| return BlumRuntimeFacade().status(db) | |
| def runtime_contracts() -> dict: | |
| return BlumRuntimeFacade().contract() | |
| def snapshots_health(db: Session = Depends(get_db)) -> dict: | |
| return SnapshotWatchdogService().health(db, queue_rebuild=False) | |
| def snapshots_produce( | |
| snapshot_type: str | None = Query(default=None), | |
| max_items: int = Query(default=settings.blum_autonomous_max_items_per_job, ge=1, le=50), | |
| db: Session = Depends(get_db), | |
| ) -> dict: | |
| if snapshot_type: | |
| return SnapshotProducerService().produce(db, snapshot_type) | |
| return SnapshotProducerService().produce_many(db, max_items=max_items) | |
| def learning_health(db: Session = Depends(get_db)) -> dict: | |
| snapshot_health = SnapshotWatchdogService().health(db, queue_rebuild=False) | |
| return LearningHealthService().health(db, snapshot_health=snapshot_health) | |
| def learning_intelligence_summary(db: Session = Depends(get_db)) -> dict: | |
| return LearningSummaryService().summary(db) | |
| def dashboard_snapshot(snapshot_type: str, db: Session = Depends(get_db)) -> dict: | |
| return DashboardSnapshotService().latest(db, snapshot_type=snapshot_type) | |