File tree Expand file tree Collapse file tree 5 files changed +39
-1
lines changed Expand file tree Collapse file tree 5 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 151
151
"title" : " Add Key" ,
152
152
"category" : " Utils AI"
153
153
},
154
+ {
155
+ "command" : " barbapapazes.utils-ai.removeKey" ,
156
+ "title" : " Remove Key" ,
157
+ "category" : " Utils AI"
158
+ },
154
159
{
155
160
"command" : " barbapapazes.utils-ai.runAction" ,
156
161
"title" : " Run action" ,
Original file line number Diff line number Diff line change 1
1
import type { Awaitable } from '../types/index.js'
2
2
3
3
export class BaseAI {
4
+ static name : string
5
+
4
6
protected key : string
5
7
protected options : Record < string , unknown >
6
8
@@ -9,7 +11,7 @@ export class BaseAI {
9
11
this . options = options
10
12
}
11
13
12
- ask ( _ : string , __ : string ) : Awaitable < string > {
14
+ ask ( _prompt : string , _content : string ) : Awaitable < string > {
13
15
throw new Error ( 'Method not implemented.' )
14
16
}
15
17
}
Original file line number Diff line number Diff line change 1
1
import { BaseAI } from './base_ai.js'
2
2
3
3
export class OpenAI extends BaseAI {
4
+ static name = 'OpenAI'
5
+
4
6
constructor ( key : string , options : Record < string , unknown > = { } ) {
5
7
super ( key , options )
6
8
}
Original file line number Diff line number Diff line change 1
1
import { AddKeyCommand } from './add_key_command.js'
2
2
import { CheckConfigCommand } from './check_config_command.js'
3
+ import { RemoveKeyCommand } from './remove_key_command.js'
3
4
import { RunActionCommand } from './run_action_command.js'
4
5
import { RunQuickActionCommand } from './run_quick_action_command.js'
5
6
6
7
export const commands = {
7
8
addKey : AddKeyCommand ,
9
+ removeKey : RemoveKeyCommand ,
8
10
runAction : RunActionCommand ,
9
11
runQuickAction : RunQuickActionCommand ,
10
12
checkConfig : CheckConfigCommand ,
Original file line number Diff line number Diff line change
1
+ import { window } from 'vscode'
2
+ import { BaseCommand } from './base_command.js'
3
+
4
+ export class RemoveKeyCommand extends BaseCommand {
5
+ readonly keysKey = 'keys'
6
+
7
+ protected async run ( ) : Promise < void > {
8
+ const keyName = await window . showQuickPick ( this . getKeyNames ( ) )
9
+
10
+ this . assert ( keyName , 'Key name is required.' )
11
+
12
+ await this . remove ( keyName )
13
+
14
+ this . logger . log ( 'Key removed successfully.' , {
15
+ notification : true ,
16
+ } )
17
+ }
18
+
19
+ protected async remove ( name : string ) : Promise < void > {
20
+ await this . context . secrets . delete ( name )
21
+ await this . context . globalState . update ( this . keysKey , this . getKeyNames ( ) . filter ( keyName => keyName !== name ) )
22
+ }
23
+
24
+ protected getKeyNames ( ) : string [ ] {
25
+ return this . context . globalState . get < [ ] | undefined > ( this . keysKey ) || [ ]
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments