@@ -136,123 +136,126 @@ describe("ConfigProviderPlugin.Plugin", () => {
136136 )
137137
138138 it . effect ( "loads configured providers and applies later model overrides" , ( ) =>
139- withEnv ( { CUSTOM_API_KEY : "secret" } , ( ) => Effect . gen ( function * ( ) {
140- const catalog = yield * Catalog . Service
141- const integrations = yield * Integration . Service
142- const plugin = yield * PluginV2 . Service
143- const providerID = ProviderV2 . ID . make ( "custom" )
144- const modelID = ModelV2 . ID . make ( "chat" )
145- const config = Config . Service . of ( {
146- entries : ( ) =>
147- Effect . succeed ( [
148- new Config . Document ( {
149- type : "document" ,
150- info : decode ( {
151- model : "custom/first" ,
152- providers : {
153- custom : {
154- name : "Configured" ,
155- env : [ "CUSTOM_API_KEY" ] ,
156- api : { type : "native" , settings : { } } ,
157- request : request ( { first : "first" , shared : "first" } ) ,
158- models : {
159- chat : {
160- name : "First" ,
161- capabilities : { tools : true , input : [ "text" ] , output : [ "text" ] } ,
162- disabled : true ,
163- limit : { context : 100 , output : 50 } ,
164- cost : { input : 1 , output : 2 } ,
165- request : request ( { first : "first" , shared : "first" } , "retained" ) ,
166- variants : [
167- {
168- id : "fast" ,
169- headers : { first : "first" , shared : "first" } ,
170- } ,
171- ] ,
139+ withEnv ( { CUSTOM_API_KEY : "secret" } , ( ) =>
140+ Effect . gen ( function * ( ) {
141+ const catalog = yield * Catalog . Service
142+ const integrations = yield * Integration . Service
143+ const plugin = yield * PluginV2 . Service
144+ const providerID = ProviderV2 . ID . make ( "custom" )
145+ const modelID = ModelV2 . ID . make ( "chat" )
146+ const config = Config . Service . of ( {
147+ entries : ( ) =>
148+ Effect . succeed ( [
149+ new Config . Document ( {
150+ type : "document" ,
151+ info : decode ( {
152+ model : "custom/first" ,
153+ providers : {
154+ custom : {
155+ name : "Configured" ,
156+ env : [ "CUSTOM_API_KEY" ] ,
157+ api : { type : "native" , settings : { } } ,
158+ request : request ( { first : "first" , shared : "first" } ) ,
159+ models : {
160+ chat : {
161+ name : "First" ,
162+ capabilities : { tools : true , input : [ "text" ] , output : [ "text" ] } ,
163+ disabled : true ,
164+ limit : { context : 100 , output : 50 } ,
165+ cost : { input : 1 , output : 2 } ,
166+ request : request ( { first : "first" , shared : "first" } , "retained" ) ,
167+ variants : [
168+ {
169+ id : "fast" ,
170+ headers : { first : "first" , shared : "first" } ,
171+ } ,
172+ ] ,
173+ } ,
172174 } ,
173175 } ,
174176 } ,
175- } ,
177+ } ) ,
176178 } ) ,
177- } ) ,
178- new Config . Document ( {
179- type : "document" ,
180- info : decode ( {
181- model : "custom/default" ,
182- providers : {
183- custom : {
184- api : { type : "aisdk" , package : "custom-sdk " , url : "https://example.test " } ,
185- request : request ( { last : "last" , shared : "last" } ) ,
186- models : {
187- default : {
188- name : "Default" ,
189- } ,
190- chat : {
191- api : { id : "api-chat" } ,
192- name : "Last" ,
193- limit : { output : 75 } ,
194- request : request ( { last : "last" , shared : "last" } ) ,
195- variants : [
196- {
197- id : "fast" ,
198- headers : { last : "last" , shared : "last" } ,
199- } ,
200- {
201- id : "slow" ,
202- headers : { slow : "slow" } ,
203- } ,
204- ] ,
179+ new Config . Document ( {
180+ type : "document" ,
181+ info : decode ( {
182+ model : "custom/default" ,
183+ providers : {
184+ custom : {
185+ api : { type : "aisdk" , package : "custom-sdk" , url : "https://example.test" } ,
186+ request : request ( { last : "last " , shared : "last " } ) ,
187+ models : {
188+ default : {
189+ name : "Default" ,
190+ } ,
191+ chat : {
192+ api : { id : "api-chat" } ,
193+ name : "Last" ,
194+ limit : { output : 75 } ,
195+ request : request ( { last : "last" , shared : "last" } ) ,
196+ variants : [
197+ {
198+ id : "fast" ,
199+ headers : { last : "last" , shared : "last" } ,
200+ } ,
201+ {
202+ id : "slow" ,
203+ headers : { slow : "slow" } ,
204+ } ,
205+ ] ,
206+ } ,
205207 } ,
206208 } ,
207209 } ,
208- } ,
210+ } ) ,
209211 } ) ,
210- } ) ,
211- new Config . Document ( {
212- type : "document" ,
213- info : decode ( {
214- providers : {
215- custom : { name : "Renamed" } ,
216- } ,
212+ new Config . Document ( {
213+ type : "document" ,
214+ info : decode ( {
215+ providers : {
216+ custom : { name : "Renamed" } ,
217+ } ,
218+ } ) ,
217219 } ) ,
218- } ) ,
219- ] ) ,
220- } )
220+ ] ) ,
221+ } )
221222
222- yield * plugin . add ( {
223- ...ConfigProviderPlugin . Plugin ,
224- effect : ConfigProviderPlugin . Plugin . effect . pipe (
225- Effect . provideService ( Config . Service , config ) ,
226- Effect . provideService ( Catalog . Service , catalog ) ,
227- Effect . provideService ( Integration . Service , integrations ) ,
228- ) ,
229- } )
223+ yield * plugin . add ( {
224+ ...ConfigProviderPlugin . Plugin ,
225+ effect : ConfigProviderPlugin . Plugin . effect . pipe (
226+ Effect . provideService ( Config . Service , config ) ,
227+ Effect . provideService ( Catalog . Service , catalog ) ,
228+ Effect . provideService ( Integration . Service , integrations ) ,
229+ ) ,
230+ } )
230231
231- const provider = yield * catalog . provider . get ( providerID )
232- const model = yield * catalog . model . get ( providerID , modelID )
233- expect ( Option . getOrUndefined ( yield * catalog . model . default ( ) ) ?. id ) . toBe ( ModelV2 . ID . make ( "default" ) )
234- expect ( provider . name ) . toBe ( "Renamed" )
235- expect ( ( yield * integrations . get ( Integration . ID . make ( "custom" ) ) ) ?. methods ) . toContainEqual (
236- { type : "env" , names : [ "CUSTOM_API_KEY" ] } ,
237- )
238- expect ( ( yield * integrations . get ( Integration . ID . make ( "custom" ) ) ) ?. name ) . toBe ( "Renamed" )
239- expect ( provider . disabled ) . toBeUndefined ( )
240- expect ( provider . api ) . toEqual ( { type : "aisdk" , package : "custom-sdk" , url : "https://example.test" } )
241- expect ( provider . request . headers ) . toEqual ( { first : "first" , shared : "last" , last : "last" } )
242- expect ( model . api . id ) . toBe ( ModelV2 . ID . make ( "api-chat" ) )
243- expect ( model . name ) . toBe ( "Last" )
244- expect ( model . capabilities ) . toEqual ( { tools : true , input : [ "text" ] , output : [ "text" ] } )
245- expect ( model . enabled ) . toBe ( false )
246- expect ( model . limit ) . toEqual ( { context : 100 , output : 75 } )
247- expect ( model . cost ) . toEqual ( [ { input : 1 , output : 2 , cache : { read : 0 , write : 0 } , tier : undefined } ] )
248- expect ( model . request . headers ) . toEqual ( { first : "first" , shared : "last" , last : "last" } )
249- expect ( model . request . variant ) . toBe ( "retained" )
250- expect ( model . variants . map ( ( variant ) => variant . id ) ) . toEqual ( [
251- ModelV2 . VariantID . make ( "fast" ) ,
252- ModelV2 . VariantID . make ( "slow" ) ,
253- ] )
254- expect ( model . variants [ 0 ] ?. headers ) . toEqual ( { first : "first" , shared : "last" , last : "last" } )
255- expect ( model . variants [ 1 ] ?. headers ) . toEqual ( { slow : "slow" } )
256- } ) ) ,
232+ const provider = yield * catalog . provider . get ( providerID )
233+ const model = yield * catalog . model . get ( providerID , modelID )
234+ expect ( Option . getOrUndefined ( yield * catalog . model . default ( ) ) ?. id ) . toBe ( ModelV2 . ID . make ( "default" ) )
235+ expect ( provider . name ) . toBe ( "Renamed" )
236+ expect ( ( yield * integrations . get ( Integration . ID . make ( "custom" ) ) ) ?. methods ) . toContainEqual ( {
237+ type : "env" ,
238+ names : [ "CUSTOM_API_KEY" ] ,
239+ } )
240+ expect ( ( yield * integrations . get ( Integration . ID . make ( "custom" ) ) ) ?. name ) . toBe ( "Renamed" )
241+ expect ( provider . disabled ) . toBeUndefined ( )
242+ expect ( provider . api ) . toEqual ( { type : "aisdk" , package : "custom-sdk" , url : "https://example.test" } )
243+ expect ( provider . request . headers ) . toEqual ( { first : "first" , shared : "last" , last : "last" } )
244+ expect ( model . api . id ) . toBe ( ModelV2 . ID . make ( "api-chat" ) )
245+ expect ( model . name ) . toBe ( "Last" )
246+ expect ( model . capabilities ) . toEqual ( { tools : true , input : [ "text" ] , output : [ "text" ] } )
247+ expect ( model . enabled ) . toBe ( false )
248+ expect ( model . limit ) . toEqual ( { context : 100 , output : 75 } )
249+ expect ( model . cost ) . toEqual ( [ { input : 1 , output : 2 , cache : { read : 0 , write : 0 } , tier : undefined } ] )
250+ expect ( model . request . headers ) . toEqual ( { first : "first" , shared : "last" , last : "last" } )
251+ expect ( model . request . variant ) . toBe ( "retained" )
252+ expect ( model . variants . map ( ( variant ) => variant . id ) ) . toEqual ( [
253+ ModelV2 . VariantID . make ( "fast" ) ,
254+ ModelV2 . VariantID . make ( "slow" ) ,
255+ ] )
256+ expect ( model . variants [ 0 ] ?. headers ) . toEqual ( { first : "first" , shared : "last" , last : "last" } )
257+ expect ( model . variants [ 1 ] ?. headers ) . toEqual ( { slow : "slow" } )
258+ } ) ,
259+ ) ,
257260 )
258261} )
0 commit comments