Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/core/src/amazonq/webview/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class WebviewUIHandler {
isScanEnabled: this.isScanEnabled,
isTestEnabled: this.isTestEnabled,
isDocEnabled: this.isDocEnabled,
hybridChat,
disabledCommands,
})

Expand Down Expand Up @@ -659,8 +660,11 @@ export class WebviewUIHandler {
},
onTabAdd: (tabID: string) => {
if (hybridChat) {
// hybrid chat doesn't support the welcome page
this.connector?.onTabAdd(tabID)
/**
* hybrid chat doesn't support the welcome page
* tabs are already added by the quick action handler
* so theres nothing we have to do here
*/
return
}
/**
Expand Down Expand Up @@ -1038,6 +1042,7 @@ export class WebviewUIHandler {
isScanEnabled: this.isScanEnabled,
isTestEnabled: this.isTestEnabled,
isDocEnabled: this.isDocEnabled,
hybridChat,
})
this.textMessageHandler = new TextMessageHandler({
mynahUIRef: this.mynahUIRef,
Expand Down
63 changes: 36 additions & 27 deletions packages/core/src/amazonq/webview/ui/quickActions/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface QuickActionsHandlerProps {
isScanEnabled: boolean
isTestEnabled: boolean
isDocEnabled: boolean
hybridChat?: boolean
disabledCommands?: string[]
}

Expand All @@ -40,6 +41,7 @@ export class QuickActionHandler {
private isScanEnabled: boolean
private isTestEnabled: boolean
private isDocEnabled: boolean
private isHybridChatEnabled: boolean

constructor(props: QuickActionsHandlerProps) {
this.mynahUIRef = props.mynahUIRef
Expand All @@ -58,6 +60,7 @@ export class QuickActionHandler {
this.isGumbyEnabled = props.isGumbyEnabled
this.isScanEnabled = props.isScanEnabled
this.isTestEnabled = props.isTestEnabled
this.isHybridChatEnabled = props.hybridChat ?? false
}

/**
Expand Down Expand Up @@ -123,14 +126,8 @@ export class QuickActionHandler {
return
}

let affectedTabId: string | undefined = tabID
// if there is no scan tab, open a new one
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
affectedTabId = this.mynahUI.updateStore('', {
loadingChat: true,
})
}
const affectedTabId: string | undefined = this.addTab(tabID)

if (affectedTabId === undefined) {
this.mynahUI.notify({
Expand Down Expand Up @@ -172,14 +169,8 @@ export class QuickActionHandler {
return
}

let affectedTabId: string | undefined = tabID
// if there is no test tab, open a new one
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
affectedTabId = this.mynahUI.updateStore('', {
loadingChat: true,
})
}
const affectedTabId: string | undefined = this.addTab(tabID)

if (affectedTabId === undefined) {
this.mynahUI.notify({
Expand Down Expand Up @@ -212,12 +203,10 @@ export class QuickActionHandler {
return
}

let affectedTabId: string | undefined = props.tabID
const realPromptText = props.chatPrompt?.escapedPrompt?.trim() ?? ''
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
affectedTabId = this.mynahUI.updateStore('', {})
}

const affectedTabId = this.addTab(props.tabID)

if (affectedTabId === undefined) {
this.mynahUI.notify({
content: uiComponentsTexts.noMoreTabsTooltip,
Expand Down Expand Up @@ -305,15 +294,8 @@ export class QuickActionHandler {
return
}

let affectedTabId: string | undefined = tabID
// if there is no gumby tab, open a new one
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
affectedTabId = this.mynahUI.updateStore('', {
loadingChat: true,
cancelButtonWhenLoading: false,
})
}
const affectedTabId: string | undefined = this.addTab(tabID)

if (affectedTabId === undefined) {
this.mynahUI.notify({
Expand Down Expand Up @@ -343,6 +325,33 @@ export class QuickActionHandler {
}
}

private addTab(affectedTabId: string | undefined) {
if (!affectedTabId || !this.mynahUI) {
return
}

const currTab = this.mynahUI.getAllTabs()[affectedTabId]
const currTabWasUsed =
(currTab.store?.chatItems?.filter((item) => item.type === ChatItemType.PROMPT).length ?? 0) > 0
if (currTabWasUsed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is this case for? What do we do differently when the tab is used/not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a note from Oksana's original p.o.c: https://github.com/aws/language-servers/pull/733/files. As far as I understand in flare you can't create a tab and then later convert it. In the old version we were basing things on tab types which wouldn't exist in chat-client so instead we're just checking if someones interacted with the current tab before re-using it. If its used we create a new tab, otherwise we re-use the current tab

affectedTabId = this.mynahUI.updateStore('', {
loadingChat: true,
cancelButtonWhenLoading: false,
})
}

if (affectedTabId && this.isHybridChatEnabled) {
this.tabsStorage.addTab({
id: affectedTabId,
type: 'unknown',
status: 'free',
isSelected: true,
})
}

return affectedTabId
}

private handleClearCommand(tabID: string) {
this.mynahUI?.updateStore(tabID, {
chatItems: [],
Expand Down
Loading