/** * Compliance API client — AI registry, DPIA template, incidents, retention policies. * * All endpoints are admin-only and target /api/v1/compliance/... */ import { apiGet, apiPost, apiPatch } from './client'; // ─── Types ─── export interface AIRegistryEntry { agent_id: string; name: string; description: string; is_active: boolean; llm_model: string; ai_use_case_metadata: Record; validation_warnings: string[]; } export interface AIRegistryResponse { items: AIRegistryEntry[]; total: number; } export interface DPIATemplate { use_case_id: string; agent_name: string; intended_purpose: string; owner: string; risk_class: string; oversight_policy: string; data_categories: string[]; allowed_providers: string[]; allowed_models: string[]; allowed_actions: string[]; human_review_required: boolean; validation_warnings: string[]; disclaimer: string; } export interface ComplianceIncident { id: string; incident_type: string; title: string; description: string; affected_use_cases: string[]; affected_versions: string[]; provider: string; measures_taken: string; evidence_refs: string[]; status: string; created_by: string | null; resolved_by: string | null; resolved_at: string | null; created_at: string | null; updated_at: string | null; } export interface IncidentCreate { incident_type: string; title: string; description?: string; affected_use_cases?: string[]; affected_versions?: string[]; provider?: string; measures_taken?: string; evidence_refs?: string[]; status?: string; } export interface IncidentUpdate { title?: string; description?: string; incident_type?: string; affected_use_cases?: string[]; affected_versions?: string[]; provider?: string; measures_taken?: string; evidence_refs?: string[]; status?: string; } export interface IncidentsResponse { items: ComplianceIncident[]; total: number; } export interface RetentionPolicyEntry { key: string; label: string; description: string; default_days: number; current_days: number; editable: boolean; } export interface RetentionPoliciesResponse { items: RetentionPolicyEntry[]; total: number; } // ─── API Functions ─── export async function fetchAIRegistry(): Promise { return apiGet('/compliance/ai-registry'); } export async function fetchDPIATemplate(agentId: string): Promise { return apiGet('/compliance/dpia-template', { params: { agent_id: agentId }, }); } export async function fetchIncidents(params?: { status?: string; incident_type?: string; limit?: number; offset?: number; }): Promise { return apiGet('/compliance/incidents', { params }); } export async function createIncident(data: IncidentCreate): Promise { return apiPost('/compliance/incidents', data); } export async function updateIncident( id: string, data: IncidentUpdate ): Promise { return apiPatch(`/compliance/incidents/${id}`, data); } export async function fetchRetentionPolicies(): Promise { return apiGet('/compliance/retention-policies'); } export async function updateRetentionPolicy( key: string, days: number ): Promise<{ key: string; days: number; message: string }> { return apiPatch<{ key: string; days: number; message: string }>( `/compliance/retention-policies/${key}`, { days } ); }