feat(core-api): add AI stats widget with proxy endpoints
Implements Phase 2 of AI performance monitoring - creating a visual
dashboard widget for Organizr to display real-time AI metrics.
New Components:
- src/clients/ai_client.py: HTTP client for Core-AI service
- Async HTTP requests to core-ai:8086
- Fetches metrics, errors, and tool failures
- Health check and metrics reset operations
- src/controllers/ai_controller.py: Proxy controller for AI metrics
- GET /ai/health - Core-AI health check
- GET /ai/metrics - Comprehensive performance metrics (proxied)
- GET /ai/metrics/errors - Recent request errors (proxied)
- GET /ai/metrics/tool-failures - Tool execution failures (proxied)
- POST /ai/metrics/reset - Reset all metrics (admin)
- static/widgets/ai-stats.html: Performance dashboard widget
- 4-panel grid layout: Agent, Tools, Memory, Health
- Real-time metrics with 10-second auto-refresh
- Color-coded performance indicators (excellent/good/warning/critical)
- Response time thresholds: <1s excellent, <3s good, <10s warning
- Success rate thresholds: >99% excellent, >95% good, >90% warning
- Top 5 tools display with call counts and success rates
- Transparent background for Organizr dark theme
- Responsive design with mobile support
Configuration:
- src/config.py: Added core_ai_base_url setting
- src/main.py: Registered ai_router for /ai/* endpoints
Architecture:
┌─────────────────────────────────────────────┐
│ Browser (Organizr iFrame) │
│ ↓ Fetches /ai/metrics │
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ core-api:8083 (api.schweitz.net) │
│ - Serves widget HTML │
│ - Proxies metrics requests │
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ core-ai:8086 (internal) │
│ - Collects metrics │
│ - Returns JSON data │
└─────────────────────────────────────────────┘
Benefits:
- External access via api.schweitz.net (proxy approach)
- No CORS issues (same-origin requests)
- Core-AI remains internal-only
- Single integration point with Organizr
Integration with Organizr:
1. Go to Settings → Customize → Homepage Items
2. Add New Item:
- Name: "AI Performance Stats"
- Type: iFrame
- URL: http://localhost:8083/static/widgets/ai-stats.html
- Authentication: User
3. Position widget on dashboard
Tested:
✅ Proxy endpoints responding correctly
✅ Widget accessible via /static/widgets/
✅ Metrics data flowing from core-ai → core-api → browser
✅ Color coding and formatting working
✅ Auto-refresh functional
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>