/**
 * Function Registry for MCP
 *
 * Central registry for managing function definitions and execution across providers
 */
import { EventEmitter } from 'events';
import { FunctionDefinition, FunctionCall, FunctionSecurity } from '../types';
/**
 * Function execution context
 */
export interface FunctionExecutionContext {
    agentDID: string;
    sessionId: string;
    requestId: string;
    provider: string;
    model: string;
    timestamp: Date;
    metadata?: Record<string, any>;
}
/**
 * Function handler
 */
export type FunctionHandler = (args: Record<string, any>, context: FunctionExecutionContext) => Promise<any>;
/**
 * Function metadata
 */
export interface FunctionMetadata {
    id: string;
    name: string;
    version: string;
    author: string;
    description: string;
    category: string;
    tags: string[];
    deprecated: boolean;
    createdAt: Date;
    updatedAt: Date;
    usageCount: number;
    averageExecutionTime: number;
    successRate: number;
}
/**
 * Function validation result
 */
export interface FunctionValidationResult {
    valid: boolean;
    errors: string[];
    warnings: string[];
    sanitizedArgs?: Record<string, any>;
}
/**
 * Registered function
 */
export interface RegisteredFunction {
    definition: FunctionDefinition;
    handler: FunctionHandler;
    metadata: FunctionMetadata;
    security: FunctionSecurity;
    enabled: boolean;
}
/**
 * Function execution result
 */
export interface FunctionExecutionResult {
    functionCallId: string;
    result: any;
    error?: string;
    executionTime: number;
    timestamp: Date;
    metadata: {
        provider: string;
        model: string;
        agentDID: string;
        sessionId: string;
        memoryUsage?: number;
        warnings?: string[];
    };
}
/**
 * Function registry configuration
 */
export interface FunctionRegistryConfig {
    maxExecutionTime: number;
    maxMemoryUsage: number;
    enableSandboxing: boolean;
    allowDynamicRegistration: boolean;
    securityLevel: 'strict' | 'moderate' | 'permissive';
    auditAllCalls: boolean;
    cacheResults: boolean;
    cacheTimeout: number;
}
/**
 * Function Registry
 */
export declare class FunctionRegistry extends EventEmitter {
    private config;
    private functions;
    private categories;
    private executionCache;
    private executionMetrics;
    constructor(config?: FunctionRegistryConfig);
    /**
     * Register a function
     */
    registerFunction(definition: FunctionDefinition, handler: FunctionHandler, options?: {
        security?: Partial<FunctionSecurity>;
        metadata?: Partial<FunctionMetadata>;
        enabled?: boolean;
    }): Promise<string>;
    /**
     * Execute a function
     */
    executeFunction(functionCall: FunctionCall, context: FunctionExecutionContext): Promise<FunctionExecutionResult>;
    /**
     * Get function definition by name
     */
    getFunctionDefinition(name: string): FunctionDefinition | null;
    /**
     * Get all function definitions
     */
    getAllFunctionDefinitions(): FunctionDefinition[];
    /**
     * Get functions by category
     */
    getFunctionsByCategory(category: string): FunctionDefinition[];
    /**
     * Search functions
     */
    searchFunctions(query: string): FunctionDefinition[];
    /**
     * Enable/disable function
     */
    setFunctionEnabled(name: string, enabled: boolean): void;
    /**
     * Unregister function
     */
    unregisterFunction(name: string): boolean;
    /**
     * Get function statistics
     */
    getFunctionStatistics(): {
        totalFunctions: number;
        enabledFunctions: number;
        functionsByCategory: Record<string, number>;
        topFunctions: Array<{
            name: string;
            calls: number;
            avgTime: number;
        }>;
        errorRate: number;
    };
    /**
     * Validate function definition
     */
    private validateFunctionDefinition;
    /**
     * Validate function arguments
     */
    private validateFunctionArguments;
    /**
     * Validate parameter value
     */
    private validateParameterValue;
    /**
     * Execute function with timeout
     */
    private executeWithTimeout;
    /**
     * Generate cache key for function call
     */
    private generateCacheKey;
    /**
     * Update execution metrics
     */
    private updateExecutionMetrics;
    /**
     * Update average execution time
     */
    private updateAverageExecutionTime;
    /**
     * Update success rate
     */
    private updateSuccessRate;
    /**
     * Initialize built-in functions
     */
    private initializeBuiltinFunctions;
    /**
     * Clear cache
     */
    clearCache(): void;
    /**
     * Shutdown
     */
    shutdown(): void;
}
export default FunctionRegistry;
//# sourceMappingURL=function-registry.d.ts.map