Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Rename AgentEventEmitter to EventEmitter for clarity #151

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/agents/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as vscode from "vscode";
import { AgentEventEmitter } from "../emitter/agent-emitter";
import { IEventPayload } from "../emitter/interface";
import { EventEmitter } from "../emitter/agent-emitter";

export abstract class BaseAiAgent
extends AgentEventEmitter
extends EventEmitter
implements vscode.Disposable
{
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/agents/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Orchestrator extends BaseAiAgent implements vscode.Disposable {
}

public handleStatus(event: IEventPayload) {
this.emitEvent("onQuery", JSON.stringify(event));
this.publish("onQuery", JSON.stringify(event));
console.log(` ${event.message} - ${JSON.stringify(event)}`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/emitter/agent-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { BaseEmitter } from "./emitter";
import { IAgentEventMap, IEventPayload } from "./interface";

export class AgentEventEmitter extends BaseEmitter<IAgentEventMap> {
export class EventEmitter extends BaseEmitter<IAgentEventMap> {
onStatusChange: vscode.Event<IEventPayload> = this.createEvent("onStatus");
onError: vscode.Event<IEventPayload> = this.createEvent("onError");
onUpdate: vscode.Event<IEventPayload> = this.createEvent("onUpdate");
Expand All @@ -16,7 +16,7 @@ export class AgentEventEmitter extends BaseEmitter<IAgentEventMap> {
* @param {string} message The message associated with the event (optional).

*/
emitEvent(eventName: keyof IAgentEventMap, message?: string, data?: any) {
publish(eventName: keyof IAgentEventMap, message?: string, data?: any) {
const payload: IEventPayload = {
type: eventName,
message,
Expand Down
8 changes: 4 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { FileUploader } from "./services/file-uploader";
import { initializeGenerativeAiEnvironment } from "./services/generative-ai-model-manager";
import { getConfigValue } from "./utils/utils";
import { Memory } from "./memory/base";
import { AgentEventEmitter } from "./emitter/agent-emitter";
import { EventEmitter } from "./emitter/agent-emitter";

const {
geminiKey,
Expand All @@ -47,7 +47,7 @@ const connectDB = async () => {
};

let quickFixCodeAction: vscode.Disposable;
let agentEventEmmitter: AgentEventEmitter;
let agentEventEmmitter: EventEmitter;

export async function activate(context: vscode.ExtensionContext) {
try {
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function activate(context: vscode.ExtensionContext) {
[explain]: () => explainCode.execute(),
[pattern]: () => codePattern.uploadFileHandler(),
[knowledge]: () => knowledgeBase.execute(),
[commitMessage]: () => generateCommitMessage.execute("hello"),
[commitMessage]: () => generateCommitMessage.execute("commitMessage"),
[generateCodeChart]: () => codeChartGenerator.execute(),
[inlineChat]: () => getInLineChat.execute(),
};
Expand All @@ -164,7 +164,7 @@ export async function activate(context: vscode.ExtensionContext) {
quickFix,
);

agentEventEmmitter = new AgentEventEmitter();
agentEventEmmitter = new EventEmitter();

const modelConfigurations: {
[key: string]: {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { formatText } from "../utils/utils";
import { getWebviewContent } from "../webview/chat";

let _view: vscode.WebviewView | undefined;
export abstract class BaseWebViewProvider {
export abstract class BaseWebViewProvider implements vscode.Disposable {
protected readonly orchestrator: Orchestrator;
public static readonly viewId = "chatView";
static webView: vscode.WebviewView | undefined;
Expand Down Expand Up @@ -109,7 +109,7 @@ export abstract class BaseWebViewProvider {
try {
const response = await this.generateContent(message.message);
if (response) {
this.orchestrator.emitEvent("onQuery", JSON.stringify(response));
this.orchestrator.publish("onQuery", JSON.stringify(response));
}
} catch (error) {
this.logger.error("Unable to publish generateContentEvent", error);
Expand Down
4 changes: 2 additions & 2 deletions src/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ export class GeminiWebViewProvider extends BaseWebViewProvider {
prompt: userInput,
thought: extractedThought,
};
this.orchestrator.emitEvent("onStatus", JSON.stringify(result));
this.orchestrator.publish("onStatus", JSON.stringify(result));
return result;
} catch (error: any) {
this.orchestrator.emitEvent("onError", error);
this.orchestrator.publish("onError", error);
vscode.window.showErrorMessage("Error processing user query");
this.logger.error(
"Error generating, queries, thoughts from user query",
Expand Down
4 changes: 2 additions & 2 deletions src/services/generative-ai-model-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { getConfigValue } from "../utils/utils";
import { AgentEventEmitter } from "../emitter/agent-emitter";
import { EventEmitter } from "../emitter/agent-emitter";

export const initializeGenerativeAiEnvironment = async (
context: vscode.ExtensionContext,
Expand All @@ -9,7 +9,7 @@ export const initializeGenerativeAiEnvironment = async (
webViewProviderClass: any,
subscriptions: vscode.Disposable[],
quickFixCodeAction: vscode.Disposable,
agentEventEmmitter: AgentEventEmitter,
agentEventEmmitter: EventEmitter,
) => {
try {
const apiKey = getConfigValue(key);
Expand Down