"use strict";
/**
 * NIST AI Risk Management Framework Compliance Pack
 *
 * NIST AI RMF 1.0 (published January 2023) with the 2024 Generative
 * AI Profile (NIST AI 600-1, published July 2024). The primary US
 * voluntary framework for trustworthy AI, increasingly expected by
 * federal procurement and referenced in executive orders.
 *
 * Standards referenced:
 *   - NIST AI 100-1 (AI RMF 1.0, Jan 2023)
 *   - NIST AI RMF Playbook (May 2023, updated periodically)
 *   - NIST AI 600-1 (AI RMF Generative AI Profile, July 2024)
 *   - NIST SP 800-53 Rev. 5 (security controls, referenced in GOVERN 1)
 *   - Executive Order 14110 (AI executive order, Oct 2023)
 *   - 2024 DHS / CISA AI Risk Management for Critical Infrastructure
 *
 * Four functions + 72 subcategories:
 *   - GOVERN: Organizational culture and governance
 *   - MAP: Context established for system evaluation
 *   - MEASURE: Performance tracked against benchmarks
 *   - MANAGE: Risks prioritized and treated
 *
 * Current state (2026):
 *   - GenAI Profile is now de facto when an AI system uses LLMs /
 *     foundation models / image generators; adds 12 generative-AI
 *     risks and 200+ action items over RMF 1.0 baseline.
 *   - Pairs with EU AI Act, Colorado AI Act, and ISO 42001.
 *   - NIST AI RMF compliance is an affirmative defence under the
 *     Colorado AI Act (§6-1-1706).
 *
 * @connexum/ai-governance
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.NIST_AI_RMF_PACK = exports.NIST_AI_RMF_CATEGORY_CLASSIFIERS = void 0;
/**
 * NIST AI RMF category classifiers.
 * NIST AI RMF governs AI risk management process flows (GOVERN, MAP, MEASURE, MANAGE).
 * Classification enforces credential scanning per MANAGE 3 (third-party AI risk).
 *
 * NOTE: PII and PHI were removed (F-NEW-CRIT-19, F-NEW-CRIT-20). NIST AI RMF
 * is a process framework; it does not independently classify personal data. When
 * PII or PHI is in scope, activate CCPA, HIPAA, or GDPR alongside this pack.
 */
