@@ -3,8 +3,13 @@ import {
33 ProviderInstanceId ,
44 ProviderDriverKind ,
55 type ProviderOptionDescriptor ,
6+ type ServerProviderModel ,
67} from "@t3tools/contracts" ;
7- import { buildTraitsTriggerDisplay , buildUnavailableModelOptionDescriptors } from "./TraitsPicker" ;
8+ import {
9+ buildTraitsTriggerDisplay ,
10+ buildUnavailableModelOptionDescriptors ,
11+ getReasoningLevelChange ,
12+ } from "./TraitsPicker" ;
813
914function selectDescriptor (
1015 id : string ,
@@ -56,6 +61,180 @@ const CONTEXT_WINDOW = selectDescriptor(
5661
5762const CODEX = ProviderDriverKind . make ( "codex" ) ;
5863
64+ describe ( "reasoning level shortcuts" , ( ) => {
65+ const options = [
66+ { id : "low" , label : "Low" } ,
67+ { id : "high" , label : "High" , isDefault : true } ,
68+ { id : "ultrathink" , label : "Ultrathink" } ,
69+ ] ;
70+ const modelWith = (
71+ descriptors : ReadonlyArray < ProviderOptionDescriptor > ,
72+ ) : ServerProviderModel [ ] => [
73+ {
74+ slug : "test-model" ,
75+ name : "Test" ,
76+ isCustom : false ,
77+ capabilities : { optionDescriptors : descriptors } ,
78+ } ,
79+ ] ;
80+ const input = {
81+ provider : CODEX ,
82+ model : "test-model" ,
83+ models : modelWith ( [
84+ { ...selectDescriptor ( "effort" , options , "high" ) , promptInjectedValues : [ "ultrathink" ] } ,
85+ fastModeDescriptor ( false ) ,
86+ ] ) ,
87+ modelOptions : [ { id : "fastMode" , value : true } ] ,
88+ prompt : "Solve this" ,
89+ planModeEnabled : false ,
90+ direction : - 1 as const ,
91+ } ;
92+
93+ it ( "steps from the default and keeps other traits" , ( ) => {
94+ expect ( getReasoningLevelChange ( input ) ) . toEqual ( {
95+ prompt : "Solve this" ,
96+ modelOptions : [
97+ { id : "effort" , value : "low" } ,
98+ { id : "fastMode" , value : true } ,
99+ ] ,
100+ } ) ;
101+ expect (
102+ getReasoningLevelChange ( {
103+ ...input ,
104+ models : modelWith ( [ { id : "effort" , label : "Effort" , type : "select" , options } ] ) ,
105+ } ) ?. modelOptions ,
106+ ) . toEqual ( [ { id : "effort" , value : "low" } ] ) ;
107+ } ) ;
108+
109+ it ( "steps from the displayed reported value unless the draft overrides it" , ( ) => {
110+ const instanceId = ProviderInstanceId . make ( "custom-codex" ) ;
111+ const reportedModelSelection = {
112+ instanceId,
113+ model : "test-model" ,
114+ options : [ { id : "effort" , value : "low" } ] ,
115+ } ;
116+ const reportedInput = { ...input , instanceId, reportedModelSelection, direction : 1 as const } ;
117+ expect ( getReasoningLevelChange ( reportedInput ) ?. modelOptions ) . toEqual ( [
118+ { id : "effort" , value : "high" } ,
119+ { id : "fastMode" , value : true } ,
120+ ] ) ;
121+ expect (
122+ getReasoningLevelChange ( {
123+ ...reportedInput ,
124+ modelOptions : [ { id : "effort" , value : "high" } ] ,
125+ } ) ,
126+ ) . toEqual ( { prompt : "Ultrathink:\nSolve this" } ) ;
127+ expect (
128+ getReasoningLevelChange ( {
129+ ...reportedInput ,
130+ reportedModelSelection : {
131+ ...reportedModelSelection ,
132+ instanceId : ProviderInstanceId . make ( "another-codex" ) ,
133+ } ,
134+ } ) ,
135+ ) . toEqual ( { prompt : "Ultrathink:\nSolve this" } ) ;
136+ expect (
137+ getReasoningLevelChange ( {
138+ ...reportedInput ,
139+ reportedModelSelection : { ...reportedModelSelection , model : "another-model" } ,
140+ } ) ,
141+ ) . toEqual ( { prompt : "Ultrathink:\nSolve this" } ) ;
142+ } ) ;
143+
144+ it ( "uses a catalog default for an unset OpenCode variant" , ( ) => {
145+ expect (
146+ getReasoningLevelChange ( {
147+ ...input ,
148+ provider : ProviderDriverKind . make ( "opencode" ) ,
149+ instanceId : ProviderInstanceId . make ( "opencode" ) ,
150+ models : modelWith ( [ selectDescriptor ( "variant" , options , "high" ) ] ) ,
151+ } ) ?. modelOptions ,
152+ ) . toEqual ( [ { id : "variant" , value : "low" } ] ) ;
153+ } ) ;
154+
155+ it ( "stops at both ends" , ( ) => {
156+ expect (
157+ getReasoningLevelChange ( { ...input , modelOptions : [ { id : "effort" , value : "low" } ] } ) ,
158+ ) . toBeNull ( ) ;
159+ expect (
160+ getReasoningLevelChange ( { ...input , prompt : "Ultrathink:\nSolve this" , direction : 1 } ) ,
161+ ) . toBeNull ( ) ;
162+ } ) ;
163+
164+ it ( "enters and leaves prompt-controlled ultrathink" , ( ) => {
165+ expect ( getReasoningLevelChange ( { ...input , direction : 1 } ) ) . toEqual ( {
166+ prompt : "Ultrathink:\nSolve this" ,
167+ } ) ;
168+ expect ( getReasoningLevelChange ( { ...input , prompt : "Ultrathink:\nSolve this" } ) ) . toEqual ( {
169+ prompt : "Solve this" ,
170+ modelOptions : [
171+ { id : "effort" , value : "high" } ,
172+ { id : "fastMode" , value : true } ,
173+ ] ,
174+ } ) ;
175+ expect (
176+ getReasoningLevelChange ( { ...input , prompt : "Please ultrathink about this" } ) ,
177+ ) . toBeNull ( ) ;
178+ } ) ;
179+
180+ it ( "preserves slash commands and can add the prefix to an empty prompt" , ( ) => {
181+ expect ( getReasoningLevelChange ( { ...input , prompt : "/review" , direction : 1 } ) ) . toEqual ( {
182+ prompt : "/review" ,
183+ } ) ;
184+ expect ( getReasoningLevelChange ( { ...input , prompt : "" , direction : 1 } ) ) . toEqual ( {
185+ prompt : "Ultrathink:\n" ,
186+ } ) ;
187+ } ) ;
188+
189+ it . each ( [
190+ [ "codex" , "reasoningEffort" ] ,
191+ [ "claudeAgent" , "effort" ] ,
192+ [ "cursor" , "reasoning" ] ,
193+ [ "grok" , "reasoningEffort" ] ,
194+ [ "opencode" , "variant" ] ,
195+ [ "antigravity" , "thinking" ] ,
196+ ] ) ( "uses %s model choices in catalog order" , ( provider , id ) => {
197+ expect (
198+ getReasoningLevelChange ( {
199+ ...input ,
200+ provider : ProviderDriverKind . make ( provider ) ,
201+ models : modelWith ( [ CONTEXT_WINDOW , selectDescriptor ( id , options , "high" ) ] ) ,
202+ } ) ?. modelOptions ,
203+ ) . toEqual ( [
204+ { id : "contextWindow" , value : "1m" } ,
205+ { id, value : "low" } ,
206+ ] ) ;
207+ } ) ;
208+
209+ it . each ( [ "agent" , "contextWindow" ] ) ( "does not change %s options" , ( id ) => {
210+ expect (
211+ getReasoningLevelChange ( {
212+ ...input ,
213+ models : modelWith ( [ selectDescriptor ( id , options , "high" ) ] ) ,
214+ } ) ,
215+ ) . toBeNull ( ) ;
216+ } ) ;
217+
218+ it ( "does nothing without an available effort choice" , ( ) => {
219+ expect ( getReasoningLevelChange ( { ...input , models : [ ] } ) ) . toBeNull ( ) ;
220+ expect ( getReasoningLevelChange ( { ...input , models : modelWith ( [ ] ) } ) ) . toBeNull ( ) ;
221+ expect (
222+ getReasoningLevelChange ( {
223+ ...input ,
224+ models : modelWith ( [ selectDescriptor ( "effort" , options , "stale" ) ] ) ,
225+ } ) ,
226+ ) . toBeNull ( ) ;
227+ expect (
228+ getReasoningLevelChange ( {
229+ ...input ,
230+ provider : ProviderDriverKind . make ( "opencode" ) ,
231+ models : [ ] ,
232+ modelOptions : [ { id : "variant" , value : "high" } ] ,
233+ } ) ,
234+ ) . toBeNull ( ) ;
235+ } ) ;
236+ } ) ;
237+
59238function display ( descriptors : ReadonlyArray < ProviderOptionDescriptor > ) {
60239 return buildTraitsTriggerDisplay ( {
61240 provider : CODEX ,
0 commit comments