Skip to content

Commit b127942

Browse files
authored
fix(amazonq): quick action handler should add to tab storage (#7070)
## Problem currently tabs get added to the tabs storage when the onTabAdd handler gets called. In hybrid chat, the onTabAdd handler will never get called, because it first needs to be in the tabsStorage, which doesn't happen because the onTabAdd handler hasn't been called ## Solution in hybrid chat mode just add new tabs directly to the tabs storage --- - 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 726ccd8 commit b127942

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export class WebviewUIHandler {
210210
isScanEnabled: this.isScanEnabled,
211211
isTestEnabled: this.isTestEnabled,
212212
isDocEnabled: this.isDocEnabled,
213+
hybridChat,
213214
disabledCommands,
214215
})
215216

@@ -659,8 +660,11 @@ export class WebviewUIHandler {
659660
},
660661
onTabAdd: (tabID: string) => {
661662
if (hybridChat) {
662-
// hybrid chat doesn't support the welcome page
663-
this.connector?.onTabAdd(tabID)
663+
/**
664+
* hybrid chat doesn't support the welcome page
665+
* tabs are already added by the quick action handler
666+
* so theres nothing we have to do here
667+
*/
664668
return
665669
}
666670
/**
@@ -1038,6 +1042,7 @@ export class WebviewUIHandler {
10381042
isScanEnabled: this.isScanEnabled,
10391043
isTestEnabled: this.isTestEnabled,
10401044
isDocEnabled: this.isDocEnabled,
1045+
hybridChat,
10411046
})
10421047
this.textMessageHandler = new TextMessageHandler({
10431048
mynahUIRef: this.mynahUIRef,

packages/core/src/amazonq/webview/ui/quickActions/handler.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface QuickActionsHandlerProps {
1919
isScanEnabled: boolean
2020
isTestEnabled: boolean
2121
isDocEnabled: boolean
22+
hybridChat?: boolean
2223
disabledCommands?: string[]
2324
}
2425

@@ -40,6 +41,7 @@ export class QuickActionHandler {
4041
private isScanEnabled: boolean
4142
private isTestEnabled: boolean
4243
private isDocEnabled: boolean
44+
private isHybridChatEnabled: boolean
4345

4446
constructor(props: QuickActionsHandlerProps) {
4547
this.mynahUIRef = props.mynahUIRef
@@ -58,6 +60,7 @@ export class QuickActionHandler {
5860
this.isGumbyEnabled = props.isGumbyEnabled
5961
this.isScanEnabled = props.isScanEnabled
6062
this.isTestEnabled = props.isTestEnabled
63+
this.isHybridChatEnabled = props.hybridChat ?? false
6164
}
6265

6366
/**
@@ -123,14 +126,8 @@ export class QuickActionHandler {
123126
return
124127
}
125128

126-
let affectedTabId: string | undefined = tabID
127129
// if there is no scan tab, open a new one
128-
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
129-
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
130-
affectedTabId = this.mynahUI.updateStore('', {
131-
loadingChat: true,
132-
})
133-
}
130+
const affectedTabId: string | undefined = this.addTab(tabID)
134131

135132
if (affectedTabId === undefined) {
136133
this.mynahUI.notify({
@@ -172,14 +169,8 @@ export class QuickActionHandler {
172169
return
173170
}
174171

175-
let affectedTabId: string | undefined = tabID
176172
// if there is no test tab, open a new one
177-
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
178-
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
179-
affectedTabId = this.mynahUI.updateStore('', {
180-
loadingChat: true,
181-
})
182-
}
173+
const affectedTabId: string | undefined = this.addTab(tabID)
183174

184175
if (affectedTabId === undefined) {
185176
this.mynahUI.notify({
@@ -212,12 +203,10 @@ export class QuickActionHandler {
212203
return
213204
}
214205

215-
let affectedTabId: string | undefined = props.tabID
216206
const realPromptText = props.chatPrompt?.escapedPrompt?.trim() ?? ''
217-
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
218-
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
219-
affectedTabId = this.mynahUI.updateStore('', {})
220-
}
207+
208+
const affectedTabId = this.addTab(props.tabID)
209+
221210
if (affectedTabId === undefined) {
222211
this.mynahUI.notify({
223212
content: uiComponentsTexts.noMoreTabsTooltip,
@@ -305,15 +294,8 @@ export class QuickActionHandler {
305294
return
306295
}
307296

308-
let affectedTabId: string | undefined = tabID
309297
// if there is no gumby tab, open a new one
310-
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
311-
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
312-
affectedTabId = this.mynahUI.updateStore('', {
313-
loadingChat: true,
314-
cancelButtonWhenLoading: false,
315-
})
316-
}
298+
const affectedTabId: string | undefined = this.addTab(tabID)
317299

318300
if (affectedTabId === undefined) {
319301
this.mynahUI.notify({
@@ -343,6 +325,33 @@ export class QuickActionHandler {
343325
}
344326
}
345327

328+
private addTab(affectedTabId: string | undefined) {
329+
if (!affectedTabId || !this.mynahUI) {
330+
return
331+
}
332+
333+
const currTab = this.mynahUI.getAllTabs()[affectedTabId]
334+
const currTabWasUsed =
335+
(currTab.store?.chatItems?.filter((item) => item.type === ChatItemType.PROMPT).length ?? 0) > 0
336+
if (currTabWasUsed) {
337+
affectedTabId = this.mynahUI.updateStore('', {
338+
loadingChat: true,
339+
cancelButtonWhenLoading: false,
340+
})
341+
}
342+
343+
if (affectedTabId && this.isHybridChatEnabled) {
344+
this.tabsStorage.addTab({
345+
id: affectedTabId,
346+
type: 'unknown',
347+
status: 'free',
348+
isSelected: true,
349+
})
350+
}
351+
352+
return affectedTabId
353+
}
354+
346355
private handleClearCommand(tabID: string) {
347356
this.mynahUI?.updateStore(tabID, {
348357
chatItems: [],

0 commit comments

Comments
 (0)