Skip to content

Commit f382e39

Browse files
Olasunkanmi OyinlolaOlasunkanmi Oyinlola
authored andcommitted
feat: Add secret storage provider and event handling
- Introduces to securely store and retrieve secrets using VS Code's secret storage. - Implements to listen for secret changes and trigger event. - Adds and events to and . - Modifies to handle events. - Updates to set code index in Memory.
1 parent 593cdb1 commit f382e39

File tree

7 files changed

+78
-7
lines changed

7 files changed

+78
-7
lines changed

src/agents/orchestrator.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ export class Orchestrator extends BaseAiAgent implements vscode.Disposable {
3131
this.publish("onResponse", event.message);
3232
}
3333

34-
// public handleError(event: IEventPayload) {
35-
// console.log(`Error: ${event.message}`);
36-
// }
37-
3834
public dispose(): void {
3935
this.disposables.forEach((d) => d.dispose());
4036
}

src/emitter/agent-emitter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export class EventEmitter extends BaseEmitter<Record<string, IEventPayload>> {
99
onPromptGenerated: vscode.Event<IEventPayload> = this.createEvent("onQuery");
1010
onThinking: vscode.Event<IEventPayload> = this.createEvent("onThinking");
1111
onResponse: vscode.Event<IEventPayload> = this.createEvent("onResponse");
12+
onSecretChange: vscode.Event<IEventPayload> =
13+
this.createEvent("onSecretChange");
14+
onBootstrap: vscode.Event<IEventPayload> = this.createEvent("onBootstrap");
1215

1316
/**
1417
* Emits a generic event with specified status, message, and optional data.

src/emitter/interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface IAgentEventMap {
1818
onQuery: IEventPayload;
1919
onResponse: IEventPayload;
2020
onThinking: IEventPayload;
21+
onSecretChange: IEventPayload;
22+
onBootstrap: IEventPayload;
2123
}
2224

2325
export interface IEventPayload {

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ import { AnthropicWebViewProvider } from "./providers/anthropic";
2424
import { CodeActionsProvider } from "./providers/code-actions";
2525
import { GeminiWebViewProvider } from "./providers/gemini";
2626
import { GroqWebViewProvider } from "./providers/groq";
27+
import { CodeIndexingService } from "./services/code-indexing";
2728
import { FileUploader } from "./services/file-uploader";
2829
import { initializeGenerativeAiEnvironment } from "./services/generative-ai-model-manager";
2930
import { Credentials } from "./services/github-authentication";
3031
import { getConfigValue } from "./utils/utils";
31-
import { WebSearchService } from "./services/web-search-service";
32-
import { CodeIndexingService } from "./services/code-indexing";
3332

3433
const {
3534
geminiKey,

src/providers/base.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export abstract class BaseWebViewProvider implements vscode.Disposable {
3030
this.orchestrator.onThinking(this.handleModelResponseEvent.bind(this)),
3131
this.orchestrator.onUpdate(this.handleModelResponseEvent.bind(this)),
3232
this.orchestrator.onError(this.handleModelResponseEvent.bind(this)),
33+
this.orchestrator.onSecretChange(
34+
this.handleModelResponseEvent.bind(this),
35+
),
3336
);
3437
}
3538

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as vscode from "vscode";
2+
import { Logger } from "../infrastructure/logger/logger";
3+
import { Orchestrator } from "./../agents/orchestrator";
4+
5+
export class VSCodeSecretStorage {
6+
private readonly context: vscode.ExtensionContext;
7+
private readonly logger: Logger;
8+
private readonly orchestrator: Orchestrator;
9+
private static instance: VSCodeSecretStorage;
10+
11+
constructor(context: vscode.ExtensionContext) {
12+
this.context = context;
13+
this.logger = new Logger("VSCodeSecretStorage");
14+
this.orchestrator = Orchestrator.getInstance();
15+
}
16+
17+
static getInstance(context: vscode.ExtensionContext) {
18+
if (!VSCodeSecretStorage.instance) {
19+
VSCodeSecretStorage.instance = new VSCodeSecretStorage(context);
20+
}
21+
return VSCodeSecretStorage.instance;
22+
}
23+
24+
async get(key: string): Promise<string | undefined> {
25+
try {
26+
return await this.context.secrets.get(key);
27+
} catch (error) {
28+
this.logger.error(`Error retrieving secret for key: ${key}`, error);
29+
return undefined;
30+
}
31+
}
32+
33+
async store(key: string, value: string): Promise<void> {
34+
try {
35+
if (value?.length > 0) {
36+
await this.context.secrets.store(key, value);
37+
}
38+
} catch (error) {
39+
this.logger.error(`Error storing secret for key: ${key}`, error);
40+
throw error;
41+
}
42+
}
43+
44+
async delete(key: string): Promise<void> {
45+
try {
46+
await this.context.secrets.delete(key);
47+
} catch (error) {
48+
this.logger.error(`Error deleting secret for key: ${key}`, error);
49+
throw error;
50+
}
51+
}
52+
53+
onDidChange(): vscode.Disposable {
54+
return this.context.secrets.onDidChange((event) => {
55+
if (event.key.length > 0) {
56+
this.orchestrator.handleStatus({
57+
type: "onSecretChange",
58+
data: event.key,
59+
timestamp: new Date().toISOString(),
60+
});
61+
}
62+
});
63+
}
64+
}

src/services/typescript-ats.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path";
22
import * as ts from "typescript";
33
import * as vscode from "vscode";
4+
import { Orchestrator } from "../agents/orchestrator";
45
import { FSPROPS } from "../application/constant";
56
import {
67
DeclarationFunctionNode,
@@ -17,14 +18,17 @@ import {
1718
import { ITypeScriptCodeMapper } from "../application/interfaces/ts.code.mapper.interface";
1819
import { handleError } from "../utils/utils";
1920
import { FileService } from "./file-system";
21+
import { Memory } from "../memory/base";
2022

2123
export class TypeScriptAtsMapper implements ITypeScriptCodeMapper {
2224
private program: ts.Program | undefined;
2325
private typeChecker: ts.TypeChecker | undefined;
2426
private readonly fsService: FileService;
2527
private static instance: TypeScriptAtsMapper;
28+
protected readonly orchestrator: Orchestrator;
2629
constructor() {
2730
this.fsService = FileService.getInstance();
31+
this.orchestrator = Orchestrator.getInstance();
2832
}
2933

3034
public async init() {
@@ -571,7 +575,7 @@ export class TypeScriptAtsMapper implements ITypeScriptCodeMapper {
571575
codebaseMap[repoNames].modules[moduleRalativePath] = moduleInfo;
572576
});
573577
});
574-
//For Code Indexing return codebaseMap
578+
Memory.set("codeIndex", filesMap);
575579
return filesMap;
576580
} catch (error) {
577581
handleError(error, "Error fetching the files");

0 commit comments

Comments
 (0)