artifacts-dashboard/backend/app/api/dashboard.py
Paweł Orzech 75313b83c0
Add multi-user workflows/pipelines and error tracking
Add multi-user automation features and per-user error tracking.

- Database migrations: add workflow_configs/workflow_runs (004), app_errors (005), pipeline_configs/pipeline_runs (006), and add user_token_hash to app_errors (007).
- Backend: introduce per-request token handling (X-API-Token) via app.api.deps and update many API routes (auth, automations, bank, characters, dashboard, events, exchange, logs) to use user-scoped Artifacts client and character scoping. Auth endpoints no longer store tokens server-side (validate-only); clear is a no-op on server.
- New Errors API and services: endpoint to list, filter, resolve, and report errors scoped to the requesting user; add error models, schemas, middleware/error handler and error_service for recording/hashing tokens.
- Pipelines & Workflows: add API routers, models, schemas and engine modules (pipeline/worker/coordinator, workflow runner/conditions) and action_executor updates to support workflow/pipeline execution.
- Logs: logs endpoint now prefers fetching recent action logs from the game API (with fallback to local DB), supports paging and filtering, and scopes results to the user.
- Frontend: add pipeline/workflow builders, lists, progress components and hooks (use-errors, use-pipelines, use-workflows), sentry client config, and updates to API client/constants/types.
- Misc: add middleware error handler, various engine strategy tweaks, tests adjusted.

Overall this change enables per-user API tokens, scopes DB queries to each user, introduces pipelines/workflows runtime support, and centralizes application error tracking.
2026-03-01 23:02:34 +01:00

44 lines
1.4 KiB
Python

import logging
from fastapi import APIRouter, HTTPException, Request
from httpx import HTTPStatusError
from app.api.deps import get_user_client
from app.schemas.game import DashboardData
from app.services.character_service import CharacterService
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api", tags=["dashboard"])
def _get_service(request: Request) -> CharacterService:
return request.app.state.character_service
@router.get("/dashboard", response_model=DashboardData)
async def get_dashboard(request: Request) -> DashboardData:
"""Return aggregated dashboard data: all characters + server status."""
client = get_user_client(request)
service = _get_service(request)
try:
characters = await service.get_all(client)
except HTTPStatusError as exc:
raise HTTPException(
status_code=exc.response.status_code,
detail=f"Artifacts API error: {exc.response.text}",
) from exc
# Server status could be extended later (e.g., ping, event info)
server_status: dict | None = None
try:
events = await client.get_events()
server_status = {"events": events}
except Exception:
logger.warning("Failed to fetch server events for dashboard", exc_info=True)
return DashboardData(
characters=characters,
server_status=server_status,
)