exports.NIST_AI_RMF_CATEGORY_CLASSIFIERS = {
    CREDENTIALS: {
        references: ['NIST AI RMF MANAGE 3 -- third-party AI risk; credential exposure'],
        classifier: (input) => {
            if (/\b(?:api[_-]?key|apikey)\s*[=:]\s*["']?[A-Za-z0-9_\-\/+]{16,}["']?/i.test(input))
                return true;
            if (/\bpassword\s*[=:]\s*["']?[A-Za-z0-9!@#$%^&*_\-]{8,}["']?/i.test(input))
                return true;
            if (/\bAKIA[A-Z0-9]{16}\b/.test(input))
                return true;
            if (/-----BEGIN\s+(?:RSA\s+)?PRIVATE\s+KEY-----/.test(input))
                return true;
            if (/\b(?:secret[_-]?key|access[_-]?token)\s*[=:]\s*["']?[A-Za-z0-9_\-\/+]{16,}["']?/i.test(input))
                return true;
            return false;
        },
    },
    AI_RISK_REGISTRATION: {
        references: ['NIST AI RMF GOVERN-1.1, MAP-1.6 -- AI system inventory and registration'],
        classifier: (input) => {
            if (/\bnist\s+ai\s+rmf\b/i.test(input) && /\b(govern|map|measure|manage)\b/i.test(input))
                return true;
            if (/\bai\s+(system\s+)?(inventory|registry|registration)\b/i.test(input))
                return true;
            if (/\bai\s+risk\s+registration\b/i.test(input))
                return true;
            if (/\b(govern|map)[\s-]?1\.[0-9]\b/i.test(input))
                return true;
            if (/\b(model\s+lineage|provenance\s+recorded)\b/i.test(input))
                return true;
            return false;
        },
    },
    AI_INCIDENT_TRACKING: {
        references: ['NIST AI RMF MEASURE-2.7 -- adverse event reporting and incident response'],
        classifier: (input) => {
            if (/\bai\s+(adverse\s+(event|outcome)|incident)\b/i.test(input))
                return true;
            if (/\badverse\s+ai\s+(event|outcome)\b/i.test(input))
                return true;
            if (/\bnist\s+ai\s+rmf\s+measure[\s-]?2\.7\b/i.test(input))
                return true;
            if (/\bai\s+system\s+harm\s+report\b/i.test(input))
                return true;
            if (/\bai\s+incident\s+tracker\b/i.test(input))
                return true;
            if (/\bhallucination\s+caused\s+(?:customer\s+)?harm\b/i.test(input))
                return true;
            if (/\bmodel\s+failure\s+during\s+(?:production\s+)?inference\b/i.test(input))
                return true;
            return false;
        },
    },
    AI_BIAS_FINDING: {
        references: ['NIST AI RMF MEASURE-2.11, MEASURE-3.2 -- fairness and disparate-impact assessment'],
        classifier: (input) => {
            if (/\b(ai\s+)?bias\s+(audit|finding|evaluation|assessment)\b/i.test(input))
                return true;
            if (/\bdisparate\s+impact\b/i.test(input))
                return true;
            if (/\bfairness\s+(metric|audit|assessment)\b/i.test(input))
                return true;
            if (/\bdemographic\s+parity\b/i.test(input))
                return true;
            if (/\bequal\s+opportunity\s+ratio\b/i.test(input))
                return true;
            if (/\bnist\s+ai\s+rmf\s+measure[\s-]?(2\.11|3\.2)\b/i.test(input))
                return true;
            if (/\b(false[\s-]negative|false[\s-]positive)\s+rate\s+higher\s+for\b/i.test(input))
                return true;
            if (/\brebias\s+intervention\b/i.test(input))
                return true;
            if (/\bprotected\s+demographic\s+group\b/i.test(input))
                return true;
            return false;
        },
    },
    AI_HUMAN_OVERSIGHT_GAP: {
        references: ['NIST AI RMF MANAGE-2.3, MANAGE-4.1 -- human oversight and operator override'],
        classifier: (input) => {
            if (/\bhuman\s+oversight\s+(gap|missing|absent)\b/i.test(input))
                return true;
            if (/\bhuman[\s-]in[\s-]the[\s-]loop\s+(missing|gap|absent|not\s+(?:configured|enabled))/i.test(input))
                return true;
            if (/\bnist\s+ai\s+rmf\s+manage[\s-]?(2\.3|4\.1)\b/i.test(input))
                return true;
            if (/\boperator\s+override\s+(mechanism\s+)?(not\s+(?:implemented|enabled)|missing)/i.test(input))
                return true;
            if (/\bmeaningful\s+human\s+review\s+(absent|missing|not\s+performed)/i.test(input))
                return true;
            if (/\bauto[\s-]approved\s+without\s+human\s+review\b/i.test(input))
                return true;
            if (/\bfully\s+autonomous\s+mode\b/i.test(input))
                return true;
            if (/\bno\s+escalation\s+path\b/i.test(input) && /\b(ai|high[\s-]risk\s+output)/i.test(input))
                return true;
            return false;
        },
    },
};
exports.NIST_AI_RMF_PACK = {
    categoryClassifiers: exports.NIST_AI_RMF_CATEGORY_CLASSIFIERS,
    id: 'nist_ai_rmf',
    name: 'NIST AI Risk Management Framework',
    version: '1.0.0',
    description: 'NIST AI RMF 1.0 (Jan 2023) + Generative AI Profile (NIST AI 600-1, Jul 2024) compliance. Covers GOVERN / MAP / MEASURE / MANAGE functions with 72 subcategories and 12 GenAI-specific risks. Provides affirmative defence under Colorado AI Act §6-1-1706.',
    authority: 'National Institute of Standards and Technology (NIST)',
    industries: ['government', 'healthcare', 'finance', 'technology', 'defense', 'critical-infrastructure', 'ai-foundation-model-provider'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'AI governance policies, processes, and procedures',
            reference: 'NIST AI RMF GOVERN 1 -- Policies and procedures',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Documentation for accountability and traceability',
            reference: 'NIST AI RMF GOVERN 4 -- Organizational practices for documentation',
        },
        {
            name: 'anomaly-detector',
            required: true,
            reason: 'Continuous monitoring; drift detection; GenAI risk tracking',
            reference: 'NIST AI RMF MEASURE 3 -- Risks tracked; GenAI Profile MS-1',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Data categorization + GenAI training-data provenance',
            reference: 'NIST AI RMF MAP 2, MAP 4 -- Data characterization',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Risk response and escalation; incident detection',
            reference: 'NIST AI RMF MANAGE 2 -- Strategies to minimize negative impacts',
        },
        {
            name: 'circuit-breaker',
            required: true,
            reason: 'Residual risk management; system-level safeguards',
            reference: 'NIST AI RMF MANAGE 4 -- Residual risk management',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Human oversight at accountability structures',
            reference: 'NIST AI RMF GOVERN 2 -- Accountability structures with human oversight',
        },
        {
            name: 'bias-monitor',
            required: true,
            reason: 'Fairness assessment; impact on individuals and groups',
            reference: 'NIST AI RMF MAP 3, MEASURE 2 -- Fairness and bias',
        },
        {
            name: 'transparency-injector',
            required: true,
            reason: 'AI system disclosure; explainability; synthetic content labelling (GenAI Profile)',
            reference: 'NIST AI RMF MEASURE 2, GenAI Profile GV-3',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'Risk register + MANAGE 4 documentation + GenAI Profile attestations',
            reference: 'NIST AI RMF MANAGE 4, GenAI Profile MG-1',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'Third-party AI/ML component risk (GenAI supply chain)',
            reference: 'NIST AI RMF GOVERN 5, MAP 4; GenAI Profile MG-3',
        },
        {
            name: 'agent-registration-integrity',
            required: true,
            reason: 'Account management and audit record generation require verified, callable identities',
            reference: 'NIST SP 800-53 Rev 5 AC-2, AU-12',
        },
    ],
    moduleConfig: {
        'anomaly-detector': {
            thresholdMultiplier: 2.0,
            continuousMonitoringRequired: true,
            genaiRiskTrackingActive: true,
        },
        'circuit-breaker': {
            maxFailures: 5,
            resetTimeoutMs: 300000,
            residualRiskMitigationRequired: true,
        },
        'governance-runtime': {
            governPoliciesRequired: true,
            mapContextRequired: true,
            manageResidualRiskRequired: true,
        },
        'attestation-manager': {
            riskRegisterRequired: true,
            genaiProfileAlignmentRequired: true,
            accountabilityDocumentationRequired: true,
        },
        'bias-monitor': {
            fairnessAssessmentRequired: true,
        },
        'transparency-injector': {
            aiDisclosureRequired: true,
            syntheticContentLabellingRequired: true,
        },
        'supply-chain': {
            thirdPartyAiMlRiskRequired: true,
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: ['NIST-AI-RMF-ALIGNED'],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: ['CREDENTIALS', 'AI_RISK_REGISTRATION', 'AI_INCIDENT_TRACKING', 'AI_BIAS_FINDING', 'AI_HUMAN_OVERSIGHT_GAP'],
        categoryActions: {
            CREDENTIALS: 'BLOCK',
            AI_RISK_REGISTRATION: 'LOG',
            AI_INCIDENT_TRACKING: 'WARN',
            AI_BIAS_FINDING: 'WARN',
            AI_HUMAN_OVERSIGHT_GAP: 'WARN',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256-GCM',
        minimumClassification: 'INTERNAL',
    },
    retentionPolicy: {
        sovereignty: ['US'],
        auditLogRetentionDays: 2555, // 7 years
        sessionRetentionDays: 365,
        incidentRetentionDays: 2555,
        reference: 'NIST AI RMF GOVERN 4 -- Maintain documentation for accountability and traceability (7 years federal norm)',
    },
    incidentPolicy: {
        notificationDeadlineHours: 72,
        reference: 'NIST AI RMF MANAGE 3 -- AI risks from third-party resources managed; 72-hour escalation to stakeholders for material incidents',
        requiredRecipients: ['risk-management-team', 'senior-leadership', 'affected-stakeholders', 'chief-ai-officer-if-designated'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'nist-govern-1',
            description: 'AI governance policies and procedures documented',
            reference: 'NIST AI RMF GOVERN 1',
            check: 'governance_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'nist-govern-2',
            description: 'Accountability structures with human oversight',
            reference: 'NIST AI RMF GOVERN 2',
            check: 'approval_queue_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'nist-govern-4',
            description: 'Documentation for accountability and traceability',
            reference: 'NIST AI RMF GOVERN 4',
            check: 'audit_trail_exists',
            failSeverity: 'HIGH',
        },
        {
            id: 'nist-map-2',
            description: 'AI system data characterized and classified',
            reference: 'NIST AI RMF MAP 2',
            check: 'data_classifier_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'nist-map-3',
            description: 'Fairness / bias characteristics evaluated',
            reference: 'NIST AI RMF MAP 3',
            check: 'bias_monitor_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'nist-measure-3',
            description: 'Continuous risk monitoring mechanisms',
            reference: 'NIST AI RMF MEASURE 3',
            check: 'post_market_monitoring',
            failSeverity: 'HIGH',
        },
        {
            id: 'nist-manage-2',
            description: 'Risk response strategies active (system-level safeguards)',
            reference: 'NIST AI RMF MANAGE 2',
            check: 'nist_manage_2_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'nist-manage-4',
            description: 'Residual risk documented in risk register',
            reference: 'NIST AI RMF MANAGE 4',
            check: 'nist_risk_register_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'nist-genai-profile',
            description: 'GenAI Profile alignment for generative AI systems',
            reference: 'NIST AI 600-1 (Jul 2024)',
            check: 'nist_genai_profile_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'nist-transparency',
            description: 'AI disclosure + synthetic content labelling',
            reference: 'NIST AI RMF MEASURE 2; GenAI Profile GV-3',
            check: 'transparency_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'nist-supply-chain',
            description: 'Third-party AI/ML supply-chain risk managed',
            reference: 'NIST AI RMF GOVERN 5, MAP 4',
            check: 'subservice_registry_active',
            failSeverity: 'MEDIUM',
        },
    ],
};
//# sourceMappingURL=nist-ai-rmf.js.map