@@ -7,6 +7,9 @@ import type {
77import type { ModelSelection , ServerProviderModel } from "@t3tools/contracts" ;
88import { getProviderOptionCurrentValue } from "@t3tools/shared/model" ;
99
10+ /** Composer option id for optional Cursor max mode; not an SDK model parameter. */
11+ export const CURSOR_SDK_MAX_MODE_OPTION_ID = "maxMode" ;
12+
1013const CURSOR_SDK_PARAMETER_TO_PROVIDER_OPTION : Readonly < Record < string , string > > = {
1114 context : "contextWindow" ,
1215 fast : "fastMode" ,
@@ -72,7 +75,6 @@ function variantMatchesParams(
7275 ) ;
7376}
7477
75- /** True when every catalog variant consistent with `params` requires max mode. */
7678export function cursorSdkMaxModeForParams (
7779 model : Pick < SDKModel , "variants" > ,
7880 params : ReadonlyArray < ModelParameterValue > | undefined ,
@@ -82,21 +84,53 @@ export function cursorSdkMaxModeForParams(
8284 return matching . length > 0 && matching . every ( ( variant ) => variant . isMaxMode === true ) ;
8385}
8486
87+ export function cursorSdkModelOffersOptionalMaxMode ( model : Pick < SDKModel , "variants" > ) : boolean {
88+ const variants = model . variants ?? [ ] ;
89+ if (
90+ ! variants . some ( ( variant ) => variant . isMaxMode === true ) ||
91+ ! variants . some ( ( variant ) => variant . isMaxMode !== true )
92+ ) {
93+ return false ;
94+ }
95+
96+ const candidateParams : Array < ReadonlyArray < ModelParameterValue > | undefined > = [ undefined ] ;
97+ for ( const variant of variants ) {
98+ candidateParams . push ( variant . params ) ;
99+ }
100+
101+ for ( const params of candidateParams ) {
102+ const matching = variants . filter ( ( variant ) => variantMatchesParams ( variant , params ) ) ;
103+ if (
104+ matching . some ( ( variant ) => variant . isMaxMode === true ) &&
105+ matching . some ( ( variant ) => variant . isMaxMode !== true )
106+ ) {
107+ return true ;
108+ }
109+ }
110+ return false ;
111+ }
112+
85113export function cursorSdkModelSelection (
86114 modelSelection : ModelSelection ,
87115 sdkModels ?: ReadonlyArray < Pick < SDKModel , "id" | "variants" > > ,
88116) : CursorSdkModelSelection {
89117 const id = modelSelection . model === "auto" ? "default" : modelSelection . model ;
118+ const options = modelSelection . options ?? [ ] ;
119+ const userRequestedMaxMode = options . some (
120+ ( option ) => option . id === CURSOR_SDK_MAX_MODE_OPTION_ID && option . value === true ,
121+ ) ;
122+ const sdkOptions = options . filter ( ( option ) => option . id !== CURSOR_SDK_MAX_MODE_OPTION_ID ) ;
90123 const params =
91- modelSelection . options === undefined || modelSelection . options . length === 0
124+ sdkOptions . length === 0
92125 ? undefined
93- : modelSelection . options . map ( ( option ) : ModelParameterValue => ( {
126+ : sdkOptions . map ( ( option ) : ModelParameterValue => ( {
94127 id : cursorSdkParameterId ( option . id ) ,
95128 value : String ( option . value ) ,
96129 } ) ) ;
97130 const catalogModel = sdkModels ?. find ( ( model ) => model . id === id ) ;
98131 const maxMode =
99- catalogModel === undefined ? false : cursorSdkMaxModeForParams ( catalogModel , params ) ;
132+ userRequestedMaxMode ||
133+ ( catalogModel !== undefined && cursorSdkMaxModeForParams ( catalogModel , params ) ) ;
100134 return {
101135 id,
102136 ...( params === undefined ? { } : { params } ) ,
0 commit comments