@@ -17,6 +17,7 @@ import type {
1717 ServerProvider ,
1818 ServerProviderState ,
1919 ModelCapabilities ,
20+ ProviderOptionDescriptor ,
2021 ServerProviderModel ,
2122 ServerProviderSkill ,
2223} from "@t3tools/contracts" ;
@@ -44,7 +45,7 @@ export interface CodexAppServerProviderSnapshot {
4445 readonly skills : ReadonlyArray < ServerProviderSkill > ;
4546}
4647
47- const REASONING_EFFORT_LABELS : Record < CodexSchema . V2ModelListResponse__ReasoningEffort , string > = {
48+ const REASONING_EFFORT_LABELS : Readonly < Record < string , string > > = {
4849 none : "None" ,
4950 minimal : "Minimal" ,
5051 low : "Low" ,
@@ -53,6 +54,12 @@ const REASONING_EFFORT_LABELS: Record<CodexSchema.V2ModelListResponse__Reasoning
5354 xhigh : "Extra High" ,
5455} ;
5556
57+ const DEFAULT_SERVICE_TIER_ID = "default" ;
58+
59+ function reasoningEffortLabel ( reasoningEffort : string ) : string {
60+ return REASONING_EFFORT_LABELS [ reasoningEffort ] ?? reasoningEffort ;
61+ }
62+
5663function codexAccountAuthLabel ( account : CodexSchema . V2GetAccountResponse [ "account" ] ) {
5764 if ( ! account ) return undefined ;
5865 if ( account . type === "apiKey" ) return "OpenAI API Key" ;
@@ -93,46 +100,71 @@ function codexAccountEmail(account: CodexSchema.V2GetAccountResponse["account"])
93100 return account . email ;
94101}
95102
96- function mapCodexModelCapabilities (
103+ export function mapCodexModelCapabilities (
97104 model : CodexSchema . V2ModelListResponse__Model ,
98105) : ModelCapabilities {
99106 const reasoningOptions = model . supportedReasoningEfforts . map ( ( { reasoningEffort } ) =>
100107 reasoningEffort === model . defaultReasoningEffort
101108 ? {
102109 id : reasoningEffort ,
103- label : REASONING_EFFORT_LABELS [ reasoningEffort ] ,
110+ label : reasoningEffortLabel ( reasoningEffort ) ,
104111 isDefault : true ,
105112 }
106113 : {
107114 id : reasoningEffort ,
108- label : REASONING_EFFORT_LABELS [ reasoningEffort ] ,
115+ label : reasoningEffortLabel ( reasoningEffort ) ,
109116 } ,
110117 ) ;
111118 const defaultReasoning = reasoningOptions . find ( ( option ) => option . isDefault ) ?. id ;
112- const supportsFastMode = ( model . additionalSpeedTiers ?? [ ] ) . includes ( "fast" ) ;
119+ const serviceTiers =
120+ model . serviceTiers && model . serviceTiers . length > 0
121+ ? model . serviceTiers
122+ : ( model . additionalSpeedTiers ?? [ ] ) . map ( ( id ) => ( {
123+ id,
124+ name : id === "fast" ? "Fast" : id ,
125+ description : "" ,
126+ } ) ) ;
127+ const catalogDefaultServiceTier = serviceTiers . some (
128+ ( tier ) => tier . id === model . defaultServiceTier ,
129+ )
130+ ? model . defaultServiceTier
131+ : null ;
132+ const defaultServiceTier = catalogDefaultServiceTier ?? DEFAULT_SERVICE_TIER_ID ;
133+ const optionDescriptors : ProviderOptionDescriptor [ ] = [ ] ;
134+
135+ if ( reasoningOptions . length > 0 ) {
136+ optionDescriptors . push ( {
137+ id : "reasoningEffort" ,
138+ label : "Reasoning" ,
139+ type : "select" ,
140+ options : reasoningOptions ,
141+ ...( defaultReasoning ? { currentValue : defaultReasoning } : { } ) ,
142+ } ) ;
143+ }
144+ if ( serviceTiers . length > 0 ) {
145+ optionDescriptors . push ( {
146+ id : "serviceTier" ,
147+ label : "Service Tier" ,
148+ type : "select" ,
149+ options : [
150+ {
151+ id : DEFAULT_SERVICE_TIER_ID ,
152+ label : "Standard" ,
153+ ...( defaultServiceTier === DEFAULT_SERVICE_TIER_ID ? { isDefault : true } : { } ) ,
154+ } ,
155+ ...serviceTiers . map ( ( tier ) => ( {
156+ id : tier . id ,
157+ label : tier . name ,
158+ ...( tier . description ? { description : tier . description } : { } ) ,
159+ ...( defaultServiceTier === tier . id ? { isDefault : true } : { } ) ,
160+ } ) ) ,
161+ ] ,
162+ currentValue : defaultServiceTier ,
163+ } ) ;
164+ }
165+
113166 return createModelCapabilities ( {
114- optionDescriptors : [
115- ...( reasoningOptions . length > 0
116- ? [
117- {
118- id : "reasoningEffort" ,
119- label : "Reasoning" ,
120- type : "select" as const ,
121- options : reasoningOptions ,
122- ...( defaultReasoning ? { currentValue : defaultReasoning } : { } ) ,
123- } ,
124- ]
125- : [ ] ) ,
126- ...( supportsFastMode
127- ? [
128- {
129- id : "fastMode" ,
130- label : "Fast Mode" ,
131- type : "boolean" as const ,
132- } ,
133- ]
134- : [ ] ) ,
135- ] ,
167+ optionDescriptors,
136168 } ) ;
137169}
138170
0 commit comments