@@ -16,6 +16,9 @@ import {
1616 initial_select_model ,
1717 initial_select_provider
1818} from './config-editing'
19+ import axios from 'axios'
20+ import { PROVIDERS } from '@shared/constants/providers'
21+ import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1922
2023export const upsert_configuration = async ( params : {
2124 context : vscode . ExtensionContext
@@ -30,44 +33,38 @@ export const upsert_configuration = async (params: {
3033 let get_configs : ( ) => Promise < ToolConfig [ ] >
3134 let save_configs : ( configs : ToolConfig [ ] ) => Promise < void >
3235 let advanced_options : string [ ] = [ ]
33- let advanced_details = ''
3436
3537 switch ( params . tool_type ) {
3638 case 'code-at-cursor' :
3739 get_configs = ( ) => providers_manager . get_code_completions_tool_configs ( )
3840 save_configs = ( configs ) =>
3941 providers_manager . save_code_completions_tool_configs ( configs )
4042 advanced_options = [ 'Temperature' , 'Reasoning Effort' ]
41- advanced_details = 'Temperature, Reasoning Effort...'
4243 break
4344 case 'commit-messages' :
4445 get_configs = ( ) => providers_manager . get_commit_messages_tool_configs ( )
4546 save_configs = ( configs ) =>
4647 providers_manager . save_commit_messages_tool_configs ( configs )
4748 advanced_options = [ 'Temperature' , 'Reasoning Effort' ]
48- advanced_details = 'Temperature, Reasoning Effort...'
4949 break
5050 case 'edit-context' :
5151 get_configs = ( ) => providers_manager . get_edit_context_tool_configs ( )
5252 save_configs = ( configs ) =>
5353 providers_manager . save_edit_context_tool_configs ( configs )
5454 advanced_options = [ 'Temperature' , 'Reasoning Effort' ]
55- advanced_details = 'Temperature, Reasoning Effort...'
5655 break
5756 case 'intelligent-update' :
5857 get_configs = ( ) =>
5958 providers_manager . get_intelligent_update_tool_configs ( )
6059 save_configs = ( configs ) =>
6160 providers_manager . save_intelligent_update_tool_configs ( configs )
6261 advanced_options = [ 'Temperature' , 'Reasoning Effort' , 'Max Concurrency' ]
63- advanced_details = 'Temperature, Reasoning Effort, Max Concurrency...'
6462 break
6563 case 'prune-context' :
6664 get_configs = ( ) => providers_manager . get_prune_context_tool_configs ( )
6765 save_configs = ( configs ) =>
6866 providers_manager . save_prune_context_tool_configs ( configs )
6967 advanced_options = [ 'Temperature' , 'Reasoning Effort' ]
70- advanced_details = 'Temperature, Reasoning Effort...'
7168 break
7269 default :
7370 throw new Error ( `Unknown tool type: ${ params . tool_type } ` )
@@ -178,7 +175,7 @@ export const upsert_configuration = async (params: {
178175 const items : vscode . QuickPickItem [ ] = [
179176 { label : 'Model Provider' , detail : updated_config . provider_name } ,
180177 { label : 'Model' , detail : updated_config . model } ,
181- { label : 'Advanced' , detail : advanced_details }
178+ { label : 'Advanced' }
182179 ]
183180
184181 const selected_item = await new Promise < vscode . QuickPickItem | undefined > (
@@ -191,7 +188,7 @@ export const upsert_configuration = async (params: {
191188 quick_pick . placeholder = 'Select a property to edit'
192189 const close_button : vscode . QuickInputButton = {
193190 iconPath : new vscode . ThemeIcon ( 'close' ) ,
194- tooltip : 'Save and Close '
191+ tooltip : 'Save and close '
195192 }
196193 const redo_button : vscode . QuickInputButton = {
197194 iconPath : new vscode . ThemeIcon ( 'redo' ) ,
@@ -223,7 +220,7 @@ export const upsert_configuration = async (params: {
223220 detail : updated_config . provider_name
224221 } ,
225222 { label : 'Model' , detail : updated_config . model } ,
226- { label : 'Advanced' , detail : advanced_details }
223+ { label : 'Advanced' }
227224 ]
228225 quick_pick . buttons = [ close_button ]
229226 }
@@ -266,7 +263,7 @@ export const upsert_configuration = async (params: {
266263 if ( advanced_options . includes ( 'Temperature' ) ) {
267264 advanced_items . push ( {
268265 label : 'Temperature' ,
269- description : 'Leave unset with reasoning models' ,
266+ description : 'Leave empty with reasoning models' ,
270267 detail : updated_config . temperature ?. toString ( )
271268 } )
272269 }
@@ -327,10 +324,60 @@ export const upsert_configuration = async (params: {
327324 new_temp === null ? undefined : new_temp
328325 }
329326 } else if ( selected_advanced . label == 'Reasoning Effort' ) {
330- const new_effort = await edit_reasoning_effort_for_config ( )
331- if ( new_effort !== undefined ) {
332- updated_config . reasoning_effort =
333- new_effort === null ? undefined : ( new_effort as any )
327+ // eslint-disable-next-line no-constant-condition
328+ while ( true ) {
329+ const new_effort = await edit_reasoning_effort_for_config ( )
330+ if ( new_effort === undefined ) break
331+
332+ let is_valid = true
333+ if ( new_effort !== null ) {
334+ const provider = await providers_manager . get_provider (
335+ updated_config . provider_name
336+ )
337+ if ( provider ) {
338+ const base_url =
339+ provider . type === 'built-in'
340+ ? PROVIDERS [ provider . name as keyof typeof PROVIDERS ]
341+ ?. base_url
342+ : provider . base_url
343+
344+ if ( base_url ) {
345+ try {
346+ await vscode . window . withProgress (
347+ {
348+ location : vscode . ProgressLocation . Notification ,
349+ title : 'Checking reasoning effort support...' ,
350+ cancellable : true
351+ } ,
352+ async ( _progress , token ) => {
353+ await verify_reasoning_effort ( {
354+ endpoint_url : base_url ! ,
355+ api_key : provider . api_key ,
356+ model : updated_config . model ,
357+ reasoning_effort : new_effort as string ,
358+ provider,
359+ cancellation_token : token
360+ } )
361+ }
362+ )
363+ } catch ( error : any ) {
364+ is_valid = false
365+ if ( error ?. message != 'Cancelled' ) {
366+ vscode . window . showWarningMessage (
367+ dictionary . warning_message
368+ . REASONING_EFFORT_NOT_SUPPORTED
369+ )
370+ }
371+ }
372+ }
373+ }
374+ }
375+
376+ if ( is_valid ) {
377+ updated_config . reasoning_effort =
378+ new_effort === null ? undefined : ( new_effort as any )
379+ break
380+ }
334381 }
335382 } else if ( selected_advanced . label == 'Max Concurrency' ) {
336383 const new_concurrency =
@@ -392,3 +439,77 @@ export const upsert_configuration = async (params: {
392439
393440 await save_configs ( configs )
394441}
442+
443+ const verify_reasoning_effort = async ( params : {
444+ endpoint_url : string
445+ api_key ?: string
446+ model : string
447+ reasoning_effort : string
448+ provider : Provider
449+ cancellation_token : vscode . CancellationToken
450+ } ) : Promise < void > => {
451+ const cancel_source = axios . CancelToken . source ( )
452+
453+ const disposable = params . cancellation_token . onCancellationRequested ( ( ) => {
454+ cancel_source . cancel ( 'User cancelled' )
455+ } )
456+
457+ const body : any = {
458+ model : params . model ,
459+ messages : [
460+ {
461+ role : 'user' ,
462+ content : 'Respond with "Hello!" and nothing else.'
463+ }
464+ ] ,
465+ stream : true
466+ }
467+
468+ apply_reasoning_effort ( body , params . provider , params . reasoning_effort as any )
469+
470+ try {
471+ const response = await axios . post (
472+ params . endpoint_url + '/chat/completions' ,
473+ body ,
474+ {
475+ headers : {
476+ ...( params . api_key
477+ ? { [ 'Authorization' ] : `Bearer ${ params . api_key } ` }
478+ : { } ) ,
479+ [ 'Content-Type' ] : 'application/json'
480+ } ,
481+ responseType : 'stream' ,
482+ cancelToken : cancel_source . token
483+ }
484+ )
485+
486+ await new Promise < void > ( ( resolve , reject ) => {
487+ const stream = response . data
488+
489+ stream . on ( 'data' , ( ) => {
490+ cancel_source . cancel ( 'Verified' )
491+ resolve ( )
492+ } )
493+
494+ stream . on ( 'error' , ( err : any ) => {
495+ reject ( err )
496+ } )
497+
498+ stream . on ( 'end' , ( ) => {
499+ resolve ( )
500+ } )
501+ } )
502+ } catch ( error ) {
503+ if ( axios . isCancel ( error ) ) {
504+ if ( error . message == 'Verified' ) {
505+ return
506+ }
507+ if ( error . message == 'User cancelled' ) {
508+ throw new Error ( 'Cancelled' )
509+ }
510+ }
511+ throw error
512+ } finally {
513+ disposable . dispose ( )
514+ }
515+ }
0 commit comments