@@ -926,6 +926,28 @@ export namespace Provider {
926926
927927 export class Service extends ServiceMap . Service < Service , Interface > ( ) ( "@opencode/Provider" ) { }
928928
929+ function cost ( c : ModelsDev . Model [ "cost" ] ) : Model [ "cost" ] {
930+ const result : Model [ "cost" ] = {
931+ input : c ?. input ?? 0 ,
932+ output : c ?. output ?? 0 ,
933+ cache : {
934+ read : c ?. cache_read ?? 0 ,
935+ write : c ?. cache_write ?? 0 ,
936+ } ,
937+ }
938+ if ( c ?. context_over_200k ) {
939+ result . experimentalOver200K = {
940+ cache : {
941+ read : c . context_over_200k . cache_read ?? 0 ,
942+ write : c . context_over_200k . cache_write ?? 0 ,
943+ } ,
944+ input : c . context_over_200k . input ,
945+ output : c . context_over_200k . output ,
946+ }
947+ }
948+ return result
949+ }
950+
929951 function fromModelsDevModel ( provider : ModelsDev . Provider , model : ModelsDev . Model ) : Model {
930952 const m : Model = {
931953 id : ModelID . make ( model . id ) ,
@@ -940,24 +962,7 @@ export namespace Provider {
940962 status : model . status ?? "active" ,
941963 headers : { } ,
942964 options : { } ,
943- cost : {
944- input : model . cost ?. input ?? 0 ,
945- output : model . cost ?. output ?? 0 ,
946- cache : {
947- read : model . cost ?. cache_read ?? 0 ,
948- write : model . cost ?. cache_write ?? 0 ,
949- } ,
950- experimentalOver200K : model . cost ?. context_over_200k
951- ? {
952- cache : {
953- read : model . cost . context_over_200k . cache_read ?? 0 ,
954- write : model . cost . context_over_200k . cache_write ?? 0 ,
955- } ,
956- input : model . cost . context_over_200k . input ,
957- output : model . cost . context_over_200k . output ,
958- }
959- : undefined ,
960- } ,
965+ cost : cost ( model . cost ) ,
961966 limit : {
962967 context : model . limit . context ,
963968 input : model . limit . input ,
@@ -994,13 +999,31 @@ export namespace Provider {
994999 }
9951000
9961001 export function fromModelsDevProvider ( provider : ModelsDev . Provider ) : Info {
1002+ const models : Record < string , Model > = { }
1003+ for ( const [ key , model ] of Object . entries ( provider . models ) ) {
1004+ models [ key ] = fromModelsDevModel ( provider , model )
1005+ for ( const [ mode , opts ] of Object . entries ( model . experimental ?. modes ?? { } ) ) {
1006+ const id = `${ model . id } -${ mode } `
1007+ const m = fromModelsDevModel ( provider , model )
1008+ m . id = ModelID . make ( id )
1009+ m . name = `${ model . name } ${ mode [ 0 ] . toUpperCase ( ) } ${ mode . slice ( 1 ) } `
1010+ if ( opts . cost ) m . cost = mergeDeep ( m . cost , cost ( opts . cost ) )
1011+ // convert body params to camelCase for ai sdk compatibility
1012+ if ( opts . provider ?. body )
1013+ m . options = Object . fromEntries (
1014+ Object . entries ( opts . provider . body ) . map ( ( [ k , v ] ) => [ k . replace ( / _ ( [ a - z ] ) / g, ( _ , c ) => c . toUpperCase ( ) ) , v ] ) ,
1015+ )
1016+ if ( opts . provider ?. headers ) m . headers = opts . provider . headers
1017+ models [ id ] = m
1018+ }
1019+ }
9971020 return {
9981021 id : ProviderID . make ( provider . id ) ,
9991022 source : "custom" ,
10001023 name : provider . name ,
10011024 env : provider . env ?? [ ] ,
10021025 options : { } ,
1003- models : mapValues ( provider . models , ( model ) => fromModelsDevModel ( provider , model ) ) ,
1026+ models,
10041027 }
10051028 }
10061029
0 commit comments