UNPKG

humanbehavior-js

Version:

SDK for HumanBehavior session and event recording

524 lines (514 loc) 14.6 kB
/** * HumanBehavior SDK Auto-Installation Wizard * * This wizard automatically detects the user's framework and modifies their codebase * to integrate the SDK with minimal user intervention. */ interface FrameworkInfo$2 { name: string; type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'astro' | 'gatsby' | 'node' | 'auto'; bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup'; packageManager?: 'npm' | 'yarn' | 'pnpm'; hasTypeScript?: boolean; hasRouter?: boolean; projectRoot?: string; version?: string; majorVersion?: number; features?: { hasReact18?: boolean; hasVue3?: boolean; hasNuxt3?: boolean; hasAngularStandalone?: boolean; hasNextAppRouter?: boolean; hasSvelteKit?: boolean; }; } interface CodeModification { filePath: string; action: 'create' | 'modify' | 'append'; content: string; description: string; } interface InstallationResult { success: boolean; framework: FrameworkInfo$2; modifications: CodeModification[]; errors: string[]; nextSteps: string[]; } declare class AutoInstallationWizard { protected apiKey: string; protected projectRoot: string; protected framework: FrameworkInfo$2 | null; constructor(apiKey: string, projectRoot?: string); /** * Simple version comparison utility */ private compareVersions; private isVersionGte; private getMajorVersion; /** * Main installation method - detects framework and auto-installs */ install(): Promise<InstallationResult>; /** * Detect the current framework and project setup */ detectFramework(): Promise<FrameworkInfo$2>; /** * Install the SDK package */ protected installPackage(): Promise<void>; /** * Generate code modifications based on framework */ protected generateModifications(): Promise<CodeModification[]>; /** * Generate React-specific modifications */ private generateReactModifications; /** * Generate Next.js-specific modifications */ private generateNextJSModifications; /** * Generate Astro-specific modifications */ private generateAstroModifications; /** * Generate Nuxt-specific modifications */ private generateNuxtModifications; /** * Generate Remix-specific modifications */ private generateRemixModifications; /** * Generate Vue-specific modifications */ private generateVueModifications; /** * Generate Angular-specific modifications */ private generateAngularModifications; /** * Generate Svelte-specific modifications */ private generateSvelteModifications; /** * Generate vanilla JS/TS modifications */ private generateVanillaModifications; /** * Generate Gatsby-specific modifications */ private generateGatsbyModifications; /** * Apply modifications to the codebase */ protected applyModifications(modifications: CodeModification[]): Promise<void>; /** * Generate next steps for the user */ private generateNextSteps; private findReactAppFile; private findVueMainFile; private findSvelteMainFile; private findHTMLFile; private injectReactProvider; private injectNextJSAppRouter; private injectNextJSPagesRouter; private injectRemixProvider; private injectVuePlugin; private injectAngularModule; private injectAngularStandaloneInit; private injectSvelteStore; private injectSvelteKitLayout; private injectVanillaScript; /** * Inject Astro layout with HumanBehavior component */ private injectAstroLayout; private injectNuxtConfig; private injectGatsbyLayout; private injectGatsbyBrowser; /** * Helper method to find the best environment file for a framework */ private findBestEnvFile; /** * Helper method to create or append to environment files */ private createEnvironmentModification; } /** * AI-Enhanced HumanBehavior SDK Auto-Installation Wizard * * This wizard uses AI to intelligently detect frameworks, analyze code patterns, * and generate optimal integration code that's both future-proof and backward-compatible. * * 🚀 KEY FEATURES: * - AI-powered framework detection beyond package.json * - Intelligent code pattern analysis * - Future-proof integration strategies * - Backward compatibility with legacy frameworks * - Adaptive code generation for new frameworks * - Smart conflict resolution * - Learning from user feedback * - Centralized AI service (no user API keys required) */ interface AICodeAnalysis { framework: FrameworkInfo$2; confidence: number; patterns: string[]; conflicts: string[]; recommendations: string[]; integrationStrategy: 'provider' | 'plugin' | 'module' | 'script' | 'standalone'; compatibilityMode: 'modern' | 'legacy' | 'hybrid'; } interface AIInstallationResult extends InstallationResult { aiAnalysis: AICodeAnalysis; learningData: { patterns: string[]; framework: string; success: boolean; userFeedback?: string; }; } /** * Centralized AI Service Interface * This runs on your backend infrastructure, not in the user's environment */ interface CentralizedAIService$1 { analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis>; resolveConflicts(conflicts: string[], framework: FrameworkInfo$2): Promise<string[]>; generateOptimizations(framework: FrameworkInfo$2, patterns: string[]): Promise<string[]>; } declare class AIEnhancedInstallationWizard extends AutoInstallationWizard { private aiService; private learningCache; private patternDatabase; constructor(apiKey: string, projectRoot?: string, aiService?: CentralizedAIService$1); /** * AI-enhanced installation with intelligent analysis */ install(): Promise<AIInstallationResult>; /** * AI-powered code analysis using centralized service */ performAICodeAnalysis(): Promise<AICodeAnalysis>; /** * Scan project files for analysis */ private scanProjectFiles; /** * Check if file is relevant for analysis */ private isRelevantFile; /** * Extract code samples for AI analysis */ private extractCodeSamples; /** * Extract relevant code patterns */ private extractCodePatterns; /** * AI-enhanced framework detection */ private detectFrameworkWithAI; /** * Generate AI-optimized modifications */ private generateAIOptimizedModifications; /** * Enhance modification with AI insights */ private enhanceModificationWithAI; /** * Generate AI-specific optimizations */ private generateAIOptimizations; /** * Apply modifications with AI conflict resolution */ private applyModificationsWithAI; /** * Detect potential conflicts */ private detectConflicts; /** * Resolve conflicts with AI */ private resolveConflicts; /** * Apply single modification */ private applyModification; /** * Generate AI-enhanced next steps */ private generateAINextSteps; /** * Learn from installation for future improvements */ private learnFromInstallation; /** * Load learning data from disk */ private loadLearningData; /** * Save learning data to disk */ private saveLearningData; /** * Get AI insights for a specific framework */ getAIInsights(frameworkName: string): any[]; /** * Get learning statistics */ getLearningStats(): any; } /** * Browser-based AI installation wizard */ declare class AIBrowserInstallationWizard { private apiKey; private aiService; constructor(apiKey: string, aiService?: CentralizedAIService$1); install(): Promise<AIInstallationResult>; private performBrowserAIAnalysis; private detectBrowserFramework; private analyzeBrowserPatterns; private generateAIBrowserModifications; } /** * AI-Enhanced HumanBehavior SDK Auto-Installation CLI * * Usage: npx humanbehavior-js ai-auto-install [api-key] * * This tool uses AI to intelligently detect frameworks, analyze code patterns, * and generate optimal integration code that's both future-proof and backward-compatible. */ interface AICLIOptions { apiKey?: string; projectPath?: string; yes?: boolean; dryRun?: boolean; framework?: string; } declare class AIAutoInstallCLI { private options; constructor(options: AICLIOptions); run(): Promise<void>; private getApiKey; private confirmInstallation; private chooseFramework; private displayResults; } /** * HumanBehavior SDK Auto-Installation CLI * * Usage: npx humanbehavior-js auto-install [api-key] * * This tool automatically detects the user's framework and modifies their codebase * to integrate the SDK with minimal user intervention. */ interface CLIOptions { apiKey?: string; projectPath?: string; yes?: boolean; dryRun?: boolean; } declare class AutoInstallCLI { private options; constructor(options: CLIOptions); run(): Promise<void>; private getApiKey; private chooseFramework; private confirmInstallation; private displayResults; } /** * Remote AI Service Implementation * * This connects to your deployed Lambda function via API Gateway */ interface FrameworkInfo$1 { name: string; type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'astro' | 'gatsby' | 'node'; bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup'; packageManager?: 'npm' | 'yarn' | 'pnpm'; hasTypeScript?: boolean; hasRouter?: boolean; projectRoot?: string; version?: string; majorVersion?: number; features?: { hasReact18?: boolean; hasVue3?: boolean; hasNuxt3?: boolean; hasAngularStandalone?: boolean; hasNextAppRouter?: boolean; hasSvelteKit?: boolean; }; } interface RemoteAIServiceConfig { apiEndpoint: string; timeout?: number; } declare class RemoteAIService { private config; constructor(config: RemoteAIServiceConfig); /** * Analyze code patterns using your deployed AI service */ analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis>; /** * Resolve conflicts using your deployed AI service */ resolveConflicts(conflicts: string[], framework: FrameworkInfo$1): Promise<string[]>; /** * Generate optimizations using your deployed AI service */ generateOptimizations(framework: FrameworkInfo$1, patterns: string[]): Promise<string[]>; /** * Heuristic analysis fallback */ private performHeuristicAnalysis; /** * Heuristic conflict resolution */ private resolveConflictsHeuristic; /** * Heuristic optimization generation */ private generateOptimizationsHeuristic; } /** * Centralized AI Service Implementation * * This service runs on your backend infrastructure and provides AI-powered * code analysis without requiring users to provide their own API keys. * * The service can be deployed as: * - AWS Lambda function * - Docker container * - Express.js server * - Cloud function */ interface FrameworkInfo { name: string; type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'astro' | 'node'; bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup'; packageManager?: 'npm' | 'yarn' | 'pnpm'; hasTypeScript?: boolean; hasRouter?: boolean; projectRoot?: string; } interface CentralizedAIServiceConfig { openaiApiKey: string; openaiModel?: string; maxTokens?: number; temperature?: number; enableCaching?: boolean; cacheTTL?: number; } /** * Centralized AI Service Implementation * This runs on your backend infrastructure */ declare class CentralizedAIService { private config; private cache; private openai; constructor(config: CentralizedAIServiceConfig); /** * Initialize OpenAI client */ private initializeOpenAI; /** * Analyze code patterns using AI */ analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis>; /** * Resolve conflicts using AI */ resolveConflicts(conflicts: string[], framework: FrameworkInfo): Promise<string[]>; /** * Generate optimizations using AI */ generateOptimizations(framework: FrameworkInfo, patterns: string[]): Promise<string[]>; /** * Perform AI analysis */ private performAIAnalysis; /** * Build analysis prompt */ private buildAnalysisPrompt; /** * Build conflict resolution prompt */ private buildConflictResolutionPrompt; /** * Build optimization prompt */ private buildOptimizationPrompt; /** * Parse analysis result */ private parseAnalysisResult; /** * Parse conflict resolutions */ private parseConflictResolutions; /** * Parse optimizations */ private parseOptimizations; /** * Heuristic analysis fallback */ private performHeuristicAnalysis; /** * Heuristic conflict resolution */ private resolveConflictsHeuristic; /** * Heuristic optimization generation */ private generateOptimizationsHeuristic; /** * Generate cache key */ private generateCacheKey; /** * Check if cache is valid */ private isCacheValid; /** * Get default analysis */ private getDefaultAnalysis; /** * Get service statistics */ getStats(): { cacheSize: number; config: { model: string | undefined; maxTokens: number | undefined; temperature: number | undefined; caching: boolean | undefined; }; openaiAvailable: boolean; }; /** * Clear cache */ clearCache(): void; } export { AIAutoInstallCLI, AIBrowserInstallationWizard, AIEnhancedInstallationWizard, AutoInstallCLI, AutoInstallationWizard, CentralizedAIService, AutoInstallationWizard as InstallWizard, RemoteAIService }; export type { AICodeAnalysis, AIInstallationResult, CentralizedAIServiceConfig, CodeModification, FrameworkInfo$2 as FrameworkInfo, InstallationResult, RemoteAIServiceConfig };