@@ -14,6 +14,17 @@ const WELL_KNOWN_VARIANT_ORDER = [
1414 "max" ,
1515] as const ;
1616
17+ const VARIANT_DEFAULT_TARGET = 3 ;
18+ const VARIANT_DEFAULT_SCORE : Record < string , number > = {
19+ none : 0 ,
20+ minimal : 1 ,
21+ low : 2 ,
22+ medium : VARIANT_DEFAULT_TARGET ,
23+ high : 4 ,
24+ xhigh : 5 ,
25+ max : 6 ,
26+ } ;
27+
1728function defaultBehaviorOption ( ) : ModelBehaviorOption {
1829 return {
1930 value : null ,
@@ -71,6 +82,30 @@ const sortVariantKeys = (keys: string[]) =>
7182 return a . localeCompare ( b ) ;
7283 } ) ;
7384
85+ const getDefaultVariantKey = ( keys : string [ ] ) => {
86+ let selected : string | null = null ;
87+ let selectedScore : number | null = null ;
88+
89+ for ( const key of keys ) {
90+ const score = VARIANT_DEFAULT_SCORE [ key ] ;
91+ if ( score == null ) continue ;
92+ if ( selectedScore == null ) {
93+ selected = key ;
94+ selectedScore = score ;
95+ continue ;
96+ }
97+
98+ const distance = Math . abs ( score - VARIANT_DEFAULT_TARGET ) ;
99+ const selectedDistance = Math . abs ( selectedScore - VARIANT_DEFAULT_TARGET ) ;
100+ if ( distance < selectedDistance || ( distance === selectedDistance && score > selectedScore ) ) {
101+ selected = key ;
102+ selectedScore = score ;
103+ }
104+ }
105+
106+ return selected ?? keys [ 0 ] ?? null ;
107+ } ;
108+
74109const providerFamily = ( providerID : string , providerName ?: string | null ) => {
75110 const normalizedId = providerID . trim ( ) . toLowerCase ( ) ;
76111 if ( [ "anthropic" , "openai" , "google" , "opencode" ] . includes ( normalizedId ) ) {
@@ -167,6 +202,9 @@ export const getModelBehaviorOptions = (
167202 ] ;
168203} ;
169204
205+ const getDefaultModelBehaviorValue = ( model : ProviderModel ) =>
206+ getDefaultVariantKey ( sortVariantKeys ( getVariantKeys ( model ) ) ) ;
207+
170208export const sanitizeModelBehaviorValue = (
171209 providerID : string ,
172210 model : ProviderModel ,
@@ -188,14 +226,16 @@ export const getModelBehaviorSummary = (
188226) => {
189227 const options = getModelBehaviorOptions ( providerID , model , providerName ) ;
190228 const sanitized = sanitizeModelBehaviorValue ( providerID , model , value , providerName ) ;
191- const selected = options . find ( ( option ) => option . value === sanitized ) ?? options [ 0 ] ?? null ;
229+ const selectedValue = sanitized ?? getDefaultModelBehaviorValue ( model ) ;
230+ const selected = options . find ( ( option ) => option . value === selectedValue ) ?? options [ 0 ] ?? null ;
192231 const title = getBehaviorTitle ( providerID , model , getVariantKeys ( model ) , providerName ) ;
193232
194233 if ( options . length > 0 ) {
195234 return {
196235 title,
197236 label : selected ?. label ?? defaultBehaviorOption ( ) . label ,
198237 description : selected ?. description ?? defaultBehaviorOption ( ) . description ,
238+ value : selected ?. value ?? null ,
199239 options,
200240 } ;
201241 }
@@ -205,6 +245,7 @@ export const getModelBehaviorSummary = (
205245 title,
206246 label : t ( "model_behavior.label_builtin" ) ,
207247 description : t ( "model_behavior.desc_builtin" ) ,
248+ value : null ,
208249 options,
209250 } ;
210251 }
@@ -213,6 +254,7 @@ export const getModelBehaviorSummary = (
213254 title,
214255 label : t ( "model_behavior.label_standard" ) ,
215256 description : t ( "model_behavior.desc_standard" ) ,
257+ value : null ,
216258 options,
217259 } ;
218260} ;
0 commit comments