UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and

143 lines (142 loc) 4.71 kB
/** * Robust Error Handling Utilities for NeuroLink * Provides structured error management for tool execution and system operations */ export declare enum ErrorCategory { VALIDATION = "validation", TIMEOUT = "timeout", NETWORK = "network", RESOURCE = "resource", PERMISSION = "permission", CONFIGURATION = "configuration", EXECUTION = "execution", SYSTEM = "system" } export declare enum ErrorSeverity { LOW = "low", MEDIUM = "medium", HIGH = "high", CRITICAL = "critical" } export interface StructuredError { code: string; message: string; category: ErrorCategory; severity: ErrorSeverity; retriable: boolean; context?: Record<string, unknown>; originalError?: Error; timestamp: Date; toolName?: string; serverId?: string; } export declare const ERROR_CODES: { readonly TOOL_NOT_FOUND: "TOOL_NOT_FOUND"; readonly TOOL_EXECUTION_FAILED: "TOOL_EXECUTION_FAILED"; readonly TOOL_TIMEOUT: "TOOL_TIMEOUT"; readonly TOOL_VALIDATION_FAILED: "TOOL_VALIDATION_FAILED"; readonly INVALID_PARAMETERS: "INVALID_PARAMETERS"; readonly MISSING_REQUIRED_PARAM: "MISSING_REQUIRED_PARAM"; readonly MEMORY_EXHAUSTED: "MEMORY_EXHAUSTED"; readonly NETWORK_ERROR: "NETWORK_ERROR"; readonly PERMISSION_DENIED: "PERMISSION_DENIED"; readonly PROVIDER_NOT_AVAILABLE: "PROVIDER_NOT_AVAILABLE"; readonly PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED"; readonly PROVIDER_QUOTA_EXCEEDED: "PROVIDER_QUOTA_EXCEEDED"; readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION"; readonly MISSING_CONFIGURATION: "MISSING_CONFIGURATION"; }; /** * Enhanced error class with structured information */ export declare class NeuroLinkError extends Error { readonly code: string; readonly category: ErrorCategory; readonly severity: ErrorSeverity; readonly retriable: boolean; readonly context: Record<string, unknown>; readonly timestamp: Date; readonly toolName?: string; readonly serverId?: string; constructor(options: { code: string; message: string; category: ErrorCategory; severity: ErrorSeverity; retriable: boolean; context?: Record<string, unknown>; originalError?: Error; toolName?: string; serverId?: string; }); /** * Convert to JSON for logging and serialization */ toJSON(): StructuredError; } /** * Error factory for common error scenarios */ export declare class ErrorFactory { /** * Create a tool not found error */ static toolNotFound(toolName: string, availableTools?: string[]): NeuroLinkError; /** * Create a tool execution failed error */ static toolExecutionFailed(toolName: string, originalError: Error, serverId?: string): NeuroLinkError; /** * Create a tool timeout error */ static toolTimeout(toolName: string, timeoutMs: number, serverId?: string): NeuroLinkError; /** * Create a parameter validation error */ static invalidParameters(toolName: string, validationError: Error, providedParams?: unknown): NeuroLinkError; /** * Create a network error */ static networkError(toolName: string, originalError: Error, serverId?: string): NeuroLinkError; /** * Create a memory exhaustion error */ static memoryExhausted(toolName: string, memoryUsageMB: number): NeuroLinkError; } /** * Timeout wrapper for async operations */ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutError?: Error): Promise<T>; /** * Retry mechanism for retriable operations */ export declare function withRetry<T>(operation: () => Promise<T>, options: { maxAttempts: number; delayMs: number; isRetriable?: (error: Error) => boolean; onRetry?: (attempt: number, error: Error) => void; }): Promise<T>; /** * Circuit breaker for preventing cascading failures */ export declare class CircuitBreaker { private readonly failureThreshold; private readonly resetTimeoutMs; private failures; private lastFailureTime; private state; constructor(failureThreshold?: number, resetTimeoutMs?: number); execute<T>(operation: () => Promise<T>): Promise<T>; private onSuccess; private onFailure; getState(): "closed" | "open" | "half-open"; getFailureCount(): number; } /** * Error handler that decides whether to retry based on error type */ export declare function isRetriableError(error: Error): boolean; /** * Enhanced error logger that provides structured logging */ export declare function logStructuredError(error: NeuroLinkError, context?: Record<string, unknown>): void;