/** * Platform API hooks — Phase I.6/I.7 (I-ONB, I-DASH, I-COST, I-USE). * * Provides hooks for the setup wizard (onboarding) and the platform dashboard * (agent status, workflow stats, search metrics, knowledge coverage, cost * tracking, system health). Backend routes may not be wired yet, so all hooks * degrade gracefully to an "unavailable" state instead of throwing. */ import { useQuery } from '@tanstack/react-query'; import { apiGet } from './client'; // ── Onboarding ────────────────────────────────────────────────────────────── export interface OnboardingStepStatus { completed: boolean; required: boolean; } export interface OnboardingStatus { steps: Record; progress_pct: number; } export interface OnboardingGuideStep { id: string; title: string; description: string; icon?: string; action_url?: string; } export interface OnboardingGuide { steps: OnboardingGuideStep[]; } export function useOnboardingStatus() { return useQuery({ queryKey: ['onboardingStatus'], queryFn: () => apiGet('/onboarding/status'), staleTime: 60 * 1000, retry: false, }); } export function useOnboardingGuide() { return useQuery({ queryKey: ['onboardingGuide'], queryFn: () => apiGet('/onboarding/guide'), staleTime: 60 * 1000, retry: false, }); } // ── Platform dashboard ────────────────────────────────────────────────────── export interface PlatformDashboardData { agents?: { active_agents?: number; total_runs?: number; recent_runs_7d?: number; error?: string; }; workflows?: { active_workflows?: number; running_instances?: number; completed_instances?: number; error?: string; }; search?: { total_queries?: number; avg_latency_ms?: number; error?: string; }; knowledge?: { wiki_articles?: number; coverage_pct?: number; error?: string; }; workstream?: { messages?: number; error?: string; }; system_health?: { redis?: string; status?: string; error?: string; }; generated_at?: string; } export function usePlatformDashboard() { return useQuery({ queryKey: ['platformDashboard'], queryFn: () => apiGet('/dashboard/platform'), staleTime: 60 * 1000, retry: false, }); } // ── Cost tracking ─────────────────────────────────────────────────────────── export interface CostDashboardData { period_days?: number; total_cost_usd?: number; by_agent?: Record; budget?: { monthly_limit_usd?: number; utilization_pct?: number; }; error?: string; } export function useCostDashboard(days = 30) { return useQuery({ queryKey: ['costDashboard', days], queryFn: () => apiGet(`/dashboard/cost?days=${days}`), staleTime: 60 * 1000, retry: false, }); } // ── Usage analytics ───────────────────────────────────────────────────────── export interface UsageAnalyticsData { period_days?: number; agent_runs?: { total?: number; completed?: number; failed?: number; success_rate?: number; error?: string; }; workflow_executions?: { total?: number; completed?: number; error?: string; }; search_queries?: { total?: number; error?: string; }; error?: string; } export function useUsageAnalytics(days = 30) { return useQuery({ queryKey: ['usageAnalytics', days], queryFn: () => apiGet(`/dashboard/usage?days=${days}`), staleTime: 60 * 1000, retry: false, }); }