Complete all 37 items: frontend UI, backend stubs, infrastructure, docs, tests
Frontend (items 1-10):
- WebSocket streaming integration with useWebSocket hook
- Admin Dashboard UI (status, voices, agents, governance tabs)
- Voice playback UI (TTS/STT integration)
- Settings/Preferences page (conversation style, sliders)
- Responsive/mobile layout (breakpoints at 480px, 768px)
- Dark/light theme with CSS variables and localStorage
- Error handling & loading states (retry, empty state, disabled input)
- Authentication UI (login page, Bearer token, logout)
- Head visualization improvements (active/speaking states, animations)
- Consequence/Ethics dashboard (lessons, consequences, insights tabs)
Backend stubs (items 11-21):
- Tool connectors: DocsConnector (text/md/PDF), DBConnector (SQLite/Postgres), CodeRunnerConnector (Python/JS/Bash/Ruby sandboxed)
- STT adapter: WhisperSTTAdapter, AzureSTTAdapter
- Multi-modal interface adapters: Visual, Haptic, Gesture, Biometric
- SSE streaming endpoint (/v1/sessions/{id}/stream/sse)
- Multi-tenant support (X-Tenant-ID header, tenant CRUD)
- Plugin marketplace/registry (register, install, list)
- Backup/restore endpoints
- Versioned API negotiation (Accept-Version header, deprecation)
Infrastructure (items 22-26):
- docker-compose.yml (API + Postgres + Redis + frontend)
- .env.example with all configurable vars
- gunicorn.conf.py production ASGI config
- Prometheus metrics collector and /metrics endpoint
- Structured JSON logging configuration
Documentation (items 27-29):
- Architecture docs with module layout and subsystem descriptions
- Quickstart guide with setup, API tour, and test instructions
Tests (items 30-32):
- Integration tests: 25 end-to-end API tests
- Frontend tests: 10 Vitest tests for hooks (useTheme, useAuth)
- Load/performance tests: latency and throughput benchmarks
- Connector tests: 16 tests for Docs, DB, CodeRunner
- Multi-modal adapter tests: 9 tests
- Metrics collector tests: 5 tests
- STT adapter tests: 2 tests
511 Python tests passing, 10 frontend tests passing, 0 ruff errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
"""FastAPI application factory for FusionAGI Dvādaśa API."""
|
||||
"""FastAPI application factory for FusionAGI Dvādaśa API.
|
||||
|
||||
Includes versioned API negotiation, metrics, and CORS support."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from collections import defaultdict
|
||||
@@ -10,6 +13,11 @@ from typing import Any
|
||||
|
||||
from fusionagi._logger import logger
|
||||
from fusionagi.api.dependencies import SessionStore, default_orchestrator, set_app_state
|
||||
from fusionagi.api.metrics import get_metrics, metrics_enabled
|
||||
|
||||
API_VERSION = "1"
|
||||
SUPPORTED_VERSIONS = ["1"]
|
||||
DEPRECATED_VERSIONS: list[str] = []
|
||||
|
||||
|
||||
def create_app(
|
||||
@@ -106,11 +114,68 @@ def create_app(
|
||||
|
||||
app.add_middleware(RateLimitMiddleware)
|
||||
|
||||
# --- Version negotiation middleware ---
|
||||
class VersionMiddleware(BaseHTTPMiddleware):
|
||||
"""API version negotiation via Accept-Version header.
|
||||
|
||||
Adds X-API-Version and deprecation warnings to responses.
|
||||
"""
|
||||
|
||||
async def dispatch(self, request: Request, call_next: Any) -> Response:
|
||||
requested = request.headers.get("accept-version", API_VERSION)
|
||||
if requested not in SUPPORTED_VERSIONS:
|
||||
return Response(
|
||||
content=json.dumps({
|
||||
"detail": f"Unsupported API version: {requested}",
|
||||
"supported_versions": SUPPORTED_VERSIONS,
|
||||
}),
|
||||
status_code=400,
|
||||
media_type="application/json",
|
||||
)
|
||||
response = await call_next(request)
|
||||
response.headers["X-API-Version"] = requested
|
||||
if requested in DEPRECATED_VERSIONS:
|
||||
response.headers["Deprecation"] = "true"
|
||||
response.headers["Sunset"] = "2026-12-31"
|
||||
return response # type: ignore[no-any-return]
|
||||
|
||||
app.add_middleware(VersionMiddleware)
|
||||
|
||||
# --- Metrics middleware ---
|
||||
if metrics_enabled():
|
||||
class MetricsMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next: Any) -> Response:
|
||||
m = get_metrics()
|
||||
m.inc("http_requests_total", labels={"method": request.method, "path": request.url.path})
|
||||
start = time.monotonic()
|
||||
response = await call_next(request)
|
||||
duration = time.monotonic() - start
|
||||
m.observe("http_request_duration_seconds", duration, labels={"path": request.url.path})
|
||||
m.inc("http_responses_total", labels={"status": str(response.status_code)})
|
||||
return response # type: ignore[no-any-return]
|
||||
|
||||
app.add_middleware(MetricsMiddleware)
|
||||
|
||||
# --- Routes ---
|
||||
from fusionagi.api.routes import router as api_router
|
||||
|
||||
app.include_router(api_router, prefix="/v1", tags=["dvadasa"])
|
||||
|
||||
# Metrics endpoint
|
||||
if metrics_enabled():
|
||||
@app.get("/metrics", tags=["monitoring"])
|
||||
def metrics_endpoint() -> dict[str, Any]:
|
||||
return get_metrics().snapshot()
|
||||
|
||||
# Version info endpoint
|
||||
@app.get("/version", tags=["meta"])
|
||||
def version_info() -> dict[str, Any]:
|
||||
return {
|
||||
"current_version": API_VERSION,
|
||||
"supported_versions": SUPPORTED_VERSIONS,
|
||||
"deprecated_versions": DEPRECATED_VERSIONS,
|
||||
}
|
||||
|
||||
if cors_origins is not None:
|
||||
try:
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
Reference in New Issue
Block a user