11import { LDLogger } from '@launchdarkly/js-server-sdk-common' ;
22
33import { LDAIConfig } from '../config/LDAIConfig' ;
4- import { LDAIConfigTracker } from '../config/LDAIConfigTracker' ;
5- import { AIProvider } from '../providers/AIProvider' ;
6- import { TrackedChat } from './TrackedChat' ;
4+ import { AIProvider } from './AIProvider' ;
75
86/**
97 * List of supported AI providers.
@@ -21,41 +19,19 @@ export const SUPPORTED_AI_PROVIDERS = [
2119export type SupportedAIProvider = ( typeof SUPPORTED_AI_PROVIDERS ) [ number ] ;
2220
2321/**
24- * Factory for creating TrackedChat instances based on the provider configuration.
22+ * Factory for creating AIProvider instances based on the provider configuration.
2523 */
26- export class TrackedChatFactory {
24+ export class AIProviderFactory {
2725 /**
28- * Create a TrackedChat instance based on the AI configuration.
26+ * Create an AIProvider instance based on the AI configuration.
2927 * This method attempts to load provider-specific implementations dynamically.
3028 * Returns undefined if the provider is not supported.
3129 *
3230 * @param aiConfig The AI configuration
33- * @param tracker The tracker for AI operations
3431 * @param logger Optional logger for logging provider initialization
3532 * @param defaultAiProvider Optional default AI provider to use
3633 */
3734 static async create (
38- aiConfig : LDAIConfig ,
39- tracker : LDAIConfigTracker ,
40- logger ?: LDLogger ,
41- defaultAiProvider ?: SupportedAIProvider ,
42- ) : Promise < TrackedChat | undefined > {
43- const provider = await this . _createAIProvider ( aiConfig , logger , defaultAiProvider ) ;
44- if ( ! provider ) {
45- logger ?. warn (
46- `Provider is not supported or failed to initialize: ${ aiConfig . provider ?. name ?? 'unknown' } ` ,
47- ) ;
48- return undefined ;
49- }
50-
51- return new TrackedChat ( aiConfig , tracker , provider ) ;
52- }
53-
54- /**
55- * Create an AIProvider instance based on the AI configuration.
56- * This method attempts to load provider-specific implementations dynamically.
57- */
58- private static async _createAIProvider (
5935 aiConfig : LDAIConfig ,
6036 logger ?: LDLogger ,
6137 defaultAiProvider ?: SupportedAIProvider ,
@@ -74,6 +50,10 @@ export class TrackedChatFactory {
7450 }
7551 }
7652
53+ // If no provider was successfully created, log a warning
54+ logger ?. warn (
55+ `Provider is not supported or failed to initialize: ${ aiConfig . provider ?. name ?? 'unknown' } ` ,
56+ ) ;
7757 return undefined ;
7858 }
7959
0 commit comments