Skip to content

Commit 34bc67e

Browse files
authored
fix(amazonq): improve welcome page opening detection (#6171)
## Problem - the current implementation only opens the first tab as a welcome tab for the next 3 times you open vscode ## Solution - the new implementation shows the welcome tab 3 total times, either when you open a new chat tab or a new vscode window or both --- - 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 4d462e2 commit 34bc67e

File tree

6 files changed

+71
-40
lines changed

6 files changed

+71
-40
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Improve when the welcome page is shown in amazon q chat"
4+
}

packages/core/src/amazonq/webview/generators/webViewContent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class WebViewContentGenerator {
2323
return JSON.stringify(Array.from(featureConfigs.entries()))
2424
}
2525

26-
public async generate(extensionURI: Uri, webView: Webview, showWelcomePage: boolean): Promise<string> {
26+
public async generate(extensionURI: Uri, webView: Webview): Promise<string> {
2727
const entrypoint = process.env.WEBPACK_DEVELOPER_SERVER
2828
? 'http: localhost'
2929
: 'https: file+.vscode-resources.vscode-cdn.net'
@@ -47,14 +47,14 @@ export class WebViewContentGenerator {
4747
<head>
4848
<meta http-equiv="Content-Security-Policy" content="${contentPolicy}">
4949
<title>Amazon Q (Preview)</title>
50-
${await this.generateJS(extensionURI, webView, showWelcomePage)}
50+
${await this.generateJS(extensionURI, webView)}
5151
</head>
5252
<body ${featureDataAttributes}>
5353
</body>
5454
</html>`
5555
}
5656

57-
private async generateJS(extensionURI: Uri, webView: Webview, showWelcomePage: boolean): Promise<string> {
57+
private async generateJS(extensionURI: Uri, webView: Webview): Promise<string> {
5858
const source = path.join('vue', 'src', 'amazonq', 'webview', 'ui', 'amazonq-ui.js') // Sent to dist/vue folder in webpack.
5959
const assetsPath = Uri.joinPath(extensionURI)
6060
const javascriptUri = Uri.joinPath(assetsPath, 'dist', source)
@@ -80,14 +80,16 @@ export class WebViewContentGenerator {
8080
const disabledCommandsString = isSageMaker() ? `['/dev', '/transform']` : '[]'
8181
const disclaimerAcknowledged = globals.globalState.tryGet('aws.amazonq.disclaimerAcknowledged', Boolean, false)
8282

83+
const welcomeLoadCount = globals.globalState.tryGet('aws.amazonq.welcomeChatShowCount', Number, 0)
84+
8385
return `
8486
<script type="text/javascript" src="${javascriptEntrypoint.toString()}" defer onload="init()"></script>
8587
${cssLinks}
8688
<script type="text/javascript">
8789
const init = () => {
8890
createMynahUI(acquireVsCodeApi(), ${
8991
(await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'
90-
},${featureConfigsString},${showWelcomePage},${disclaimerAcknowledged},${disabledCommandsString});
92+
},${featureConfigsString},${welcomeLoadCount},${disclaimerAcknowledged},${disabledCommandsString});
9193
}
9294
</script>
9395
`

packages/core/src/amazonq/webview/messages/messageDispatcher.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export function dispatchWebViewMessagesToApps(
7474
globals.globalState.tryUpdate('aws.amazonq.disclaimerAcknowledged', true)
7575
return
7676
}
77+
case 'update-welcome-count': {
78+
const currentLoadCount = globals.globalState.tryGet('aws.amazonq.welcomeChatShowCount', Number, 0)
79+
void globals.globalState.tryUpdate('aws.amazonq.welcomeChatShowCount', currentLoadCount + 1)
80+
return
81+
}
7782
}
7883

7984
if (msg.type === 'error') {

packages/core/src/amazonq/webview/ui/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ type MessageCommand =
4141
| 'review'
4242
| 'open-user-guide'
4343
| 'send-telemetry'
44+
| 'update-welcome-count'
4445

4546
export type ExtensionMessage = Record<string, any> & { command: MessageCommand }

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ import { agentWalkthroughDataModel } from './walkthrough/agent'
3333
import { createClickTelemetry, createOpenAgentTelemetry } from './telemetry/actions'
3434
import { disclaimerAcknowledgeButtonId, disclaimerCard } from './texts/disclaimer'
3535

36+
/**
37+
* The number of welcome chat tabs that can be opened before the NEXT one will become
38+
* a regular chat tab.
39+
*/
40+
const welcomeCountThreshold = 3
41+
3642
export const createMynahUI = (
3743
ideApi: any,
3844
amazonQEnabled: boolean,
3945
featureConfigsSerialized: [string, FeatureContext][],
40-
showWelcomePage: boolean,
46+
welcomeCount: number,
4147
disclaimerAcknowledged: boolean,
4248
disabledCommands?: string[]
4349
) => {
@@ -70,11 +76,23 @@ export const createMynahUI = (
7076
})
7177
},
7278
})
79+
80+
const showWelcomePage = () => {
81+
return welcomeCount < welcomeCountThreshold
82+
}
83+
84+
const updateWelcomeCount = () => {
85+
ideApi.postMessage({
86+
command: 'update-welcome-count',
87+
})
88+
welcomeCount += 1
89+
}
90+
7391
// Adding the first tab as CWC tab
7492
tabsStorage.addTab({
7593
id: 'tab-1',
7694
status: 'free',
77-
type: showWelcomePage ? 'welcome' : 'cwc',
95+
type: showWelcomePage() ? 'welcome' : 'cwc',
7896
isSelected: true,
7997
})
8098

@@ -541,6 +559,25 @@ export const createMynahUI = (
541559
mynahUI = new MynahUI({
542560
onReady: connector.uiReady,
543561
onTabAdd: (tabID: string) => {
562+
/**
563+
* If the next tab opening will cross the welcome count threshold then
564+
* update the next tabs defaults
565+
*/
566+
if (welcomeCount + 1 >= welcomeCountThreshold) {
567+
tabsStorage.updateTabTypeFromUnknown(tabID, 'cwc')
568+
mynahUI?.updateTabDefaults({
569+
store: {
570+
...tabDataGenerator.getTabData('cwc', true),
571+
tabHeaderDetails: void 0,
572+
compactMode: false,
573+
tabBackground: false,
574+
},
575+
})
576+
} else {
577+
// we haven't reached the welcome count limit yet
578+
updateWelcomeCount()
579+
}
580+
544581
// If featureDev has changed availability inbetween the default store settings and now
545582
// make sure to show/hide it accordingly
546583
mynahUI.updateStore(tabID, {
@@ -812,15 +849,17 @@ export const createMynahUI = (
812849
'tab-1': {
813850
isSelected: true,
814851
store: {
815-
...(showWelcomePage
852+
...(showWelcomePage()
816853
? welcomeScreenTabData(tabDataGenerator).store
817854
: tabDataGenerator.getTabData('cwc', true)),
818855
...(disclaimerCardActive ? { promptInputStickyCard: disclaimerCard } : {}),
819856
},
820857
},
821858
},
822859
defaults: {
823-
store: tabDataGenerator.getTabData('cwc', true),
860+
store: showWelcomePage()
861+
? welcomeScreenTabData(tabDataGenerator).store
862+
: tabDataGenerator.getTabData('cwc', true),
824863
},
825864
config: {
826865
maxTabs: 10,
@@ -829,6 +868,14 @@ export const createMynahUI = (
829868
},
830869
})
831870

871+
/**
872+
* Update the welcome count if we've initially shown
873+
* the welcome page
874+
*/
875+
if (showWelcomePage()) {
876+
updateWelcomeCount()
877+
}
878+
832879
followUpsInteractionHandler = new FollowUpInteractionHandler({
833880
mynahUI,
834881
connector,

packages/core/src/amazonq/webview/webView.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ import { TabType } from './ui/storages/tabsStorage'
2222
import { deactivateInitialViewBadge, shouldShowBadge } from '../util/viewBadgeHandler'
2323
import { telemetry } from '../../shared/telemetry/telemetry'
2424
import { amazonqMark } from '../../shared/performance/marks'
25-
import { globals } from '../../shared'
26-
import { AuthUtil } from '../../codewhisperer/util/authUtil'
27-
28-
// The max number of times we should show the welcome to q chat panel before moving them to the regular one
29-
const maxWelcomeWebviewLoads = 3
3025

3126
export class AmazonQChatViewProvider implements WebviewViewProvider {
3227
public static readonly viewType = 'aws.AmazonQChatView'
@@ -65,33 +60,10 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
6560

6661
dispatchAppsMessagesToWebView(webviewView.webview, this.appsMessagesListener)
6762

68-
/**
69-
* Show the welcome to q chat ${maxWelcomeWebviewLoads} times before showing the normal panel
70-
*/
71-
const welcomeLoadCount = globals.globalState.tryGet('aws.amazonq.welcomeChatShowCount', Number, 0)
72-
if (welcomeLoadCount < maxWelcomeWebviewLoads) {
73-
webviewView.webview.html = await this.webViewContentGenerator.generate(
74-
this.extensionContext.extensionUri,
75-
webviewView.webview,
76-
true
77-
)
78-
79-
/**
80-
* resolveWebviewView gets called even when the user isn't logged in and the auth page is showing.
81-
* We don't want to incremenent the show count until the user has fully logged in and resolveWebviewView
82-
* gets called again
83-
*/
84-
const authenticated = (await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'
85-
if (authenticated) {
86-
await globals.globalState.update('aws.amazonq.welcomeChatShowCount', welcomeLoadCount + 1)
87-
}
88-
} else {
89-
webviewView.webview.html = await this.webViewContentGenerator.generate(
90-
this.extensionContext.extensionUri,
91-
webviewView.webview,
92-
false
93-
)
94-
}
63+
webviewView.webview.html = await this.webViewContentGenerator.generate(
64+
this.extensionContext.extensionUri,
65+
webviewView.webview
66+
)
9567

9668
performance.mark(amazonqMark.open)
9769

0 commit comments

Comments
 (0)