@@ -77,7 +77,7 @@ export class AIProviderService implements Disposable {
77
77
this . _provider ?. dispose ( ) ;
78
78
}
79
79
80
- get providerId ( ) {
80
+ get currentProviderId ( ) {
81
81
return this . _provider ?. id ;
82
82
}
83
83
@@ -108,13 +108,15 @@ export class AIProviderService implements Disposable {
108
108
return models . flatMap ( m => getSettledValue ( m , [ ] ) ) ;
109
109
}
110
110
111
- private async getOrChooseModel ( force ?: boolean ) : Promise < AIModel | undefined > {
111
+ private async getModel ( options ?: { force ?: boolean ; silent ?: boolean } ) : Promise < AIModel | undefined > {
112
112
const cfg = this . getConfiguredModel ( ) ;
113
- if ( ! force && cfg ?. provider != null && cfg ?. model != null ) {
113
+ if ( ! options ?. force && cfg ?. provider != null && cfg ?. model != null ) {
114
114
const model = await this . getOrUpdateModel ( cfg . provider , cfg . model ) ;
115
115
if ( model != null ) return model ;
116
116
}
117
117
118
+ if ( options ?. silent ) return undefined ;
119
+
118
120
const pick = await showAIModelPicker ( this . container , cfg ) ;
119
121
if ( pick == null ) return undefined ;
120
122
@@ -221,7 +223,7 @@ export class AIProviderService implements Disposable {
221
223
changes = diff . contents ;
222
224
}
223
225
224
- const model = await this . getOrChooseModel ( ) ;
226
+ const model = await this . getModel ( ) ;
225
227
if ( model == null ) return undefined ;
226
228
227
229
const provider = this . _provider ! ;
@@ -276,7 +278,7 @@ export class AIProviderService implements Disposable {
276
278
const diff = await this . container . git . getDiff ( commit . repoPath , commit . sha ) ;
277
279
if ( ! diff ?. contents ) throw new Error ( 'No changes found to explain.' ) ;
278
280
279
- const model = await this . getOrChooseModel ( ) ;
281
+ const model = await this . getModel ( ) ;
280
282
if ( model == null ) return undefined ;
281
283
282
284
const provider = this . _provider ! ;
@@ -301,22 +303,64 @@ export class AIProviderService implements Disposable {
301
303
} ) ;
302
304
}
303
305
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' ) ) ;
307
348
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
+ }
309
352
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
+ }
312
356
}
313
357
314
358
supports ( provider : AIProviders | string ) {
315
359
return _supportedProviderTypes . has ( provider as AIProviders ) ;
316
360
}
317
361
318
362
async switchModel ( ) {
319
- void ( await this . getOrChooseModel ( true ) ) ;
363
+ void ( await this . getModel ( { force : true } ) ) ;
320
364
}
321
365
}
322
366
0 commit comments