diff --git a/package.json b/package.json index 7b5015f..cfd1e49 100644 --- a/package.json +++ b/package.json @@ -285,6 +285,11 @@ "command": "flexpilot.status.icon.menu", "enablement": "false", "title": "Status Icon Menu" + }, + { + "command": "flexpilot.reload", + "enablement": "false", + "title": "Read storage changes" } ], "icons": { @@ -361,6 +366,7 @@ "chatParticipantPrivate", "chatProvider", "chatVariableResolver", + "contribSourceControlInputBoxMenu", "defaultChatParticipant", "terminalExecuteCommandEvent", "terminalSelection" @@ -368,4 +374,4 @@ "engines": { "vscode": "1.95.x" } -} \ No newline at end of file +} diff --git a/src/commands/reload.ts b/src/commands/reload.ts new file mode 100644 index 0000000..d260a51 --- /dev/null +++ b/src/commands/reload.ts @@ -0,0 +1,26 @@ +import * as vscode from "vscode"; +import { events } from "../events"; +import InlineChatParticipant from "../inline-chat"; +import { logger } from "../logger"; +import PanelChatParticipant from "../panel-chat"; +import { storage } from "../storage"; + +export class ReloadCommand { + static register() { + storage.getContext().subscriptions.push( + vscode.commands.registerCommand("flexpilot.reload", () => { + InlineChatParticipant.reload(); + PanelChatParticipant.reload(); + events.fire({ + name: "inlineCompletionProviderUpdated", + payload: { updatedAt: Date.now() }, + }); + events.fire({ + name: "modelProvidersUpdated", + payload: { updatedAt: Date.now() }, + }); + }), + ); + logger.info("ReloadCommand registered"); + } +} diff --git a/src/inline-chat.ts b/src/inline-chat.ts index f88c4d8..8e8a990 100644 --- a/src/inline-chat.ts +++ b/src/inline-chat.ts @@ -14,7 +14,8 @@ import { getEol } from "./utilities"; class InlineChatParticipant { private static instance: InlineChatParticipant | null = null; private readonly chatParticipant: vscode.ChatParticipant; - // private readonly githubSession: vscode.AuthenticationSession; + private readonly session: vscode.AuthenticationSession; + private readonly icon: vscode.Uri | undefined; /** * Private constructor to prevent direct instantiation. @@ -27,12 +28,14 @@ class InlineChatParticipant { this.handleChatRequest.bind(this), ); - // Get the GitHub session - // this.githubSession = storage.session.get(); + // Get the Custom session + this.session = storage.customSession.get() || storage.session.get(); + this.icon = storage.customSession.icon(); // Set up requester information this.chatParticipant.requester = { - name: "anonymous", + name: this.session.account.label, + icon: this.icon, }; // Set chat participant icon @@ -60,6 +63,11 @@ class InlineChatParticipant { } } + public static reload() { + InlineChatParticipant.dispose(); + InlineChatParticipant.register(); + } + /** * Handles the chat request and generates a response. * @param {vscode.ChatRequest} request - The chat request. diff --git a/src/lazy-load.ts b/src/lazy-load.ts index 9d53192..cbad4a2 100644 --- a/src/lazy-load.ts +++ b/src/lazy-load.ts @@ -1,5 +1,6 @@ import { CommitMessageCommand } from "./commands/commit-message"; import { ConfigureModelCommand } from "./commands/configure-model"; +import { ReloadCommand } from "./commands/reload"; import { StatusIconMenuCommand } from "./commands/status-icon-menu"; import { events } from "./events"; import { logger } from "./logger"; @@ -31,6 +32,7 @@ export const activate = async () => { StatusIconMenuCommand.register(); CommitMessageCommand.register(); ConfigureModelCommand.register(); + ReloadCommand.register(); // Handle the session change SessionManager.register(); diff --git a/src/panel-chat.ts b/src/panel-chat.ts index 7b95ec0..5aaceda 100644 --- a/src/panel-chat.ts +++ b/src/panel-chat.ts @@ -14,15 +14,17 @@ import { VariablesManager } from "./variables"; class PanelChatParticipant { private static instance: PanelChatParticipant | null = null; private readonly chatParticipant: vscode.ChatParticipant; - // private readonly githubSession: vscode.AuthenticationSession; + private readonly session: vscode.AuthenticationSession; + private readonly icon: vscode.Uri | undefined; /** * Private constructor to prevent direct instantiation. * Initializes the chat participant with necessary providers and configurations. */ private constructor() { - // Get the GitHub session - // this.githubSession = storage.session.get(); + // Get the custom session + this.session = storage.customSession.get() || storage.session.get(); + this.icon = storage.customSession.icon(); // Create the chat participant this.chatParticipant = vscode.chat.createChatParticipant( @@ -63,10 +65,8 @@ class PanelChatParticipant { // Set up requester information this.chatParticipant.requester = { - name: "anonymous", - // icon: vscode.Uri.parse( - // `https://avatars.githubusercontent.com/u/${this.githubSession.account.id}`, - // ), + name: this.session.account.label, + icon: this.icon, }; // Set up help text variables prefix @@ -95,6 +95,11 @@ class PanelChatParticipant { } } + public static reload() { + PanelChatParticipant.dispose(); + PanelChatParticipant.register(); + } + /** * Handles the chat request and generates a response. * @param {vscode.ChatRequest} request - The chat request. diff --git a/src/storage.ts b/src/storage.ts index b814756..81cbe4e 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -99,6 +99,27 @@ class StorageManager { }, }; + /** + * Custom session info instead of GitHub. + */ + public customSession = { + get: (): vscode.AuthenticationSession | undefined => { + if (!this.context) { + throw new Error("Storage manager not initialized"); + } + return this.context.globalState.get("customSession"); + }, + icon: (): vscode.Uri | undefined => { + if (!this.context) { + throw new Error("Storage manager not initialized"); + } + const url = this.context.globalState.get("customIcon"); + if (url) { + return vscode.Uri.parse(url as string); + } + }, + }; + public models = { /** * Retrieves a value from model providers.