diff --git a/packages/amazonq/src/lsp/chat/activation.ts b/packages/amazonq/src/lsp/chat/activation.ts index 7cadafadb79..c4091827ab7 100644 --- a/packages/amazonq/src/lsp/chat/activation.ts +++ b/packages/amazonq/src/lsp/chat/activation.ts @@ -11,8 +11,13 @@ import { registerLanguageServerEventListener, registerMessageListeners } from '. import { getLogger, globals } from 'aws-core-vscode/shared' import { activate as registerLegacyChatListeners } from '../../app/chat/activation' import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq' +import { AuthUtil } from 'aws-core-vscode/codewhisperer' +import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol' export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) { + // Make sure we've sent an auth profile to the language server before even initializing the UI + await updateProfile(languageClient) + const provider = new AmazonQChatViewProvider(mynahUIPath) globals.context.subscriptions.push( @@ -44,4 +49,21 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu // register event listeners from the legacy agent flow await registerLegacyChatListeners(globals.context) + + globals.context.subscriptions.push( + AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => { + void updateProfile(languageClient) + await provider.refreshWebview() + }) + ) +} + +async function updateProfile(client: LanguageClient) { + // update the profile on the language server + await client.sendRequest(updateConfigurationRequestType.method, { + section: 'aws.q', + settings: { + profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn, + }, + }) } diff --git a/packages/amazonq/src/lsp/chat/webviewProvider.ts b/packages/amazonq/src/lsp/chat/webviewProvider.ts index 2c4d5755434..5ca3b51f21d 100644 --- a/packages/amazonq/src/lsp/chat/webviewProvider.ts +++ b/packages/amazonq/src/lsp/chat/webviewProvider.ts @@ -30,6 +30,9 @@ export class AmazonQChatViewProvider implements WebviewViewProvider { webview: Webview | undefined + connectorAdapterPath?: string + uiPath?: string + constructor(private readonly mynahUIPath: string) {} public async resolveWebviewView( @@ -49,20 +52,22 @@ export class AmazonQChatViewProvider implements WebviewViewProvider { const source = 'vue/src/amazonq/webview/ui/amazonq-ui-connector-adapter.js' // Sent to dist/vue folder in webpack. const serverHostname = process.env.WEBPACK_DEVELOPER_SERVER - const connectorAdapterPath = + + this.connectorAdapterPath = serverHostname !== undefined ? Uri.parse(serverHostname) .with({ path: `/${source}` }) .toString() : webviewView.webview.asWebviewUri(Uri.parse(path.join(dist.fsPath, source))).toString() - const uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString() - webviewView.webview.html = await this.getWebviewContent(uiPath, connectorAdapterPath) + this.uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString() + + webviewView.webview.html = await this.getWebviewContent() this.onDidResolveWebviewEmitter.fire() performance.mark(amazonqMark.open) } - private async getWebviewContent(mynahUIPath: string, hybridChatConnector: string) { + private async getWebviewContent() { const featureConfigData = await featureConfig.getFeatureConfigs() const isSM = isSageMaker('SMAI') @@ -110,8 +115,8 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
- - + +