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>
101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
"""Backup/restore endpoints for PersistentLearningStore and state data."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import shutil
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import FileResponse
|
|
|
|
from fusionagi._logger import logger
|
|
|
|
router = APIRouter()
|
|
|
|
BACKUP_DIR = Path("backups")
|
|
|
|
|
|
@router.post("/backup")
|
|
def create_backup(body: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
"""Create a backup of learning data and state."""
|
|
BACKUP_DIR.mkdir(parents=True, exist_ok=True)
|
|
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
|
|
backup_id = f"backup_{timestamp}"
|
|
backup_path = BACKUP_DIR / backup_id
|
|
|
|
backup_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Backup PersistentLearningStore
|
|
learning_store_path = Path("data/learning_store.json")
|
|
if learning_store_path.exists():
|
|
shutil.copy2(learning_store_path, backup_path / "learning_store.json")
|
|
|
|
# Backup state files
|
|
state_path = Path("data/state.json")
|
|
if state_path.exists():
|
|
shutil.copy2(state_path, backup_path / "state.json")
|
|
|
|
# Write manifest
|
|
manifest = {
|
|
"backup_id": backup_id,
|
|
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
"files": [f.name for f in backup_path.iterdir() if f.is_file()],
|
|
}
|
|
(backup_path / "manifest.json").write_text(json.dumps(manifest, indent=2))
|
|
|
|
logger.info("Backup created", extra={"backup_id": backup_id, "path": str(backup_path)})
|
|
return manifest
|
|
|
|
|
|
@router.get("/backups")
|
|
def list_backups() -> dict[str, Any]:
|
|
"""List available backups."""
|
|
if not BACKUP_DIR.exists():
|
|
return {"backups": []}
|
|
|
|
backups = []
|
|
for d in sorted(BACKUP_DIR.iterdir(), reverse=True):
|
|
if d.is_dir():
|
|
manifest_path = d / "manifest.json"
|
|
if manifest_path.exists():
|
|
manifest = json.loads(manifest_path.read_text())
|
|
backups.append(manifest)
|
|
else:
|
|
backups.append({"backup_id": d.name, "files": []})
|
|
return {"backups": backups}
|
|
|
|
|
|
@router.post("/restore/{backup_id}")
|
|
def restore_backup(backup_id: str) -> dict[str, Any]:
|
|
"""Restore data from a backup."""
|
|
backup_path = BACKUP_DIR / backup_id
|
|
if not backup_path.exists():
|
|
return {"error": f"Backup not found: {backup_id}"}
|
|
|
|
data_dir = Path("data")
|
|
data_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
restored = []
|
|
for f in backup_path.iterdir():
|
|
if f.is_file() and f.name != "manifest.json":
|
|
shutil.copy2(f, data_dir / f.name)
|
|
restored.append(f.name)
|
|
|
|
logger.info("Backup restored", extra={"backup_id": backup_id, "files": restored})
|
|
return {"backup_id": backup_id, "restored_files": restored, "status": "ok"}
|
|
|
|
|
|
@router.get("/backup/{backup_id}/download")
|
|
def download_backup(backup_id: str) -> Any:
|
|
"""Download a backup as a zip archive."""
|
|
backup_path = BACKUP_DIR / backup_id
|
|
if not backup_path.exists():
|
|
return {"error": f"Backup not found: {backup_id}"}
|
|
|
|
zip_path = BACKUP_DIR / f"{backup_id}.zip"
|
|
shutil.make_archive(str(zip_path.with_suffix("")), "zip", str(backup_path))
|
|
return FileResponse(str(zip_path), media_type="application/zip", filename=f"{backup_id}.zip")
|