@@ -77,7 +77,7 @@ export class AIProviderService implements Disposable {
7777 this . _provider ?. dispose ( ) ;
7878 }
7979
80- get providerId ( ) {
80+ get currentProviderId ( ) {
8181 return this . _provider ?. id ;
8282 }
8383
@@ -108,13 +108,15 @@ export class AIProviderService implements Disposable {
108108 return models . flatMap ( m => getSettledValue ( m , [ ] ) ) ;
109109 }
110110
111- private async getOrChooseModel ( force ?: boolean ) : Promise < AIModel | undefined > {
111+ private async getModel ( options ?: { force ?: boolean ; silent ?: boolean } ) : Promise < AIModel | undefined > {
112112 const cfg = this . getConfiguredModel ( ) ;
113- if ( ! force && cfg ?. provider != null && cfg ?. model != null ) {
113+ if ( ! options ?. force && cfg ?. provider != null && cfg ?. model != null ) {
114114 const model = await this . getOrUpdateModel ( cfg . provider , cfg . model ) ;
115115 if ( model != null ) return model ;
116116 }
117117
118+ if ( options ?. silent ) return undefined ;
119+
118120 const pick = await showAIModelPicker ( this . container , cfg ) ;
119121 if ( pick == null ) return undefined ;
120122
@@ -221,7 +223,7 @@ export class AIProviderService implements Disposable {
221223 changes = diff . contents ;
222224 }
223225
224- const model = await this . getOrChooseModel ( ) ;
226+ const model = await this . getModel ( ) ;
225227 if ( model == null ) return undefined ;
226228
227229 const provider = this . _provider ! ;
@@ -276,7 +278,7 @@ export class AIProviderService implements Disposable {
276278 const diff = await this . container . git . getDiff ( commit . repoPath , commit . sha ) ;
277279 if ( ! diff ?. contents ) throw new Error ( 'No changes found to explain.' ) ;
278280
279- const model = await this . getOrChooseModel ( ) ;
281+ const model = await this . getModel ( ) ;
280282 if ( model == null ) return undefined ;
281283
282284 const provider = this . _provider ! ;
@@ -301,22 +303,64 @@ export class AIProviderService implements Disposable {
301303 } ) ;
302304 }
303305
304- reset ( ) {
305- const { providerId } = this ;
306- if ( providerId == null ) return ;
306+ async reset ( ) {
307+ let { _provider : provider } = this ;
308+ if ( provider == null ) {
309+ // If we have no provider, try to get the current model (which will load the provider)
310+ await this . getModel ( { silent : true } ) ;
311+ provider = this . _provider ;
312+ }
313+
314+ const resetCurrent : MessageItem = { title : `Reset Current` } ;
315+ const resetAll : MessageItem = { title : 'Reset All' } ;
316+ const cancel : MessageItem = { title : 'Cancel' , isCloseAffordance : true } ;
317+
318+ let result ;
319+ if ( provider == null ) {
320+ result = await window . showInformationMessage (
321+ `Do you want to reset all of the stored AI keys?` ,
322+ { modal : true } ,
323+ resetAll ,
324+ cancel ,
325+ ) ;
326+ } else {
327+ result = await window . showInformationMessage (
328+ `Do you want to reset the stored key for the current provider (${ provider . name } ) or reset all of the stored AI keys?` ,
329+ { modal : true } ,
330+ resetCurrent ,
331+ resetAll ,
332+ cancel ,
333+ ) ;
334+ }
335+
336+ if ( provider != null && result === resetCurrent ) {
337+ void env . clipboard . writeText ( ( await this . container . storage . getSecret ( `gitlens.${ provider . id } .key` ) ) ?? '' ) ;
338+ void this . container . storage . deleteSecret ( `gitlens.${ provider . id } .key` ) ;
339+
340+ void this . container . storage . delete ( `confirm:ai:tos:${ provider . id } ` ) ;
341+ void this . container . storage . deleteWorkspace ( `confirm:ai:tos:${ provider . id } ` ) ;
342+ } else if ( result === resetAll ) {
343+ const keys = [ ] ;
344+ for ( const [ providerId ] of _supportedProviderTypes ) {
345+ keys . push ( await this . container . storage . getSecret ( `gitlens.${ providerId } .key` ) ) ;
346+ }
347+ void env . clipboard . writeText ( keys . join ( '\n' ) ) ;
307348
308- void this . container . storage . deleteSecret ( `gitlens.${ providerId } .key` ) ;
349+ for ( const [ providerId ] of _supportedProviderTypes ) {
350+ void this . container . storage . deleteSecret ( `gitlens.${ providerId } .key` ) ;
351+ }
309352
310- void this . container . storage . delete ( `confirm:ai:tos:${ providerId } ` ) ;
311- void this . container . storage . deleteWorkspace ( `confirm:ai:tos:${ providerId } ` ) ;
353+ void this . container . storage . deleteWithPrefix ( `confirm:ai:tos` ) ;
354+ void this . container . storage . deleteWorkspaceWithPrefix ( `confirm:ai:tos` ) ;
355+ }
312356 }
313357
314358 supports ( provider : AIProviders | string ) {
315359 return _supportedProviderTypes . has ( provider as AIProviders ) ;
316360 }
317361
318362 async switchModel ( ) {
319- void ( await this . getOrChooseModel ( true ) ) ;
363+ void ( await this . getModel ( { force : true } ) ) ;
320364 }
321365}
322366
0 commit comments