99 LDAIAgentRequestConfig ,
1010 LDAICompletionConfig ,
1111 LDAICompletionConfigDefault ,
12+ LDAIConfigDefault ,
1213 LDAIConfigDefaultKind ,
1314 LDAIConfigKind ,
1415 LDAIConfigMode ,
@@ -42,6 +43,8 @@ const INIT_TRACK_CONTEXT: LDContext = {
4243 anonymous : true ,
4344} ;
4445
46+ const disabledAIConfig : LDAIConfigDefault = { enabled : false } ;
47+
4548export class LDAIClientImpl implements LDAIClient {
4649 private _logger ?: LDLogger ;
4750
@@ -141,7 +144,7 @@ export class LDAIClientImpl implements LDAIClient {
141144 const judge = await this . createJudge (
142145 judgeConfig . key ,
143146 context ,
144- { enabled : false } ,
147+ undefined ,
145148 variables ,
146149 defaultAiProvider ,
147150 ) ;
@@ -171,12 +174,11 @@ export class LDAIClientImpl implements LDAIClient {
171174 async completionConfig (
172175 key : string ,
173176 context : LDContext ,
174- defaultValue : LDAICompletionConfigDefault ,
177+ defaultValue ? : LDAICompletionConfigDefault ,
175178 variables ?: Record < string , unknown > ,
176179 ) : Promise < LDAICompletionConfig > {
177180 this . _ldClient . track ( TRACK_USAGE_COMPLETION_CONFIG , context , key , 1 ) ;
178-
179- return this . _completionConfig ( key , context , defaultValue , variables ) ;
181+ return this . _completionConfig ( key , context , defaultValue ?? disabledAIConfig , variables ) ;
180182 }
181183
182184 /**
@@ -185,7 +187,7 @@ export class LDAIClientImpl implements LDAIClient {
185187 async config (
186188 key : string ,
187189 context : LDContext ,
188- defaultValue : LDAICompletionConfigDefault ,
190+ defaultValue ? : LDAICompletionConfigDefault ,
189191 variables ?: Record < string , unknown > ,
190192 ) : Promise < LDAICompletionConfig > {
191193 return this . completionConfig ( key , context , defaultValue , variables ) ;
@@ -204,23 +206,27 @@ export class LDAIClientImpl implements LDAIClient {
204206 async judgeConfig (
205207 key : string ,
206208 context : LDContext ,
207- defaultValue : LDAIJudgeConfigDefault ,
209+ defaultValue ? : LDAIJudgeConfigDefault ,
208210 variables ?: Record < string , unknown > ,
209211 ) : Promise < LDAIJudgeConfig > {
210212 this . _ldClient . track ( TRACK_USAGE_JUDGE_CONFIG , context , key , 1 ) ;
211-
212- return this . _judgeConfig ( key , context , defaultValue , variables ) ;
213+ return this . _judgeConfig ( key , context , defaultValue ?? disabledAIConfig , variables ) ;
213214 }
214215
215216 async agentConfig (
216217 key : string ,
217218 context : LDContext ,
218- defaultValue : LDAIAgentConfigDefault ,
219+ defaultValue ? : LDAIAgentConfigDefault ,
219220 variables ?: Record < string , unknown > ,
220221 ) : Promise < LDAIAgentConfig > {
221222 this . _ldClient . track ( TRACK_USAGE_AGENT_CONFIG , context , key , 1 ) ;
222-
223- const config = await this . _evaluate ( key , context , defaultValue , 'agent' , variables ) ;
223+ const config = await this . _evaluate (
224+ key ,
225+ context ,
226+ defaultValue ?? disabledAIConfig ,
227+ 'agent' ,
228+ variables ,
229+ ) ;
224230 return config as LDAIAgentConfig ;
225231 }
226232
@@ -230,7 +236,7 @@ export class LDAIClientImpl implements LDAIClient {
230236 async agent (
231237 key : string ,
232238 context : LDContext ,
233- defaultValue : LDAIAgentConfigDefault ,
239+ defaultValue ? : LDAIAgentConfigDefault ,
234240 variables ?: Record < string , unknown > ,
235241 ) : Promise < LDAIAgentConfig > {
236242 return this . agentConfig ( key , context , defaultValue , variables ) ;
@@ -254,7 +260,7 @@ export class LDAIClientImpl implements LDAIClient {
254260 const agent = await this . _evaluate (
255261 config . key ,
256262 context ,
257- config . defaultValue ,
263+ config . defaultValue ?? disabledAIConfig ,
258264 'agent' ,
259265 config . variables ,
260266 ) ;
@@ -278,13 +284,17 @@ export class LDAIClientImpl implements LDAIClient {
278284 async createChat (
279285 key : string ,
280286 context : LDContext ,
281- defaultValue : LDAICompletionConfigDefault ,
287+ defaultValue ? : LDAICompletionConfigDefault ,
282288 variables ?: Record < string , unknown > ,
283289 defaultAiProvider ?: SupportedAIProvider ,
284290 ) : Promise < TrackedChat | undefined > {
285291 this . _ldClient . track ( TRACK_USAGE_CREATE_CHAT , context , key , 1 ) ;
286-
287- const config = await this . _completionConfig ( key , context , defaultValue , variables ) ;
292+ const config = await this . _completionConfig (
293+ key ,
294+ context ,
295+ defaultValue ?? disabledAIConfig ,
296+ variables ,
297+ ) ;
288298
289299 if ( ! config . enabled || ! config . tracker ) {
290300 this . _logger ?. info ( `Chat configuration is disabled: ${ key } ` ) ;
@@ -309,7 +319,7 @@ export class LDAIClientImpl implements LDAIClient {
309319 async createJudge (
310320 key : string ,
311321 context : LDContext ,
312- defaultValue : LDAIJudgeConfigDefault ,
322+ defaultValue ? : LDAIJudgeConfigDefault ,
313323 variables ?: Record < string , unknown > ,
314324 defaultAiProvider ?: SupportedAIProvider ,
315325 ) : Promise < Judge | undefined > {
@@ -334,7 +344,12 @@ export class LDAIClientImpl implements LDAIClient {
334344 response_to_evaluate : '{{response_to_evaluate}}' ,
335345 } ;
336346
337- const judgeConfig = await this . _judgeConfig ( key , context , defaultValue , extendedVariables ) ;
347+ const judgeConfig = await this . _judgeConfig (
348+ key ,
349+ context ,
350+ defaultValue ?? disabledAIConfig ,
351+ extendedVariables ,
352+ ) ;
338353
339354 if ( ! judgeConfig . enabled || ! judgeConfig . tracker ) {
340355 this . _logger ?. info ( `Judge configuration is disabled: ${ key } ` ) ;
@@ -359,7 +374,7 @@ export class LDAIClientImpl implements LDAIClient {
359374 async initChat (
360375 key : string ,
361376 context : LDContext ,
362- defaultValue : LDAICompletionConfigDefault ,
377+ defaultValue ? : LDAICompletionConfigDefault ,
363378 variables ?: Record < string , unknown > ,
364379 defaultAiProvider ?: SupportedAIProvider ,
365380 ) : Promise < TrackedChat | undefined > {
0 commit comments