UNPKG

@dorothywebb/any-browser-mcp

Version:

Any Browser MCP - Launch Chrome with your actual data in debug mode for comprehensive browser automation

475 lines 18 kB
/** * Configuration Validation System using Zod * * @fileoverview Provides runtime validation of config.json with detailed error messages, * warnings for potentially problematic configurations, and automatic merging with defaults. * * @example * ```typescript * import { ConfigValidator } from './ConfigValidator.js'; * * // Validate a configuration object * const result = ConfigValidator.validate(userConfig); * if (result.success) { * console.log('Configuration is valid:', result.config); * } else { * console.error('Validation errors:', result.errors); * } * * // Merge with defaults * const mergedConfig = ConfigValidator.mergeWithDefaults(partialConfig); * ``` * * @category Configuration */ import { z } from 'zod'; declare const BrowserConfigSchema: z.ZodObject<{ type: z.ZodEnum<["chrome", "edge", "firefox"]>; debugPort: z.ZodDefault<z.ZodNumber>; autoLaunch: z.ZodDefault<z.ZodBoolean>; allowLaunch: z.ZodDefault<z.ZodBoolean>; useExistingOnly: z.ZodDefault<z.ZodBoolean>; endpoint: z.ZodOptional<z.ZodString>; connectionTimeout: z.ZodDefault<z.ZodNumber>; retryAttempts: z.ZodDefault<z.ZodNumber>; retryDelay: z.ZodDefault<z.ZodNumber>; useSeparateInstance: z.ZodDefault<z.ZodBoolean>; mcpProfilePath: z.ZodDefault<z.ZodString>; copyUserData: z.ZodDefault<z.ZodBoolean>; launchTimeout: z.ZodDefault<z.ZodNumber>; confirmDestructiveActions: z.ZodDefault<z.ZodBoolean>; sourceProfilePath: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { type: "chrome" | "edge" | "firefox"; debugPort: number; autoLaunch: boolean; allowLaunch: boolean; useExistingOnly: boolean; connectionTimeout: number; retryAttempts: number; retryDelay: number; useSeparateInstance: boolean; mcpProfilePath: string; copyUserData: boolean; launchTimeout: number; confirmDestructiveActions: boolean; endpoint?: string | undefined; sourceProfilePath?: string | undefined; }, { type: "chrome" | "edge" | "firefox"; debugPort?: number | undefined; autoLaunch?: boolean | undefined; allowLaunch?: boolean | undefined; useExistingOnly?: boolean | undefined; endpoint?: string | undefined; connectionTimeout?: number | undefined; retryAttempts?: number | undefined; retryDelay?: number | undefined; useSeparateInstance?: boolean | undefined; mcpProfilePath?: string | undefined; copyUserData?: boolean | undefined; launchTimeout?: number | undefined; confirmDestructiveActions?: boolean | undefined; sourceProfilePath?: string | undefined; }>; declare const ServerConfigSchema: z.ZodObject<{ strategy: z.ZodDefault<z.ZodEnum<["direct-cdp", "playwright", "hybrid", "separate-instance"]>>; lazyInitialization: z.ZodDefault<z.ZodBoolean>; initializeOnStartup: z.ZodDefault<z.ZodBoolean>; connectOnFirstUse: z.ZodDefault<z.ZodBoolean>; verbose: z.ZodDefault<z.ZodBoolean>; maxConcurrentConnections: z.ZodDefault<z.ZodNumber>; }, "strip", z.ZodTypeAny, { strategy: "direct-cdp" | "playwright" | "hybrid" | "separate-instance"; lazyInitialization: boolean; initializeOnStartup: boolean; connectOnFirstUse: boolean; verbose: boolean; maxConcurrentConnections: number; }, { strategy?: "direct-cdp" | "playwright" | "hybrid" | "separate-instance" | undefined; lazyInitialization?: boolean | undefined; initializeOnStartup?: boolean | undefined; connectOnFirstUse?: boolean | undefined; verbose?: boolean | undefined; maxConcurrentConnections?: number | undefined; }>; declare const SafetyConfigSchema: z.ZodObject<{ neverLaunchBrowser: z.ZodDefault<z.ZodBoolean>; requireExistingBrowser: z.ZodDefault<z.ZodBoolean>; allowSeparateInstance: z.ZodDefault<z.ZodBoolean>; validateConnection: z.ZodDefault<z.ZodBoolean>; timeoutConnections: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { neverLaunchBrowser: boolean; requireExistingBrowser: boolean; allowSeparateInstance: boolean; validateConnection: boolean; timeoutConnections: boolean; }, { neverLaunchBrowser?: boolean | undefined; requireExistingBrowser?: boolean | undefined; allowSeparateInstance?: boolean | undefined; validateConnection?: boolean | undefined; timeoutConnections?: boolean | undefined; }>; declare const FeaturesConfigSchema: z.ZodObject<{ preventAutoStart: z.ZodDefault<z.ZodBoolean>; useExistingTabs: z.ZodDefault<z.ZodBoolean>; duplicateUserData: z.ZodDefault<z.ZodBoolean>; respectUserBrowser: z.ZodDefault<z.ZodBoolean>; separateInstance: z.ZodDefault<z.ZodBoolean>; autoLaunchWhenNeeded: z.ZodDefault<z.ZodBoolean>; confirmDestructiveActions: z.ZodDefault<z.ZodBoolean>; errorRetry: z.ZodDefault<z.ZodBoolean>; gracefulFailure: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { confirmDestructiveActions: boolean; preventAutoStart: boolean; useExistingTabs: boolean; duplicateUserData: boolean; respectUserBrowser: boolean; separateInstance: boolean; autoLaunchWhenNeeded: boolean; errorRetry: boolean; gracefulFailure: boolean; }, { confirmDestructiveActions?: boolean | undefined; preventAutoStart?: boolean | undefined; useExistingTabs?: boolean | undefined; duplicateUserData?: boolean | undefined; respectUserBrowser?: boolean | undefined; separateInstance?: boolean | undefined; autoLaunchWhenNeeded?: boolean | undefined; errorRetry?: boolean | undefined; gracefulFailure?: boolean | undefined; }>; declare const PathsConfigSchema: z.ZodObject<{ chrome: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>; }, "strip", z.ZodTypeAny, { chrome: Record<string, string>; }, { chrome?: Record<string, string> | undefined; }>; export declare const AppConfigSchema: z.ZodObject<{ browser: z.ZodDefault<z.ZodOptional<z.ZodObject<{ type: z.ZodEnum<["chrome", "edge", "firefox"]>; debugPort: z.ZodDefault<z.ZodNumber>; autoLaunch: z.ZodDefault<z.ZodBoolean>; allowLaunch: z.ZodDefault<z.ZodBoolean>; useExistingOnly: z.ZodDefault<z.ZodBoolean>; endpoint: z.ZodOptional<z.ZodString>; connectionTimeout: z.ZodDefault<z.ZodNumber>; retryAttempts: z.ZodDefault<z.ZodNumber>; retryDelay: z.ZodDefault<z.ZodNumber>; useSeparateInstance: z.ZodDefault<z.ZodBoolean>; mcpProfilePath: z.ZodDefault<z.ZodString>; copyUserData: z.ZodDefault<z.ZodBoolean>; launchTimeout: z.ZodDefault<z.ZodNumber>; confirmDestructiveActions: z.ZodDefault<z.ZodBoolean>; sourceProfilePath: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { type: "chrome" | "edge" | "firefox"; debugPort: number; autoLaunch: boolean; allowLaunch: boolean; useExistingOnly: boolean; connectionTimeout: number; retryAttempts: number; retryDelay: number; useSeparateInstance: boolean; mcpProfilePath: string; copyUserData: boolean; launchTimeout: number; confirmDestructiveActions: boolean; endpoint?: string | undefined; sourceProfilePath?: string | undefined; }, { type: "chrome" | "edge" | "firefox"; debugPort?: number | undefined; autoLaunch?: boolean | undefined; allowLaunch?: boolean | undefined; useExistingOnly?: boolean | undefined; endpoint?: string | undefined; connectionTimeout?: number | undefined; retryAttempts?: number | undefined; retryDelay?: number | undefined; useSeparateInstance?: boolean | undefined; mcpProfilePath?: string | undefined; copyUserData?: boolean | undefined; launchTimeout?: number | undefined; confirmDestructiveActions?: boolean | undefined; sourceProfilePath?: string | undefined; }>>>; server: z.ZodDefault<z.ZodOptional<z.ZodObject<{ strategy: z.ZodDefault<z.ZodEnum<["direct-cdp", "playwright", "hybrid", "separate-instance"]>>; lazyInitialization: z.ZodDefault<z.ZodBoolean>; initializeOnStartup: z.ZodDefault<z.ZodBoolean>; connectOnFirstUse: z.ZodDefault<z.ZodBoolean>; verbose: z.ZodDefault<z.ZodBoolean>; maxConcurrentConnections: z.ZodDefault<z.ZodNumber>; }, "strip", z.ZodTypeAny, { strategy: "direct-cdp" | "playwright" | "hybrid" | "separate-instance"; lazyInitialization: boolean; initializeOnStartup: boolean; connectOnFirstUse: boolean; verbose: boolean; maxConcurrentConnections: number; }, { strategy?: "direct-cdp" | "playwright" | "hybrid" | "separate-instance" | undefined; lazyInitialization?: boolean | undefined; initializeOnStartup?: boolean | undefined; connectOnFirstUse?: boolean | undefined; verbose?: boolean | undefined; maxConcurrentConnections?: number | undefined; }>>>; safety: z.ZodDefault<z.ZodOptional<z.ZodObject<{ neverLaunchBrowser: z.ZodDefault<z.ZodBoolean>; requireExistingBrowser: z.ZodDefault<z.ZodBoolean>; allowSeparateInstance: z.ZodDefault<z.ZodBoolean>; validateConnection: z.ZodDefault<z.ZodBoolean>; timeoutConnections: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { neverLaunchBrowser: boolean; requireExistingBrowser: boolean; allowSeparateInstance: boolean; validateConnection: boolean; timeoutConnections: boolean; }, { neverLaunchBrowser?: boolean | undefined; requireExistingBrowser?: boolean | undefined; allowSeparateInstance?: boolean | undefined; validateConnection?: boolean | undefined; timeoutConnections?: boolean | undefined; }>>>; features: z.ZodDefault<z.ZodOptional<z.ZodObject<{ preventAutoStart: z.ZodDefault<z.ZodBoolean>; useExistingTabs: z.ZodDefault<z.ZodBoolean>; duplicateUserData: z.ZodDefault<z.ZodBoolean>; respectUserBrowser: z.ZodDefault<z.ZodBoolean>; separateInstance: z.ZodDefault<z.ZodBoolean>; autoLaunchWhenNeeded: z.ZodDefault<z.ZodBoolean>; confirmDestructiveActions: z.ZodDefault<z.ZodBoolean>; errorRetry: z.ZodDefault<z.ZodBoolean>; gracefulFailure: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { confirmDestructiveActions: boolean; preventAutoStart: boolean; useExistingTabs: boolean; duplicateUserData: boolean; respectUserBrowser: boolean; separateInstance: boolean; autoLaunchWhenNeeded: boolean; errorRetry: boolean; gracefulFailure: boolean; }, { confirmDestructiveActions?: boolean | undefined; preventAutoStart?: boolean | undefined; useExistingTabs?: boolean | undefined; duplicateUserData?: boolean | undefined; respectUserBrowser?: boolean | undefined; separateInstance?: boolean | undefined; autoLaunchWhenNeeded?: boolean | undefined; errorRetry?: boolean | undefined; gracefulFailure?: boolean | undefined; }>>>; paths: z.ZodDefault<z.ZodOptional<z.ZodObject<{ chrome: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>; }, "strip", z.ZodTypeAny, { chrome: Record<string, string>; }, { chrome?: Record<string, string> | undefined; }>>>; }, "strip", z.ZodTypeAny, { browser: { type: "chrome" | "edge" | "firefox"; debugPort: number; autoLaunch: boolean; allowLaunch: boolean; useExistingOnly: boolean; connectionTimeout: number; retryAttempts: number; retryDelay: number; useSeparateInstance: boolean; mcpProfilePath: string; copyUserData: boolean; launchTimeout: number; confirmDestructiveActions: boolean; endpoint?: string | undefined; sourceProfilePath?: string | undefined; }; server: { strategy: "direct-cdp" | "playwright" | "hybrid" | "separate-instance"; lazyInitialization: boolean; initializeOnStartup: boolean; connectOnFirstUse: boolean; verbose: boolean; maxConcurrentConnections: number; }; safety: { neverLaunchBrowser: boolean; requireExistingBrowser: boolean; allowSeparateInstance: boolean; validateConnection: boolean; timeoutConnections: boolean; }; features: { confirmDestructiveActions: boolean; preventAutoStart: boolean; useExistingTabs: boolean; duplicateUserData: boolean; respectUserBrowser: boolean; separateInstance: boolean; autoLaunchWhenNeeded: boolean; errorRetry: boolean; gracefulFailure: boolean; }; paths: { chrome: Record<string, string>; }; }, { browser?: { type: "chrome" | "edge" | "firefox"; debugPort?: number | undefined; autoLaunch?: boolean | undefined; allowLaunch?: boolean | undefined; useExistingOnly?: boolean | undefined; endpoint?: string | undefined; connectionTimeout?: number | undefined; retryAttempts?: number | undefined; retryDelay?: number | undefined; useSeparateInstance?: boolean | undefined; mcpProfilePath?: string | undefined; copyUserData?: boolean | undefined; launchTimeout?: number | undefined; confirmDestructiveActions?: boolean | undefined; sourceProfilePath?: string | undefined; } | undefined; server?: { strategy?: "direct-cdp" | "playwright" | "hybrid" | "separate-instance" | undefined; lazyInitialization?: boolean | undefined; initializeOnStartup?: boolean | undefined; connectOnFirstUse?: boolean | undefined; verbose?: boolean | undefined; maxConcurrentConnections?: number | undefined; } | undefined; safety?: { neverLaunchBrowser?: boolean | undefined; requireExistingBrowser?: boolean | undefined; allowSeparateInstance?: boolean | undefined; validateConnection?: boolean | undefined; timeoutConnections?: boolean | undefined; } | undefined; features?: { confirmDestructiveActions?: boolean | undefined; preventAutoStart?: boolean | undefined; useExistingTabs?: boolean | undefined; duplicateUserData?: boolean | undefined; respectUserBrowser?: boolean | undefined; separateInstance?: boolean | undefined; autoLaunchWhenNeeded?: boolean | undefined; errorRetry?: boolean | undefined; gracefulFailure?: boolean | undefined; } | undefined; paths?: { chrome?: Record<string, string> | undefined; } | undefined; }>; export type ValidatedAppConfig = z.infer<typeof AppConfigSchema>; export type ValidatedBrowserConfig = z.infer<typeof BrowserConfigSchema>; export type ValidatedServerConfig = z.infer<typeof ServerConfigSchema>; export type ValidatedSafetyConfig = z.infer<typeof SafetyConfigSchema>; /** * Configuration validation result */ export interface ValidationResult { success: boolean; config?: ValidatedAppConfig; errors?: ValidationError[]; warnings?: ValidationWarning[]; } export interface ValidationError { path: string; message: string; code: string; received?: any; expected?: any; } export interface ValidationWarning { path: string; message: string; suggestion?: string; } /** * Configuration Validator class providing comprehensive validation capabilities. * * @description This class uses Zod schemas to validate configuration objects, * generate helpful warnings, and merge user configurations with sensible defaults. * * @example * ```typescript * // Basic validation * const result = ConfigValidator.validate(userConfig); * * // Validation with error throwing * const validConfig = ConfigValidator.validateOrThrow(userConfig); * * // Merge with defaults * const mergedConfig = ConfigValidator.mergeWithDefaults(partialConfig); * ``` */ export declare class ConfigValidator { /** * Validates a configuration object against the schema. * * @param config - The configuration object to validate * @returns Validation result with success status, validated config, errors, and warnings * * @example * ```typescript * const result = ConfigValidator.validate({ * browser: { type: 'chrome', debugPort: 9223 } * }); * * if (result.success) { * console.log('Valid config:', result.config); * if (result.warnings?.length) { * console.warn('Warnings:', result.warnings); * } * } else { * console.error('Validation failed:', result.errors); * } * ``` */ static validate(config: any): ValidationResult; /** * Validate and throw on error */ static validateOrThrow(config: any): ValidatedAppConfig; /** * Format Zod errors into our error format */ private static formatZodErrors; /** * Generate warnings for potentially problematic configurations */ private static generateWarnings; /** * Get default configuration */ static getDefaultConfig(): ValidatedAppConfig; /** * Merge user config with defaults */ static mergeWithDefaults(userConfig: any): ValidatedAppConfig; /** * Deep merge two objects */ private static deepMerge; /** * Validate specific configuration section */ static validateSection<T>(sectionName: keyof ValidatedAppConfig, config: any, schema: z.ZodSchema<T>): ValidationResult; } export { BrowserConfigSchema, ServerConfigSchema, SafetyConfigSchema, FeaturesConfigSchema, PathsConfigSchema }; //# sourceMappingURL=ConfigValidator.d.ts.map