humanbehavior-js
Version:
SDK for HumanBehavior session and event recording
159 lines • 4.02 kB
TypeScript
/**
* 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
*/
import { AICodeAnalysis } from '../ai/ai-install-wizard';
export 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;
}
export interface CentralizedAIServiceConfig {
openaiApiKey: string;
openaiModel?: string;
maxTokens?: number;
temperature?: number;
enableCaching?: boolean;
cacheTTL?: number;
}
export interface AIAnalysisRequest {
codeSamples: string[];
projectType?: string;
userAgent?: string;
timestamp: string;
}
export interface AIAnalysisResponse {
analysis: AICodeAnalysis;
processingTime: number;
cacheHit?: boolean;
modelUsed: string;
}
export interface ConflictResolutionRequest {
conflicts: string[];
framework: FrameworkInfo;
codeContext?: string;
}
export interface OptimizationRequest {
framework: FrameworkInfo;
patterns: string[];
projectContext?: string;
}
/**
* Centralized AI Service Implementation
* This runs on your backend infrastructure
*/
export 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;
}
/**
* Express.js server implementation
*/
export declare function createAIServiceServer(config: CentralizedAIServiceConfig): any;
/**
* AWS Lambda handler
*/
export declare function lambdaHandler(event: any, context: any): Promise<{
statusCode: number;
body: string;
}>;
//# sourceMappingURL=centralized-ai-service.d.ts.map