Skip to content

Commit d30741c

Browse files
committed
feat: add command to remove key
1 parent 824c214 commit d30741c

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
"title": "Add Key",
152152
"category": "Utils AI"
153153
},
154+
{
155+
"command": "barbapapazes.utils-ai.removeKey",
156+
"title": "Remove Key",
157+
"category": "Utils AI"
158+
},
154159
{
155160
"command": "barbapapazes.utils-ai.runAction",
156161
"title": "Run action",

src/ai/base_ai.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Awaitable } from '../types/index.js'
22

33
export class BaseAI {
4+
static name: string
5+
46
protected key: string
57
protected options: Record<string, unknown>
68

@@ -9,7 +11,7 @@ export class BaseAI {
911
this.options = options
1012
}
1113

12-
ask(_: string, __: string): Awaitable<string> {
14+
ask(_prompt: string, _content: string): Awaitable<string> {
1315
throw new Error('Method not implemented.')
1416
}
1517
}

src/ai/openai.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { BaseAI } from './base_ai.js'
22

33
export class OpenAI extends BaseAI {
4+
static name = 'OpenAI'
5+
46
constructor(key: string, options: Record<string, unknown> = {}) {
57
super(key, options)
68
}

src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { AddKeyCommand } from './add_key_command.js'
22
import { CheckConfigCommand } from './check_config_command.js'
3+
import { RemoveKeyCommand } from './remove_key_command.js'
34
import { RunActionCommand } from './run_action_command.js'
45
import { RunQuickActionCommand } from './run_quick_action_command.js'
56

67
export const commands = {
78
addKey: AddKeyCommand,
9+
removeKey: RemoveKeyCommand,
810
runAction: RunActionCommand,
911
runQuickAction: RunQuickActionCommand,
1012
checkConfig: CheckConfigCommand,

src/commands/remove_key_command.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)