From 119f6ecc511f43bfdf0c971173f79c6f5398a7bf Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 12 Dec 2025 14:53:53 +0000 Subject: [PATCH] feat(frontend): Add AI intelligence API types and methods Add TypeScript types and API methods for AI intelligence data: Types (aiIntelligence.ts): - FailurePattern - Detected recurring patterns - FailurePrediction - Predicted failures with confidence - ResourceCorrelation - Detected resource dependencies - InfrastructureChange - Recent config/state changes - ResourceBaseline - Learned normal behavior baselines API Methods (ai.ts): - getPatterns(resourceId?) - Fetch failure patterns - getPredictions(resourceId?) - Fetch failure predictions - getCorrelations(resourceId?) - Fetch resource correlations - getRecentChanges(hours?) - Fetch infrastructure changes - getBaselines(resourceId?) - Fetch learned baselines All methods support optional resource_id filtering. --- frontend-modern/src/api/ai.ts | 41 ++++++++++ frontend-modern/src/types/aiIntelligence.ts | 88 +++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 frontend-modern/src/types/aiIntelligence.ts diff --git a/frontend-modern/src/api/ai.ts b/frontend-modern/src/api/ai.ts index 415d3f1..d7060f2 100644 --- a/frontend-modern/src/api/ai.ts +++ b/frontend-modern/src/api/ai.ts @@ -9,6 +9,13 @@ import type { AIStreamEvent, AICostSummary, } from '@/types/ai'; +import type { + PatternsResponse, + PredictionsResponse, + CorrelationsResponse, + ChangesResponse, + BaselinesResponse, +} from '@/types/aiIntelligence'; export class AIAPI { private static baseUrl = '/api'; @@ -62,6 +69,40 @@ export class AIAPI { return apiFetch(`${this.baseUrl}/ai/cost/export?days=${days}&format=${format}`, { method: 'GET' }); } + // ============================================ + // AI Intelligence API - Patterns, Predictions, Correlations + // ============================================ + + // Get detected failure patterns + static async getPatterns(resourceId?: string): Promise { + const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : ''; + return apiFetchJSON(`${this.baseUrl}/ai/intelligence/patterns${params}`) as Promise; + } + + // Get failure predictions + static async getPredictions(resourceId?: string): Promise { + const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : ''; + return apiFetchJSON(`${this.baseUrl}/ai/intelligence/predictions${params}`) as Promise; + } + + // Get resource correlations + static async getCorrelations(resourceId?: string): Promise { + const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : ''; + return apiFetchJSON(`${this.baseUrl}/ai/intelligence/correlations${params}`) as Promise; + } + + // Get recent infrastructure changes + static async getRecentChanges(hours = 24): Promise { + return apiFetchJSON(`${this.baseUrl}/ai/intelligence/changes?hours=${hours}`) as Promise; + } + + // Get learned baselines + static async getBaselines(resourceId?: string): Promise { + const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : ''; + return apiFetchJSON(`${this.baseUrl}/ai/intelligence/baselines${params}`) as Promise; + } + + // Start OAuth flow for Claude Pro/Max subscription // Returns the authorization URL to redirect the user to static async startOAuth(): Promise<{ auth_url: string; state: string }> { diff --git a/frontend-modern/src/types/aiIntelligence.ts b/frontend-modern/src/types/aiIntelligence.ts new file mode 100644 index 0000000..0b385f8 --- /dev/null +++ b/frontend-modern/src/types/aiIntelligence.ts @@ -0,0 +1,88 @@ +// AI Intelligence types for patterns, predictions, and correlations + +export interface FailurePattern { + key: string; + resource_id: string; + event_type: string; + occurrences: number; + average_interval: string; + average_duration: string; + last_occurrence: string; + confidence: number; +} + +export interface FailurePrediction { + resource_id: string; + event_type: string; + predicted_at: string; + days_until: number; + confidence: number; + basis: string; + is_overdue: boolean; +} + +export interface ResourceCorrelation { + source_id: string; + source_name: string; + source_type: string; + target_id: string; + target_name: string; + target_type: string; + event_pattern: string; + occurrences: number; + avg_delay: string; + confidence: number; + last_seen: string; + description: string; +} + +export interface InfrastructureChange { + id: string; + resource_id: string; + resource_name: string; + resource_type: string; + change_type: string; + before: unknown; + after: unknown; + detected_at: string; + description: string; +} + +export interface ResourceBaseline { + key: string; + resource_id: string; + metric: string; + mean: number; + std_dev: number; + min: number; + max: number; + samples: number; + last_update: string; +} + +// API response types +export interface PatternsResponse { + patterns: FailurePattern[]; + count: number; +} + +export interface PredictionsResponse { + predictions: FailurePrediction[]; + count: number; +} + +export interface CorrelationsResponse { + correlations: ResourceCorrelation[]; + count: number; +} + +export interface ChangesResponse { + changes: InfrastructureChange[]; + count: number; + hours: number; +} + +export interface BaselinesResponse { + baselines: ResourceBaseline[]; + count: number; +}