11import { LDContext } from '@launchdarkly/js-server-sdk-common' ;
22
3- import { LDGenerationConfig } from '../src/api/config' ;
3+ import { LDAIDefaults } from '../src/api/config' ;
44import { LDAIClientImpl } from '../src/LDAIClientImpl' ;
55import { LDClientMin } from '../src/LDClientMin' ;
66
@@ -32,13 +32,14 @@ it('handles empty variables in template interpolation', () => {
3232it ( 'returns model config with interpolated prompts' , async ( ) => {
3333 const client = new LDAIClientImpl ( mockLdClient ) ;
3434 const key = 'test-flag' ;
35- const defaultValue : LDGenerationConfig = {
35+ const defaultValue : LDAIDefaults = {
3636 model : { modelId : 'test' , name : 'test-model' } ,
3737 prompt : [ ] ,
38+ enabled : true ,
3839 } ;
3940
4041 const mockVariation = {
41- model : { modelId : 'example-provider' , name : 'imagination' } ,
42+ model : { modelId : 'example-provider' , name : 'imagination' , temperature : 0.7 , maxTokens : 4096 } ,
4243 prompt : [
4344 { role : 'system' , content : 'Hello {{name}}' } ,
4445 { role : 'user' , content : 'Score: {{score}}' } ,
@@ -55,13 +56,11 @@ it('returns model config with interpolated prompts', async () => {
5556 const result = await client . modelConfig ( key , testContext , defaultValue , variables ) ;
5657
5758 expect ( result ) . toEqual ( {
58- config : {
59- model : { modelId : 'example-provider' , name : 'imagination' } ,
60- prompt : [
61- { role : 'system' , content : 'Hello John' } ,
62- { role : 'user' , content : 'Score: 42' } ,
63- ] ,
64- } ,
59+ model : { modelId : 'example-provider' , name : 'imagination' , temperature : 0.7 , maxTokens : 4096 } ,
60+ prompt : [
61+ { role : 'system' , content : 'Hello John' } ,
62+ { role : 'user' , content : 'Score: 42' } ,
63+ ] ,
6564 tracker : expect . any ( Object ) ,
6665 enabled : true ,
6766 } ) ;
@@ -70,7 +69,7 @@ it('returns model config with interpolated prompts', async () => {
7069it ( 'includes context in variables for prompt interpolation' , async ( ) => {
7170 const client = new LDAIClientImpl ( mockLdClient ) ;
7271 const key = 'test-flag' ;
73- const defaultValue : LDGenerationConfig = {
72+ const defaultValue : LDAIDefaults = {
7473 model : { modelId : 'test' , name : 'test-model' } ,
7574 prompt : [ ] ,
7675 } ;
@@ -84,13 +83,13 @@ it('includes context in variables for prompt interpolation', async () => {
8483
8584 const result = await client . modelConfig ( key , testContext , defaultValue ) ;
8685
87- expect ( result . config . prompt ?. [ 0 ] . content ) . toBe ( 'User key: test-user' ) ;
86+ expect ( result . prompt ?. [ 0 ] . content ) . toBe ( 'User key: test-user' ) ;
8887} ) ;
8988
9089it ( 'handles missing metadata in variation' , async ( ) => {
9190 const client = new LDAIClientImpl ( mockLdClient ) ;
9291 const key = 'test-flag' ;
93- const defaultValue : LDGenerationConfig = {
92+ const defaultValue : LDAIDefaults = {
9493 model : { modelId : 'test' , name : 'test-model' } ,
9594 prompt : [ ] ,
9695 } ;
@@ -105,10 +104,8 @@ it('handles missing metadata in variation', async () => {
105104 const result = await client . modelConfig ( key , testContext , defaultValue ) ;
106105
107106 expect ( result ) . toEqual ( {
108- config : {
109- model : { modelId : 'example-provider' , name : 'imagination' } ,
110- prompt : [ { role : 'system' , content : 'Hello' } ] ,
111- } ,
107+ model : { modelId : 'example-provider' , name : 'imagination' } ,
108+ prompt : [ { role : 'system' , content : 'Hello' } ] ,
112109 tracker : expect . any ( Object ) ,
113110 enabled : false ,
114111 } ) ;
@@ -117,17 +114,19 @@ it('handles missing metadata in variation', async () => {
117114it ( 'passes the default value to the underlying client' , async ( ) => {
118115 const client = new LDAIClientImpl ( mockLdClient ) ;
119116 const key = 'non-existent-flag' ;
120- const defaultValue : LDGenerationConfig = {
117+ const defaultValue : LDAIDefaults = {
121118 model : { modelId : 'default-model' , name : 'default' } ,
122119 prompt : [ { role : 'system' , content : 'Default prompt' } ] ,
120+ enabled : true ,
123121 } ;
124122
125123 mockLdClient . variation . mockResolvedValue ( defaultValue ) ;
126124
127125 const result = await client . modelConfig ( key , testContext , defaultValue ) ;
128126
129127 expect ( result ) . toEqual ( {
130- config : defaultValue ,
128+ model : defaultValue . model ,
129+ prompt : defaultValue . prompt ,
131130 tracker : expect . any ( Object ) ,
132131 enabled : false ,
133132 } ) ;
0 commit comments