11import * as vscode from 'vscode'
22import {
33 ModelProvidersManager ,
4- get_tool_config_id ,
5- ToolConfig
4+ get_api_configuration_id ,
5+ ApiConfiguration
66} from '../../../services/model-providers-manager'
77import { Logger } from '@shared/utils/logger'
88import { RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
99import { PanelProvider } from '@/views/panel/backend/panel-provider'
1010import { dictionary } from '@shared/constants/dictionary'
1111import { t } from '@/i18n'
1212
13- export const get_code_at_cursor_config = async ( params : {
13+ export const get_code_at_cursor_api_configuration = async ( params : {
1414 api_providers_manager : ModelProvidersManager
1515 show_quick_pick ?: boolean
1616 context : vscode . ExtensionContext
17- config_id ?: string
17+ api_configuration_id ?: string
1818 panel_provider ?: PanelProvider
19- } ) : Promise < { provider : any ; config : any } | undefined > => {
20- const code_at_cursor_configs =
21- await params . api_providers_manager . get_tool_configs ( )
19+ } ) : Promise < { model_provider : any ; api_configuration : any } | undefined > => {
20+ const code_at_cursor_api_configurations =
21+ await params . api_providers_manager . get_api_configurations ( )
2222
23- if ( code_at_cursor_configs . length == 0 ) {
23+ if ( code_at_cursor_api_configurations . length == 0 ) {
2424 vscode . commands . executeCommand ( 'codeWebChat.settings' )
2525 vscode . window . showInformationMessage (
2626 dictionary . information_message . NO_CODE_AT_CURSOR_CONFIGURATIONS_FOUND
2727 )
2828 return
2929 }
3030
31- let selected_config : ToolConfig | null = null
31+ let selected_api_configuration : ApiConfiguration | null = null
3232
33- if ( params . config_id !== undefined ) {
34- selected_config =
35- code_at_cursor_configs . find (
36- ( c ) => get_tool_config_id ( c ) === params . config_id
33+ if ( params . api_configuration_id !== undefined ) {
34+ selected_api_configuration =
35+ code_at_cursor_api_configurations . find (
36+ ( c ) => get_api_configuration_id ( c ) === params . api_configuration_id
3737 ) || null
3838 } else if ( ! params . show_quick_pick ) {
39- const default_config =
40- await params . api_providers_manager . get_default_code_completions_config ( )
41- if ( default_config ) {
42- selected_config = default_config
39+ const default_api_configuration =
40+ await params . api_providers_manager . get_default_code_completions_api_configuration ( )
41+ if ( default_api_configuration ) {
42+ selected_api_configuration = default_api_configuration
4343 } else {
4444 const recents = params . context . workspaceState . get < string [ ] > (
4545 RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY
4646 )
4747 const last_selected_id = recents ?. [ 0 ]
4848 if ( last_selected_id ) {
49- selected_config =
50- code_at_cursor_configs . find (
51- ( c ) => get_tool_config_id ( c ) == last_selected_id
49+ selected_api_configuration =
50+ code_at_cursor_api_configurations . find (
51+ ( c ) => get_api_configuration_id ( c ) == last_selected_id
5252 ) || null
5353 }
54- if ( ! selected_config && code_at_cursor_configs . length > 0 ) {
55- selected_config = code_at_cursor_configs [ 0 ]
54+ if ( ! selected_api_configuration && code_at_cursor_api_configurations . length > 0 ) {
55+ selected_api_configuration = code_at_cursor_api_configurations [ 0 ]
5656 }
5757 }
5858 }
5959
60- if ( ! selected_config || params . show_quick_pick ) {
60+ if ( ! selected_api_configuration || params . show_quick_pick ) {
6161 const create_items = ( ) => {
6262 const recent_ids =
6363 params . context . workspaceState . get < string [ ] > (
6464 RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY
6565 ) || [ ]
6666
67- const matched_recent_configs : ToolConfig [ ] = [ ]
68- const remaining_configs : ToolConfig [ ] = [ ]
67+ const matched_recent_api_configurations : ApiConfiguration [ ] = [ ]
68+ const remaining_api_configurations : ApiConfiguration [ ] = [ ]
6969
70- code_at_cursor_configs . forEach ( ( config ) => {
71- const id = get_tool_config_id ( config )
70+ code_at_cursor_api_configurations . forEach ( ( api_configuration ) => {
71+ const id = get_api_configuration_id ( api_configuration )
7272 if ( recent_ids . includes ( id ) ) {
73- matched_recent_configs . push ( config )
73+ matched_recent_api_configurations . push ( api_configuration )
7474 } else {
75- remaining_configs . push ( config )
75+ remaining_api_configurations . push ( api_configuration )
7676 }
7777 } )
7878
79- matched_recent_configs . sort ( ( a , b ) => {
80- const id_a = get_tool_config_id ( a )
81- const id_b = get_tool_config_id ( b )
79+ matched_recent_api_configurations . sort ( ( a , b ) => {
80+ const id_a = get_api_configuration_id ( a )
81+ const id_b = get_api_configuration_id ( b )
8282 return recent_ids . indexOf ( id_a ) - recent_ids . indexOf ( id_b )
8383 } )
8484
85- const recent_configs = matched_recent_configs
86- const other_configs = remaining_configs
85+ const recent_api_configurations = matched_recent_api_configurations
86+ const other_api_configurations = remaining_api_configurations
8787
88- const map_config_to_item = ( config : ToolConfig ) => {
89- const description_parts = [ config . provider_name ]
90- if ( config . temperature != null ) {
91- description_parts . push ( `${ config . temperature } ` )
88+ const map_api_configuration_to_item = ( api_configuration : ApiConfiguration ) => {
89+ const description_parts = [ api_configuration . model_provider_name ]
90+ if ( api_configuration . temperature != null ) {
91+ description_parts . push ( `${ api_configuration . temperature } ` )
9292 }
93- if ( config . reasoning_effort ) {
94- description_parts . push ( `${ config . reasoning_effort } ` )
93+ if ( api_configuration . reasoning_effort ) {
94+ description_parts . push ( `${ api_configuration . reasoning_effort } ` )
9595 }
9696
9797 const buttons : vscode . QuickInputButton [ ] = [ ]
9898
9999 return {
100- label : config . model ,
100+ label : api_configuration . model ,
101101 description : description_parts . join ( ' · ' ) ,
102102 buttons,
103- config ,
104- id : get_tool_config_id ( config )
103+ api_configuration ,
104+ id : get_api_configuration_id ( api_configuration )
105105 }
106106 }
107107
108108 const items : ( vscode . QuickPickItem & {
109- config ?: ToolConfig
109+ api_configuration ?: ApiConfiguration
110110 id ?: string
111111 } ) [ ] = [ ]
112112
113- if ( recent_configs . length > 0 ) {
113+ if ( recent_api_configurations . length > 0 ) {
114114 items . push ( {
115115 label : t ( 'common.separator.recently-used' ) ,
116116 kind : vscode . QuickPickItemKind . Separator
117117 } )
118- items . push ( ...recent_configs . map ( map_config_to_item ) )
118+ items . push ( ...recent_api_configurations . map ( map_api_configuration_to_item ) )
119119 }
120120
121- if ( other_configs . length > 0 ) {
122- if ( recent_configs . length > 0 ) {
121+ if ( other_api_configurations . length > 0 ) {
122+ if ( recent_api_configurations . length > 0 ) {
123123 items . push ( {
124124 label : t ( 'common.config.other' ) ,
125125 kind : vscode . QuickPickItemKind . Separator
126126 } )
127127 }
128- items . push ( ...other_configs . map ( map_config_to_item ) )
128+ items . push ( ...other_api_configurations . map ( map_api_configuration_to_item ) )
129129 }
130130
131131 return items
@@ -154,7 +154,7 @@ export const get_code_at_cursor_config = async (params: {
154154 }
155155 }
156156
157- return new Promise < { provider : any ; config : any } | undefined > (
157+ return new Promise < { model_provider : any ; api_configuration : any } | undefined > (
158158 ( resolve ) => {
159159 quick_pick . onDidTriggerButton ( ( button ) => {
160160 if ( button . tooltip == t ( 'common.close' ) ) {
@@ -167,7 +167,7 @@ export const get_code_at_cursor_config = async (params: {
167167 const selected = quick_pick . selectedItems [ 0 ] as any
168168 quick_pick . hide ( )
169169
170- if ( ! selected || ! selected . config ) {
170+ if ( ! selected || ! selected . api_configuration ) {
171171 resolve ( undefined )
172172 return
173173 }
@@ -190,10 +190,10 @@ export const get_code_at_cursor_config = async (params: {
190190 } )
191191 }
192192
193- const provider = await params . api_providers_manager . get_provider (
194- selected . config . provider_name
193+ const model_provider = await params . api_providers_manager . get_model_provider (
194+ selected . api_configuration . model_provider_name
195195 )
196- if ( ! provider ) {
196+ if ( ! model_provider ) {
197197 vscode . window . showErrorMessage (
198198 dictionary . error_message . API_PROVIDER_NOT_FOUND
199199 )
@@ -202,8 +202,8 @@ export const get_code_at_cursor_config = async (params: {
202202 }
203203
204204 resolve ( {
205- provider ,
206- config : selected . config
205+ model_provider ,
206+ api_configuration : selected . api_configuration
207207 } )
208208 } )
209209
@@ -217,23 +217,23 @@ export const get_code_at_cursor_config = async (params: {
217217 )
218218 }
219219
220- const provider = await params . api_providers_manager . get_provider (
221- selected_config . provider_name
220+ const model_provider = await params . api_providers_manager . get_model_provider (
221+ selected_api_configuration . model_provider_name
222222 )
223223
224- if ( ! provider ) {
224+ if ( ! model_provider ) {
225225 vscode . window . showErrorMessage (
226226 dictionary . error_message . API_PROVIDER_NOT_FOUND
227227 )
228228 Logger . warn ( {
229- function_name : 'get_code_at_cursor_config ' ,
229+ function_name : 'get_code_at_cursor_api_configuration ' ,
230230 message : 'API provider not found for Code Completions tool.'
231231 } )
232232 return
233233 }
234234
235235 return {
236- provider ,
237- config : selected_config
236+ model_provider ,
237+ api_configuration : selected_api_configuration
238238 }
239239}
0 commit comments