/** * External Dependency Detection * * Detects and categorizes errors from known external services (Plaid, Stripe, AWS, etc.) * to distinguish between: * - Environment misconfiguration (missing credentials) * - External API failures (service down, rate limited) * - Actual code bugs * * This helps users understand whether test failures are due to their MCP server code * or external factors beyond their control. */ import { EXTERNAL_DEPENDENCIES } from '../constants.js'; import type { ErrorPattern } from './response-fingerprint.js'; import type { ExternalServicesConfig } from '../interview/types.js'; /** Known external service names */ export type ExternalServiceName = keyof typeof EXTERNAL_DEPENDENCIES.SERVICES; /** Error source classification */ export type ErrorSource = keyof typeof EXTERNAL_DEPENDENCIES.ERROR_SOURCES; /** * Confidence level for dependency detection. * - 'confirmed': Actual error messages from the service were observed * - 'likely': Strong evidence from tool name/description patterns * - 'possible': Weak evidence, only partial matches */ export type DependencyConfidenceLevel = 'confirmed' | 'likely' | 'possible'; /** Information about a detected external dependency */ export interface ExternalDependencyInfo { /** Name of the external service (e.g., 'plaid', 'stripe') */ serviceName: ExternalServiceName; /** Display name of the service (e.g., 'Plaid', 'Stripe') */ displayName: string; /** Confidence level of the detection (0-1) */ confidence: number; /** * Whether this dependency was confirmed by actual errors. * - 'confirmed': Error message matched service-specific patterns * - 'likely': Tool name/description strongly suggests this service * - 'possible': Weak evidence, might be a false positive */ confidenceLevel: DependencyConfidenceLevel; /** Whether this appears to be a transient/temporary error */ isTransient: boolean; /** Suggested remediation for this error */ remediation: string; /** Matched patterns that led to detection */ matchedPatterns: string[]; /** Evidence breakdown for transparency */ evidence: { /** True if error message patterns matched */ fromErrorMessage: boolean; /** True if tool name patterns matched */ fromToolName: boolean; /** True if tool description patterns matched */ fromDescription: boolean; /** Number of actual errors attributed to this dependency */ actualErrorCount: number; }; } /** Configuration status for a known external service */ export interface ServiceStatus { /** External service name */ service: ExternalServiceName; /** Whether the service is fully configured */ configured: boolean; /** Missing credential keys or env vars */ missingCredentials: string[]; /** Whether a sandbox is available */ sandboxAvailable: boolean; /** Whether a mock response is available */ mockAvailable: boolean; } /** Result of analyzing an error for external dependencies */ export interface ExternalDependencyAnalysis { /** The error source classification */ source: ErrorSource; /** Detected external dependency info (if source is 'external_dependency') */ dependency?: ExternalDependencyInfo; /** Whether the error appears transient */ isTransient: boolean; /** Human-readable explanation of the classification */ explanation: string; /** Remediation suggestion */ remediation?: string; } /** Summary of external dependencies across all tools */ export interface ExternalDependencySummary { /** Services detected across all tools */ services: Map; /** Total number of external dependency errors */ totalExternalErrors: number; /** Total number of environment configuration errors */ totalEnvironmentErrors: number; /** Total number of likely code bugs */ totalCodeBugErrors: number; /** Total number of unclassified errors */ totalUnknownErrors: number; /** Tools affected by external dependencies */ affectedTools: Map; } /** Summary for a single external service */ export interface ExternalServiceSummary { /** Display name of the service */ displayName: string; /** Number of errors from this service */ errorCount: number; /** Number of confirmed errors (from error message patterns) */ confirmedErrorCount: number; /** Tools that use this service (confirmed from errors) */ confirmedTools: string[]; /** Tools that likely use this service (from name/description only) */ detectedTools: string[]; /** All tools associated with this service */ tools: string[]; /** Whether errors appear to be transient */ hasTransientErrors: boolean; /** Primary remediation suggestion */ remediation: string; /** Highest confidence level for this service */ highestConfidenceLevel: DependencyConfidenceLevel; } /** * Detect if an error message indicates an external dependency. * * @param errorMessage - The error message to analyze * @param toolName - Optional tool name for context * @param toolDescription - Optional tool description for context * @returns External dependency info if detected, null otherwise */ export declare function detectExternalDependency(errorMessage: string, toolName?: string, toolDescription?: string): ExternalDependencyInfo | null; /** * Detect external service dependencies based on tool name/description alone. */ export declare function detectExternalServiceFromTool(toolName: string, toolDescription?: string): ExternalDependencyInfo | null; /** * Determine whether an external service is configured. */ export declare function getExternalServiceStatus(serviceName: ExternalServiceName, config?: ExternalServicesConfig): ServiceStatus; /** * Categorize the source of an error. * * @param errorMessage - The error message to analyze * @param toolName - Optional tool name for context * @param toolDescription - Optional tool description for context * @returns Analysis of the error source */ export declare function categorizeErrorSource(errorMessage: string, toolName?: string, toolDescription?: string): ExternalDependencyAnalysis; /** * Check if an error appears to be transient (temporary). * * @param errorMessage - The error message to check * @returns True if the error appears transient */ export declare function isTransientError(errorMessage: string): boolean; /** * Analyze multiple error patterns and generate a summary. * * @param errors - Array of tool names and their error patterns * @returns Summary of external dependencies */ export declare function analyzeExternalDependencies(errors: Array<{ toolName: string; toolDescription?: string; patterns: ErrorPattern[]; }>): ExternalDependencySummary; /** * Format external dependency summary for display. * * @param summary - The summary to format * @param useColors - Whether to use ANSI colors * @returns Formatted string */ export declare function formatExternalDependencySummary(summary: ExternalDependencySummary, useColors?: boolean): string; /** * Generate markdown table for external dependencies. * * @param summary - The summary to format * @returns Markdown string */ export declare function formatExternalDependenciesMarkdown(summary: ExternalDependencySummary): string; //# sourceMappingURL=external-dependency-detector.d.ts.map