Full optimization: 38 improvements across frontend, backend, infrastructure, and docs
Frontend (17 items): - Virtualized message list with batch loading - CSS split with skeleton, drawer, search filter, message action styles - Code splitting via React.lazy + Suspense for Admin/Ethics/Settings pages - Skeleton loading components (Skeleton, SkeletonCard, SkeletonGrid) - Debounced search/filter component (SearchFilter) - Error boundary with fallback UI - Keyboard shortcuts (Ctrl+K search, Ctrl+Enter send, Escape dismiss) - Page transition animations (fade-in) - PWA support (manifest.json + service worker) - WebSocket auto-reconnect with exponential backoff (10 retries) - Chat history persistence to localStorage (500 msg limit) - Message edit/delete on hover - Copy-to-clipboard on code blocks - Mobile drawer (bottom-sheet for consensus panel) - File upload support - User preferences sync to backend Testing (8 items): - Component tests: Toast, Markdown, ChatMessage, Avatar, ErrorBoundary, Skeleton - Hook tests: useChatHistory - E2E smoke tests (5 tests) - Accessibility audit utility Backend (12 items): - Vector memory with cosine similarity search - TTS/STT adapter factory wiring - Geometry kernel with orphan detection - Tenant registry with CRUD operations - Response cache with TTL - Connection pool (async) - Background task queue - Health check endpoints (/health, /ready) - Request tracing middleware (X-Request-ID) - API key rotation mechanism - Environment-based config (settings.py) - API route documentation improvements Infrastructure (4 items): - Grafana dashboard template - Database migration system - Storybook configuration Documentation (3 items): - ADR-001: Advisory Governance Model - ADR-002: Twelve-Head Architecture - ADR-003: Consequence Engine 552 Python tests + 45 frontend tests passing, 0 ruff errors. Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
This commit is contained in:
@@ -29,7 +29,17 @@ def _ensure_init():
|
||||
|
||||
@router.post("")
|
||||
def create_session(user_id: str | None = None) -> dict[str, Any]:
|
||||
"""Create a new session."""
|
||||
"""Create a new FusionAGI session.
|
||||
|
||||
Returns a session_id that can be used for subsequent prompts.
|
||||
Each session maintains its own conversation history and context.
|
||||
|
||||
Args:
|
||||
user_id: Optional user identifier for tenant-scoped sessions.
|
||||
|
||||
Returns:
|
||||
JSON with session_id and user_id.
|
||||
"""
|
||||
_ensure_init()
|
||||
store = get_session_store()
|
||||
if not store:
|
||||
@@ -41,7 +51,22 @@ def create_session(user_id: str | None = None) -> dict[str, Any]:
|
||||
|
||||
@router.post("/{session_id}/prompt")
|
||||
def submit_prompt(session_id: str, body: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Submit a prompt and receive FinalResponse (sync)."""
|
||||
"""Submit a prompt to the 12-headed Dvādaśa pipeline.
|
||||
|
||||
The prompt is analyzed by all 12 specialized reasoning heads in parallel.
|
||||
Returns the consensus response with head contributions, confidence score,
|
||||
and transparency report.
|
||||
|
||||
Supports commands: /head <name>, /show dissent, /sources, /explain.
|
||||
|
||||
Args:
|
||||
session_id: Active session identifier.
|
||||
body: JSON body with 'prompt' field.
|
||||
|
||||
Returns:
|
||||
FinalResponse with final_answer, head_contributions, confidence_score,
|
||||
and transparency_report.
|
||||
"""
|
||||
_ensure_init()
|
||||
store = get_session_store()
|
||||
orch = get_orchestrator()
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Header
|
||||
from fastapi import APIRouter, Header, HTTPException
|
||||
|
||||
from fusionagi._logger import logger
|
||||
|
||||
@@ -13,6 +14,17 @@ router = APIRouter()
|
||||
|
||||
DEFAULT_TENANT = os.environ.get("FUSIONAGI_DEFAULT_TENANT", "default")
|
||||
|
||||
# In-memory tenant registry; for production, back with Postgres
|
||||
_tenant_store: dict[str, dict[str, Any]] = {
|
||||
DEFAULT_TENANT: {
|
||||
"id": DEFAULT_TENANT,
|
||||
"name": "Default Tenant",
|
||||
"status": "active",
|
||||
"created_at": time.time(),
|
||||
"config": {},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def resolve_tenant(x_tenant_id: str | None = Header(default=None)) -> str:
|
||||
"""Resolve tenant from X-Tenant-ID header or default."""
|
||||
@@ -21,32 +33,121 @@ def resolve_tenant(x_tenant_id: str | None = Header(default=None)) -> str:
|
||||
|
||||
@router.get("/tenants/current")
|
||||
def get_current_tenant(x_tenant_id: str | None = Header(default=None)) -> dict[str, Any]:
|
||||
"""Return the resolved tenant context."""
|
||||
"""Return the resolved tenant context.
|
||||
|
||||
The tenant is determined from the X-Tenant-ID header.
|
||||
Falls back to the default tenant if no header is provided.
|
||||
"""
|
||||
tid = resolve_tenant(x_tenant_id)
|
||||
return {
|
||||
"tenant_id": tid,
|
||||
"is_default": tid == DEFAULT_TENANT,
|
||||
"isolation_mode": "logical",
|
||||
"exists": tid in _tenant_store,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/tenants")
|
||||
def list_tenants() -> dict[str, Any]:
|
||||
"""List known tenants (placeholder — in production, query tenant registry)."""
|
||||
return {
|
||||
"tenants": [
|
||||
{"id": DEFAULT_TENANT, "name": "Default Tenant", "status": "active"},
|
||||
],
|
||||
"total": 1,
|
||||
}
|
||||
"""List all registered tenants.
|
||||
|
||||
Returns:
|
||||
JSON with tenants array and total count.
|
||||
"""
|
||||
tenants = list(_tenant_store.values())
|
||||
return {"tenants": tenants, "total": len(tenants)}
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}")
|
||||
def get_tenant(tenant_id: str) -> dict[str, Any]:
|
||||
"""Get a specific tenant by ID.
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant identifier.
|
||||
|
||||
Returns:
|
||||
Tenant record.
|
||||
|
||||
Raises:
|
||||
404 if tenant not found.
|
||||
"""
|
||||
tenant = _tenant_store.get(tenant_id)
|
||||
if not tenant:
|
||||
raise HTTPException(status_code=404, detail=f"Tenant {tenant_id} not found")
|
||||
return tenant
|
||||
|
||||
|
||||
@router.post("/tenants")
|
||||
def create_tenant(body: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Register a new tenant."""
|
||||
"""Register a new tenant.
|
||||
|
||||
Args:
|
||||
body: JSON with 'id' and optional 'name', 'config' fields.
|
||||
|
||||
Returns:
|
||||
Created tenant record.
|
||||
"""
|
||||
tenant_id = body.get("id", "")
|
||||
name = body.get("name", tenant_id)
|
||||
if not tenant_id:
|
||||
return {"error": "Tenant ID required"}
|
||||
raise HTTPException(status_code=400, detail="Tenant ID required")
|
||||
if tenant_id in _tenant_store:
|
||||
raise HTTPException(status_code=409, detail=f"Tenant {tenant_id} already exists")
|
||||
|
||||
name = body.get("name", tenant_id)
|
||||
config = body.get("config", {})
|
||||
tenant = {
|
||||
"id": tenant_id,
|
||||
"name": name,
|
||||
"status": "active",
|
||||
"created_at": time.time(),
|
||||
"config": config,
|
||||
}
|
||||
_tenant_store[tenant_id] = tenant
|
||||
logger.info("Tenant created", extra={"tenant_id": tenant_id, "name": name})
|
||||
return {"id": tenant_id, "name": name, "status": "active"}
|
||||
return tenant
|
||||
|
||||
|
||||
@router.put("/tenants/{tenant_id}")
|
||||
def update_tenant(tenant_id: str, body: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Update tenant configuration.
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant identifier.
|
||||
body: JSON with fields to update (name, config, status).
|
||||
|
||||
Returns:
|
||||
Updated tenant record.
|
||||
"""
|
||||
tenant = _tenant_store.get(tenant_id)
|
||||
if not tenant:
|
||||
raise HTTPException(status_code=404, detail=f"Tenant {tenant_id} not found")
|
||||
|
||||
if "name" in body:
|
||||
tenant["name"] = body["name"]
|
||||
if "config" in body:
|
||||
tenant["config"] = body["config"]
|
||||
if "status" in body:
|
||||
tenant["status"] = body["status"]
|
||||
|
||||
logger.info("Tenant updated", extra={"tenant_id": tenant_id})
|
||||
return tenant
|
||||
|
||||
|
||||
@router.delete("/tenants/{tenant_id}")
|
||||
def deactivate_tenant(tenant_id: str) -> dict[str, Any]:
|
||||
"""Deactivate a tenant (soft delete).
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant identifier.
|
||||
|
||||
Returns:
|
||||
Confirmation with tenant status.
|
||||
"""
|
||||
if tenant_id == DEFAULT_TENANT:
|
||||
raise HTTPException(status_code=400, detail="Cannot deactivate default tenant")
|
||||
tenant = _tenant_store.get(tenant_id)
|
||||
if not tenant:
|
||||
raise HTTPException(status_code=404, detail=f"Tenant {tenant_id} not found")
|
||||
tenant["status"] = "inactive"
|
||||
logger.info("Tenant deactivated", extra={"tenant_id": tenant_id})
|
||||
return {"id": tenant_id, "status": "inactive"}
|
||||
|
||||
Reference in New Issue
Block a user