Skip to content

Commit 92323ec

Browse files
authored
fix: Rename to AIProviderFactory for more accurate naming (#949)
1 parent 8553f24 commit 92323ec

File tree

5 files changed

+21
-33
lines changed

5 files changed

+21
-33
lines changed

packages/sdk/server-ai/src/LDAIClientImpl.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Mustache from 'mustache';
33
import { LDContext, LDLogger } from '@launchdarkly/js-server-sdk-common';
44

55
import { LDAIAgent, LDAIAgentConfig, LDAIAgentDefaults } from './api/agents';
6-
import { SupportedAIProvider, TrackedChat, TrackedChatFactory } from './api/chat';
6+
import { TrackedChat } from './api/chat';
77
import {
88
LDAIConfig,
99
LDAIConfigTracker,
@@ -16,6 +16,7 @@ import {
1616
VercelAISDKProvider,
1717
} from './api/config';
1818
import { LDAIClient } from './api/LDAIClient';
19+
import { AIProviderFactory, SupportedAIProvider } from './api/providers';
1920
import { LDAIConfigMapper } from './LDAIConfigMapper';
2021
import { LDAIConfigTrackerImpl } from './LDAIConfigTrackerImpl';
2122
import { LDClientMin } from './LDClientMin';
@@ -246,7 +247,13 @@ export class LDAIClientImpl implements LDAIClient {
246247
return undefined;
247248
}
248249

249-
// Create the TrackedChat instance based on the provider
250-
return TrackedChatFactory.create(aiConfig, aiConfig.tracker, this._logger, defaultAiProvider);
250+
// Create the AIProvider instance
251+
const provider = await AIProviderFactory.create(aiConfig, this._logger, defaultAiProvider);
252+
if (!provider) {
253+
return undefined;
254+
}
255+
256+
// Create the TrackedChat instance with the provider
257+
return new TrackedChat(aiConfig, aiConfig.tracker, provider);
251258
}
252259
}

packages/sdk/server-ai/src/api/LDAIClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { LDContext } from '@launchdarkly/js-server-sdk-common';
22

33
import { LDAIAgent, LDAIAgentConfig, LDAIAgentDefaults } from './agents';
4-
import { SupportedAIProvider, TrackedChat } from './chat';
4+
import { TrackedChat } from './chat';
55
import { LDAIConfig, LDAIDefaults } from './config/LDAIConfig';
6+
import { SupportedAIProvider } from './providers';
67

78
/**
89
* Interface for performing AI operations using LaunchDarkly.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './types';
22
export * from './TrackedChat';
3-
export * from './TrackedChatFactory';

packages/sdk/server-ai/src/api/chat/TrackedChatFactory.ts renamed to packages/sdk/server-ai/src/api/providers/AIProviderFactory.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { LDLogger } from '@launchdarkly/js-server-sdk-common';
22

33
import { 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 = [
2119
export 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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './AIProvider';
2+
export * from './AIProviderFactory';

0 commit comments

Comments
 (0)