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.
This commit is contained in:
parent
7fc705ba07
commit
119f6ecc51
2 changed files with 129 additions and 0 deletions
|
|
@ -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<PatternsResponse> {
|
||||
const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : '';
|
||||
return apiFetchJSON(`${this.baseUrl}/ai/intelligence/patterns${params}`) as Promise<PatternsResponse>;
|
||||
}
|
||||
|
||||
// Get failure predictions
|
||||
static async getPredictions(resourceId?: string): Promise<PredictionsResponse> {
|
||||
const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : '';
|
||||
return apiFetchJSON(`${this.baseUrl}/ai/intelligence/predictions${params}`) as Promise<PredictionsResponse>;
|
||||
}
|
||||
|
||||
// Get resource correlations
|
||||
static async getCorrelations(resourceId?: string): Promise<CorrelationsResponse> {
|
||||
const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : '';
|
||||
return apiFetchJSON(`${this.baseUrl}/ai/intelligence/correlations${params}`) as Promise<CorrelationsResponse>;
|
||||
}
|
||||
|
||||
// Get recent infrastructure changes
|
||||
static async getRecentChanges(hours = 24): Promise<ChangesResponse> {
|
||||
return apiFetchJSON(`${this.baseUrl}/ai/intelligence/changes?hours=${hours}`) as Promise<ChangesResponse>;
|
||||
}
|
||||
|
||||
// Get learned baselines
|
||||
static async getBaselines(resourceId?: string): Promise<BaselinesResponse> {
|
||||
const params = resourceId ? `?resource_id=${encodeURIComponent(resourceId)}` : '';
|
||||
return apiFetchJSON(`${this.baseUrl}/ai/intelligence/baselines${params}`) as Promise<BaselinesResponse>;
|
||||
}
|
||||
|
||||
|
||||
// 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 }> {
|
||||
|
|
|
|||
88
frontend-modern/src/types/aiIntelligence.ts
Normal file
88
frontend-modern/src/types/aiIntelligence.ts
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Reference in a new issue