Skip to content

Commit ebe7b8c

Browse files
authored
feat(amazonq): sync developer profiles to flare chat panel (#7072)
## Problem - developer profiles are only synced to our local agents (/dev, /doc, etc). Now that the main chat panel is served by flare we need to update the profile information when it becomes available so that flare is using the correct profile for the request ## Solution - send profile information to flare on the initial request + subsequent changes to the active profile - refresh the webview if the profile changes --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 91cd6e3 commit ebe7b8c

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

packages/amazonq/src/lsp/chat/activation.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ import { registerLanguageServerEventListener, registerMessageListeners } from '.
1111
import { getLogger, globals } from 'aws-core-vscode/shared'
1212
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
1313
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
14+
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
15+
import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol'
1416

1517
export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
18+
// Make sure we've sent an auth profile to the language server before even initializing the UI
19+
await updateProfile(languageClient)
20+
1621
const provider = new AmazonQChatViewProvider(mynahUIPath)
1722

1823
globals.context.subscriptions.push(
@@ -44,4 +49,21 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
4449

4550
// register event listeners from the legacy agent flow
4651
await registerLegacyChatListeners(globals.context)
52+
53+
globals.context.subscriptions.push(
54+
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
55+
void updateProfile(languageClient)
56+
await provider.refreshWebview()
57+
})
58+
)
59+
}
60+
61+
async function updateProfile(client: LanguageClient) {
62+
// update the profile on the language server
63+
await client.sendRequest(updateConfigurationRequestType.method, {
64+
section: 'aws.q',
65+
settings: {
66+
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
67+
},
68+
})
4769
}

packages/amazonq/src/lsp/chat/webviewProvider.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
3030

3131
webview: Webview | undefined
3232

33+
connectorAdapterPath?: string
34+
uiPath?: string
35+
3336
constructor(private readonly mynahUIPath: string) {}
3437

3538
public async resolveWebviewView(
@@ -49,20 +52,22 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
4952

5053
const source = 'vue/src/amazonq/webview/ui/amazonq-ui-connector-adapter.js' // Sent to dist/vue folder in webpack.
5154
const serverHostname = process.env.WEBPACK_DEVELOPER_SERVER
52-
const connectorAdapterPath =
55+
56+
this.connectorAdapterPath =
5357
serverHostname !== undefined
5458
? Uri.parse(serverHostname)
5559
.with({ path: `/${source}` })
5660
.toString()
5761
: webviewView.webview.asWebviewUri(Uri.parse(path.join(dist.fsPath, source))).toString()
58-
const uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()
59-
webviewView.webview.html = await this.getWebviewContent(uiPath, connectorAdapterPath)
62+
this.uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()
63+
64+
webviewView.webview.html = await this.getWebviewContent()
6065

6166
this.onDidResolveWebviewEmitter.fire()
6267
performance.mark(amazonqMark.open)
6368
}
6469

65-
private async getWebviewContent(mynahUIPath: string, hybridChatConnector: string) {
70+
private async getWebviewContent() {
6671
const featureConfigData = await featureConfig.getFeatureConfigs()
6772

6873
const isSM = isSageMaker('SMAI')
@@ -110,8 +115,8 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
110115
</style>
111116
</head>
112117
<body>
113-
<script type="text/javascript" src="${mynahUIPath.toString()}" defer onload="init()"></script>
114-
<script type="text/javascript" src="${hybridChatConnector.toString()}"></script>
118+
<script type="text/javascript" src="${this.uiPath?.toString()}" defer onload="init()"></script>
119+
<script type="text/javascript" src="${this.connectorAdapterPath?.toString()}"></script>
115120
<script type="text/javascript">
116121
const init = () => {
117122
const vscodeApi = acquireVsCodeApi()
@@ -123,4 +128,11 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
123128
</body>
124129
</html>`
125130
}
131+
132+
async refreshWebview() {
133+
if (this.webview) {
134+
// refresh the webview when the profile changes
135+
this.webview.html = await this.getWebviewContent()
136+
}
137+
}
126138
}

packages/amazonq/src/lsp/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export async function startLanguageServer(
7272
clientId: crypto.randomUUID(),
7373
},
7474
awsClientCapabilities: {
75+
q: {
76+
developerProfiles: true,
77+
},
7578
window: {
7679
notifications: true,
7780
showSaveFileDialog: true,

0 commit comments

Comments
 (0)