UNPKG

@entro314labs/ai-changelog-generator

Version:

AI-powered changelog generator with MCP server support - works with most providers, online and local models

230 lines (229 loc) 9.24 kB
/** * Helper functions that can be mixed into provider classes * Reduces code duplication by providing common implementations */ import { type ResolvedProviderModelConfig } from './model-config.js'; import type { ProviderConfig, ProviderModelDescriptor, ProviderResult } from '../core/base-provider.js'; interface ProviderCapabilities extends Record<string, boolean | number | string | undefined> { isHubProvider?: boolean; availableInHub?: boolean; } interface ProviderHelperHost { config: ProviderConfig; isAvailable(): boolean; generateCompletion(...args: any[]): Promise<ProviderResult>; getAvailableModels?(): ProviderModelDescriptor[] | Promise<ProviderModelDescriptor[]>; refreshAvailableModels?(): Promise<void>; getModelRecommendation?(commitDetails: any): any; getProviderInfo?(): string | Record<string, any>; getCapabilities(modelName?: string): ProviderCapabilities; getName?(): string; testConnection?(): Promise<ProviderResult>; testModel?(modelName: string): Promise<ProviderResult>; getProviderConfig?(): Record<string, any>; getProviderModelConfig?(): ResolvedProviderModelConfig | Record<string, any>; buildClientOptions?(extraDefaults?: Record<string, any>): Record<string, any>; handleProviderError(error: Error, operation: string, context?: Record<string, any>): ProviderResult; initializeClient?(): void | Promise<boolean | ProviderResult>; } /** * Mixin that provides enhanced model recommendation logic with hub support * @param {string} providerName - Name of the provider * @returns {Object} Mixin methods */ export declare function ModelRecommendationMixin(providerName: any): { getModelRecommendation(this: ProviderHelperHost, commitDetails: any): { model: any; reason: string; } | { model: any; complexity: string; reasoning: string; isHubProvider: boolean; availableModels: number; }; selectOptimalModel(this: ProviderHelperHost, commitDetails: any): Promise<any>; selectModelForCapabilities(this: ProviderHelperHost, requiredCapabilities?: any[]): Promise<string>; }; /** * Mixin that provides standard connection testing * @param {string} providerName - Name of the provider * @returns {Object} Mixin methods */ export declare function ConnectionTestMixin(providerName: any): { testConnection(this: ProviderHelperHost): Promise<{ available: boolean; provider: any; timestamp: string; }>; }; /** * Mixin that provides standard model validation * @param {string} providerName - Name of the provider * @returns {Object} Mixin methods */ export declare function ModelValidationMixin(providerName: any): { validateModelAvailability(this: ProviderHelperHost, modelName: any): Promise<{ available: boolean; provider: any; timestamp: string; }>; }; /** * Mixin that provides standard capabilities lookup * @param {string} providerName - Name of the provider * @returns {Object} Mixin methods */ export declare function CapabilitiesMixin(providerName: any): { getCapabilities(this: ProviderHelperHost, modelName: any): ProviderCapabilities; /** * Enhanced capability testing - tests actual provider functionality * @param {Object} options - Test options * @returns {Promise<Object>} Detailed capability test results */ testCapabilities(this: ProviderHelperHost, options?: Record<string, any>): Promise<{ available: boolean; connection: boolean; modelAccess: boolean; capabilities: Record<string, any>; errors: string[]; performance: { connectionTime?: number; modelResponseTime?: number; tokensGenerated?: number; }; tested_at: string; }>; /** * Quick health check - lightweight version of testCapabilities * @returns {Promise<Object>} Basic health status */ quickHealthCheck(this: ProviderHelperHost): Promise<{ status: string; available: boolean; configured: boolean; timestamp: string; error?: string; }>; getSimilarModels(this: ProviderHelperHost, modelName: any, providedAvailableModels?: any[]): any[]; }; /** * Mixin that provides standard configuration handling * @param {string} providerName - Name of the provider * @param {Object} defaults - Default configuration values * @returns {Object} Mixin methods */ export declare function ConfigurationMixin(providerName: any, defaults?: Record<string, any>): { getProviderConfig(this: ProviderHelperHost): Record<string, any>; getProviderModelConfig(this: ProviderHelperHost): ResolvedProviderModelConfig; buildClientOptions(this: ProviderHelperHost, extraDefaults?: Record<string, any>): { [x: string]: any; }; getRequiredEnvVars(): string[]; getDefaultModel(this: ProviderHelperHost): any; getProviderInfo(this: ProviderHelperHost): { name: string; configured: boolean; config_keys: string[]; default_model: string; isHub: boolean; hubInfo?: { availableModels: number; supportedProviders: string[]; defaultProvider?: string; canDetectDeployments: boolean; sampleModels?: string[]; }; }; }; /** * Unified Provider Response Handler * Centralizes common patterns across all providers for consistency and maintainability */ export declare class ProviderResponseHandler { [key: string]: any; /** * Execute provider operation with standardized error handling and availability checking * @param {Object} provider - Provider instance * @param {string} operation - Operation name (e.g., 'generate_completion') * @param {Function} operationFn - Function to execute the operation * @param {Object} context - Additional context for error handling * @returns {Promise<Object>} Standardized response */ static executeWithErrorHandling(provider: ProviderHelperHost, operation: string, operationFn: () => Promise<Record<string, any>>, context?: Record<string, any>): Promise<ProviderResult | { available: boolean; provider: any; operation: any; error: any; alternatives: any[]; timestamp: string; }>; /** * Create standardized unavailable response * @param {string} providerName - Name of the provider * @param {string} operation - Operation that was attempted * @returns {Object} Error response */ static createUnavailableResponse(providerName: string, operation: string): { available: boolean; provider: any; operation: any; error: any; alternatives: any[]; timestamp: string; }; /** * Execute multiple provider operations in sequence with unified error handling * @param {Object} provider - Provider instance * @param {Array} operations - Array of {name, fn, context} operations * @returns {Promise<Array>} Array of results */ static executeMultiple(provider: ProviderHelperHost, operations: Array<{ name: string; fn: () => Promise<Record<string, any>>; context?: Record<string, any>; }>): Promise<any[]>; } /** * Mixin that provides standard error handling for providers * @param {string} providerName - Name of the provider * @returns {Object} Mixin methods */ export declare function ErrorHandlingMixin(providerName: any): { handleProviderError(this: ProviderHelperHost, error: any, operation: any, context?: Record<string, any>): { available: boolean; provider: any; operation: any; error: any; alternatives: any[]; timestamp: string; }; }; /** * Apply multiple mixins to a provider class. * * Mixins fill in behaviour a provider has NOT defined; they never replace it. * A plain `Object.assign` onto the prototype would overwrite the class body, * which silently disabled every provider-specific `getRequiredEnvVars`, * `getDefaultModel`, `getCapabilities`, `getProviderModelConfig`, * `getProviderInfo`, `testConnection` and `validateModelAvailability` in the * codebase — the opposite of what "providers should override if needed" implies. * * Own properties of the class prototype therefore win. Later mixins still fill * gaps left by earlier ones, so mixin ordering is unchanged for anything a * provider does not implement itself. * * @param {Function} ProviderClass - The provider class to enhance * @param {string} providerName - Name of the provider * @param {Array<Function>} mixins - Array of mixin functions to apply * @returns {Function} Enhanced provider class */ export declare function applyMixins(ProviderClass: any, providerName: any, mixins?: any[]): any; /** * Create a standardized provider class with all common functionality * @param {string} providerName - Name of the provider * @param {Object} options - Provider-specific options * @returns {Function} Base provider class with mixins applied */ export declare function createEnhancedProvider(providerName: any, options?: Record<string, any>): any; export {};