/**
 * TransparencyInjector -- EU AI Act Art. 13, 50 transparency enforcement.
 *
 * Ensures AI-generated content is properly disclosed and labeled.
 * Injects disclosure statements into chatbot responses and
 * labels AI-generated outputs with metadata.
 *
 * Required by:
 *   - EU AI Act Art. 13: Transparency requirements for high-risk AI
 *   - EU AI Act Art. 50: Transparency for certain AI systems
 *   - NYC Local Law 144: Automated employment decision tools
 *
 * @connexum/ai-governance
 */
import { createLogger } from '../util/log.js';
const log = createLogger('transparency');
export class TransparencyInjector {
    config;
    outputCount = 0;
    disclosureCount = 0;
    constructor(config) {
        this.config = {
            systemName: 'AI Agent',
            disclosureText: '',
            autoAppend: true,
            labelTypes: ['text', 'report', 'analysis', 'recommendation'],
            jurisdictions: ['eu'],
            ...config,
        };
        if (!this.config.disclosureText) {
            this.config.disclosureText = this.buildDefaultDisclosure();
        }
    }
    /**
     * Create a content label for AI-generated output.
     */
    label(options) {
        this.outputCount++;
        return {
            aiGenerated: true,
            systemId: this.config.systemName,
            organization: this.config.organizationName,
            model: options?.model,
            generatedAt: new Date().toISOString(),
            purpose: options?.purpose,
            humanReviewed: options?.humanReviewed ?? false,
            confidence: options?.confidence,
        };
    }
    /**
     * Get the disclosure text for chatbot interfaces.
     * EU AI Act Art. 50(1): Persons interacting with an AI system
     * shall be informed they are interacting with an AI system.
     */
    getDisclosure() {
        return this.config.disclosureText;
    }
    /**
     * Append disclosure to content if autoAppend is enabled.
     */
    wrapContent(content, options) {
        const contentLabel = this.label(options);
        let wrappedContent = content;
        if (this.config.autoAppend) {
            wrappedContent = `${content}\n\n---\n${this.config.disclosureText}`;
            this.disclosureCount++;
        }
        return { content: wrappedContent, label: contentLabel };
    }
    /**
     * Generate a machine-readable transparency card for the AI system.
     * EU AI Act Art. 13: Instructions for use.
     */
    generateTransparencyCard() {
        return {
            version: '1.0',
            system: {
                name: this.config.systemName,
                organization: this.config.organizationName,
                type: 'AI Agent Governance System',
            },
            capabilities: {
                description: 'Monitors and governs AI agent behavior for regulatory compliance',
                intendedUse: 'Enterprise AI governance and compliance enforcement',
                limitations: [
                    'Regex-based pattern matching may miss novel data formats',
                    'Compliance packs are informational, not legal advice',
                    'Requires human oversight for final compliance decisions',
                ],
            },
            transparency: {
                aiGenerated: true,
                humanOversight: 'Required for all critical decisions',
                disclosureMechanism: 'Automatic disclosure injection',
            },
            compliance: {
                frameworks: this.config.jurisdictions,
                lastUpdated: new Date().toISOString(),
            },
        };
    }
    /**
     * Check if the system meets transparency requirements for a jurisdiction.
     */
    checkCompliance(jurisdiction) {
        const requirements = [];
        const gaps = [];
        switch (jurisdiction.toLowerCase()) {
            case 'eu':
                requirements.push('AI system disclosure (Art. 50)');
                requirements.push('Technical documentation (Art. 11)');
                requirements.push('Record-keeping (Art. 12)');
                requirements.push('Transparency for users (Art. 13)');
                requirements.push('Human oversight capability (Art. 14)');
                if (!this.config.autoAppend)
                    gaps.push('Auto-disclosure not enabled');
                if (!this.config.disclosureText)
                    gaps.push('No disclosure text configured');
                break;
            case 'us-nyc':
                requirements.push('AEDT disclosure (NYC LL144)');
                requirements.push('Bias audit summary publication');
                if (!this.config.autoAppend)
                    gaps.push('Auto-disclosure not enabled');
                break;
            default:
                requirements.push(`No specific requirements mapped for ${jurisdiction}`);
        }
        return {
            compliant: gaps.length === 0,
            requirements,
            gaps,
        };
    }
    /**
     * Get transparency statistics.
     */
    getStats() {
        const complianceStatus = {};
        for (const j of this.config.jurisdictions) {
            complianceStatus[j] = this.checkCompliance(j).compliant;
        }
        return {
            outputsLabeled: this.outputCount,
            disclosuresInjected: this.disclosureCount,
            jurisdictions: this.config.jurisdictions,
            complianceStatus,
        };
    }
    // --- Private ---
    buildDefaultDisclosure() {
        return `This content was generated by ${this.config.systemName}, ` +
            `an AI system operated by ${this.config.organizationName}. ` +
            `AI-generated content should be reviewed by a qualified professional ` +
            `before being used for decision-making.`;
    }
}
//# sourceMappingURL=transparency-injector.js.map