@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
232 lines • 6.71 kB
TypeScript
/**
* Automated Prescriptive Error Enhancement System
* @description Converts generic validation errors into intelligent, actionable guidance
*
* This system uses pattern detection to automatically enhance any error with:
* - Clear explanations of what went wrong
* - Specific actions to fix the problem
* - Template mode suggestions when appropriate
* - Field examples and documentation links
*
* The system requires zero maintenance - new fields and entities automatically
* get prescriptive guidance based on schema metadata and platform context.
*
* @author Optimizely MCP Server
* @version 1.0.0
*/
/**
* Context information for error enhancement
*/
export interface ErrorEnhancementContext {
entityType?: string;
operation?: 'create' | 'update' | 'delete';
platform?: 'feature' | 'web';
projectId?: string;
field?: string;
originalError?: any;
metadata?: Record<string, any>;
}
/**
* Enhanced error response structure
*/
export interface PrescriptiveErrorResponse {
status: 'ERROR' | 'TEMPLATE_MODE_REQUIRED' | 'VALIDATION_FAILED' | 'MISSING_DEPENDENCY' | 'WORKFLOW_GUIDANCE_REQUIRED' | 'CONCEPTUAL_GUIDANCE_REQUIRED';
error: {
code: string;
message: string;
field?: string;
provided?: any;
expected?: any;
existing_id?: string;
};
required_action?: {
tool: string;
mode?: string;
parameters?: Record<string, any>;
};
fix_options?: Array<{
priority: 'recommended' | 'alternative';
action: string;
command?: string;
reason: string;
}>;
hints?: string[];
examples?: any[];
documentation?: string;
project_info?: {
current?: string;
required?: string;
};
immediate_guidance?: {
critical_rule?: string;
why_templates_required?: string;
next_step?: string;
detected_workflow?: string;
common_mistake?: string;
};
common_errors?: Record<string, any>;
workflow_explanation?: {
title?: string;
required_steps?: string[];
critical_concepts?: Record<string, string>;
};
conceptual_guidance?: {
title?: string;
key_concepts?: Record<string, string>;
correct_workflow?: string[];
};
workflow_hints?: string[];
api_guidance?: {
correct_pattern?: string;
common_mistakes?: string[];
http_methods?: Record<string, string>;
required_parameters?: string[];
common_errors?: Record<string, string>;
};
modification_context?: {
target_entity?: string;
modification_type?: string;
related_entities?: string[];
complexity_reason?: string;
};
traffic_rules?: Record<string, any>;
calculation_help?: string[];
documentation_link?: string;
}
/**
* Automated system for enhancing validation errors with prescriptive guidance
*/
export declare class AutomatedPrescriptiveErrorEnhancer {
private patterns;
constructor();
/**
* Main entry point for error enhancement
*/
enhanceError(originalError: string, context?: ErrorEnhancementContext): PrescriptiveErrorResponse;
/**
* Enhances missing required field errors
*/
private enhanceMissingFieldError;
/**
* Enhances already exists errors (duplicate keys/names)
*/
private enhanceAlreadyExistsError;
/**
* Enhances template mode requirement errors
*/
private enhanceTemplateModeError;
/**
* Enhances invalid type errors
*/
private enhanceInvalidTypeError;
/**
* Enhances invalid enum value errors
*/
private enhanceInvalidEnumError;
/**
* Enhances platform mismatch errors
*/
private enhancePlatformMismatchError;
/**
* Creates a fallback enhanced response for unmatched patterns
*/
private createGenericPrescriptiveError;
/**
* Determines if template mode should be suggested for a missing field
*/
private shouldUseTemplate;
/**
* Gets field guidance from schema metadata
*/
private getFieldGuidance;
/**
* Gets template-specific hints
*/
private getTemplateHints;
/**
* Gets field fix options for manual correction
*/
private getFieldFixOptions;
/**
* Gets field examples from schema metadata
*/
private getFieldExamples;
/**
* Gets type-specific examples
*/
private getTypeExamples;
/**
* Gets type-specific hints
*/
private getTypeHints;
/**
* Generates documentation URLs
*/
private getDocumentationUrl;
/**
* Helper methods for pattern detection and data extraction
*/
private isPlatformMismatchError;
private extractEntityTypeFromError;
private extractExpectedType;
private extractProvidedValue;
private inferRequiredPlatform;
private getPlatformGuidanceMessage;
/**
* Detects audience condition validation errors
*/
private isAudienceConditionError;
/**
* Enhances audience condition validation errors with template guidance
*/
private enhanceAudienceConditionError;
/**
* Finds the closest valid condition type using fuzzy matching for typos
*/
private findClosestConditionType;
/**
* Calculates similarity between two strings using a simple algorithm
*/
private calculateSimilarity;
/**
* Enhances ruleset operation errors with proper workflow guidance
*/
private enhanceRulesetOperationError;
/**
* Enhances template not found errors with available template list
*/
private enhanceTemplateNotFoundError;
/**
* Enhances parameter order errors with correct sequence
*/
private enhanceParameterError;
/**
* Enhances entity exists errors with adoption options
*/
private enhanceEntityExistsError;
/**
* Enhances foreign key constraint errors with dependency guidance
*/
private enhanceForeignKeyConstraintError;
/**
* Enhances validation errors with format examples
*/
private enhanceValidationError;
/**
* Enhances permission denied errors with access guidance
*/
private enhancePermissionDeniedError;
/**
* Enhances rate limit errors with retry guidance
*/
private enhanceRateLimitError;
/**
* Enhances network errors with connectivity guidance
*/
private enhanceNetworkError;
}
/**
* Singleton instance for global use
*/
export declare const automatedErrorEnhancer: AutomatedPrescriptiveErrorEnhancer;
//# sourceMappingURL=AutomatedPrescriptiveErrorEnhancer.d.ts.map