/**
 * Fastify Middleware for AI Governance
 * Integrates AI governance controls into Fastify endpoints
 * Vorion Security Platform
 */
import { FastifyRequest, FastifyReply, FastifyPluginCallback } from 'fastify';
import fp from 'fastify-plugin';
import { ModelRegistry } from './model-registry';
import { AccessPolicyManager } from './access-policy';
import { PromptInjectionDetector } from './prompt-injection';
import { OutputFilter } from './output-filter';
import { AuditTrail } from './audit-trail';
import { BiasDetector } from './bias-detection';
import { AIRateLimiter } from './rate-limiter';
import { AuditLevel, TokenUsage, InjectionDetectionResult, OutputFilterResult } from './types';
/**
 * AI Governance middleware options
 */
export interface AIGovernanceMiddlewareOptions {
    modelRegistry: ModelRegistry;
    accessPolicyManager: AccessPolicyManager;
    injectionDetector: PromptInjectionDetector;
    outputFilter: OutputFilter;
    auditTrail: AuditTrail;
    biasDetector: BiasDetector;
    rateLimiter: AIRateLimiter;
    enabled?: boolean;
    skipPaths?: string[];
    extractModelId?: (request: FastifyRequest) => string;
    extractUserId?: (request: FastifyRequest) => string;
    extractRoles?: (request: FastifyRequest) => string[];
    extractDepartment?: (request: FastifyRequest) => string;
    extractPrompt?: (request: FastifyRequest) => string;
    onAccessDenied?: (request: FastifyRequest, reply: FastifyReply, reason: string) => Promise<void>;
    onInjectionDetected?: (request: FastifyRequest, reply: FastifyReply, result: InjectionDetectionResult) => Promise<void>;
    onRateLimitExceeded?: (request: FastifyRequest, reply: FastifyReply, status: {
        retryAfterSeconds?: number;
    }) => Promise<void>;
}
/**
 * Extended request with AI governance context
 */
declare module 'fastify' {
    interface FastifyRequest {
        aiGovernance?: AIGovernanceContext;
    }
}
/**
 * AI Governance context attached to requests
 */
export interface AIGovernanceContext {
    modelId: string;
    userId: string;
    sessionId: string;
    roles: string[];
    department: string;
    auditLevel: AuditLevel;
    injectionResult?: InjectionDetectionResult;
    sanitizedPrompt?: string;
    startTime: number;
    tokenEstimate?: number;
}
/**
 * AI model response wrapper
 */
export interface AIModelResponse {
    content: string;
    tokenUsage: TokenUsage;
    modelVersion: string;
    metadata?: Record<string, unknown>;
}
/**
 * Create AI Governance middleware plugin
 */
declare const aiGovernancePlugin: FastifyPluginCallback<AIGovernanceMiddlewareOptions>;
/**
 * Create pre-configured AI Governance middleware
 */
export declare function createAIGovernanceMiddleware(options?: Partial<AIGovernanceMiddlewareOptions>): {
    plugin: ReturnType<typeof fp>;
    components: {
        modelRegistry: ModelRegistry;
        accessPolicyManager: AccessPolicyManager;
        injectionDetector: PromptInjectionDetector;
        outputFilter: OutputFilter;
        auditTrail: AuditTrail;
        biasDetector: BiasDetector;
        rateLimiter: AIRateLimiter;
    };
};
/**
 * Type declarations for fastify instance decoration
 */
declare module 'fastify' {
    interface FastifyInstance {
        aiGovernance: {
            processResponse(request: FastifyRequest, response: AIModelResponse): Promise<{
                filteredContent: string;
                filterResult: OutputFilterResult;
                auditEntryId: string;
            }>;
            logQuery(request: FastifyRequest, prompt: string, tokenUsage: TokenUsage): Promise<string>;
            getContext(request: FastifyRequest): AIGovernanceContext | undefined;
            getSanitizedPrompt(request: FastifyRequest): string | undefined;
        };
    }
}
export { aiGovernancePlugin };
export default createAIGovernanceMiddleware;
//# sourceMappingURL=middleware.d.ts.map