Skip to content

Commit 0eea1d8

Browse files
authored
Merge pull request aws#7053 from ashishrp-aws/feature/agentic-chat
fix(chat): fix for stop button for disappearing for subsequent conversations
2 parents ad148d4 + 40e3f3d commit 0eea1d8

File tree

8 files changed

+104
-136
lines changed

8 files changed

+104
-136
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@
525525
"@aws-sdk/s3-request-presigner": "<3.731.0",
526526
"@aws-sdk/smithy-client": "<3.731.0",
527527
"@aws-sdk/util-arn-parser": "<3.731.0",
528-
"@aws/mynah-ui": "^4.31.0-beta.2",
528+
"@aws/mynah-ui": "^4.31.0-beta.3",
529529
"@gerhobbelt/gitignore-parser": "^0.2.0-9",
530530
"@iarna/toml": "^2.2.5",
531531
"@smithy/fetch-http-handler": "^5.0.1",

packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class Connector extends BaseConnector {
290290
}
291291

292292
if (messageData.type === 'asyncEventProgressMessage') {
293-
const isPromptInputDisabled = true
293+
const isPromptInputDisabled = false
294294
this.onAsyncEventProgress(
295295
messageData.tabID,
296296
messageData.inProgress,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class FollowUpInteractionHandler {
4747
if (followUp.prompt !== undefined) {
4848
this.mynahUI.updateStore(tabID, {
4949
loadingChat: true,
50-
cancelButtonWhenLoading: false,
5150
promptInputDisabledState: true,
5251
})
5352
this.mynahUI.addChatItem(tabID, {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ export const createMynahUI = (
471471
) {
472472
mynahUI.updateStore(tabID, {
473473
loadingChat: true,
474-
cancelButtonWhenLoading: false,
475474
promptInputDisabledState: true,
476475
})
477476

packages/core/src/amazonq/webview/ui/messages/controller.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export class MessageController {
8888

8989
this.mynahUI.updateStore(selectedTab.id, {
9090
loadingChat: true,
91-
cancelButtonWhenLoading: false,
9291
promptInputDisabledState: true,
9392
})
9493
this.mynahUI.addChatItem(selectedTab.id, message)
@@ -120,7 +119,6 @@ export class MessageController {
120119

121120
this.mynahUI.updateStore(newTabID, {
122121
loadingChat: true,
123-
cancelButtonWhenLoading: false,
124122
promptInputDisabledState: true,
125123
})
126124

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class TextMessageHandler {
3636

3737
this.mynahUI.updateStore(tabID, {
3838
loadingChat: true,
39-
cancelButtonWhenLoading: false,
4039
promptInputDisabledState: true,
4140
})
4241

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

Lines changed: 98 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -103,107 +103,122 @@ export class QuickActionHandler {
103103
}
104104
}
105105

106-
private handleScanCommand(tabID: string, eventId: string | undefined) {
107-
if (!this.isScanEnabled) {
106+
/**
107+
* Common helper method to handle specialized tab commands (scan, test, transform)
108+
* @param options Configuration options for the specialized tab
109+
*/
110+
private handleSpecializedTabCommand(options: {
111+
tabID: string // Current tab ID
112+
eventId?: string // Event ID for tracking
113+
isEnabled: boolean // Feature flag
114+
tabType: TabType // Type of tab to create/switch to
115+
existingTabType: TabType // Type to look for in existing tabs
116+
taskName?: string // Optional task name
117+
promptText?: string // Optional prompt text
118+
onExistingTab: (tabId: string) => void // Callback for existing tab
119+
onNewTab: (tabId: string) => void // Callback for new tab
120+
}): void {
121+
if (!options.isEnabled) {
108122
return
109123
}
110-
let scanTabId: string | undefined = undefined
111124

125+
// Check if a tab of this type already exists
126+
let existingTabId: string | undefined = undefined
112127
for (const tab of this.tabsStorage.getTabs()) {
113-
if (tab.type === 'review') {
114-
scanTabId = tab.id
128+
if (tab.type === options.existingTabType) {
129+
existingTabId = tab.id
130+
break
115131
}
116132
}
117133

118-
if (scanTabId !== undefined) {
119-
this.mynahUI.selectTab(scanTabId, eventId || '')
120-
this.connector.onTabChange(scanTabId)
121-
this.connector.scans(scanTabId)
134+
// If tab exists, select it and run the callback
135+
if (existingTabId !== undefined) {
136+
this.mynahUI.selectTab(existingTabId, options.eventId || '')
137+
this.connector.onTabChange(existingTabId)
138+
options.onExistingTab(existingTabId)
122139
return
123140
}
124141

125-
let affectedTabId: string | undefined = tabID
126-
// if there is no scan tab, open a new one
142+
// Otherwise, create a new tab
143+
let affectedTabId: string | undefined = options.tabID
144+
145+
// If current tab is not unknown or welcome, create a new tab
127146
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
128147
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
129148
affectedTabId = this.mynahUI.updateStore('', {
130149
loadingChat: true,
131150
})
132151
}
133152

153+
// Handle case where we can't create a new tab
134154
if (affectedTabId === undefined) {
135155
this.mynahUI.notify({
136156
content: uiComponentsTexts.noMoreTabsTooltip,
137157
type: NotificationType.WARNING,
138158
})
139159
return
140-
} else {
141-
this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, 'review')
142-
this.connector.onKnownTabOpen(affectedTabId)
143-
this.connector.onUpdateTabType(affectedTabId)
144-
145-
// reset chat history
146-
this.mynahUI.updateStore(affectedTabId, {
147-
chatItems: [],
148-
})
149-
150-
this.mynahUI.updateStore(affectedTabId, this.tabDataGenerator.getTabData('review', true, undefined)) // creating a new tab and printing some title
151-
152-
// disable chat prompt
153-
this.mynahUI.updateStore(affectedTabId, {
154-
loadingChat: true,
155-
})
156-
this.connector.scans(affectedTabId)
157160
}
158-
}
159161

160-
private handleTestCommand(chatPrompt: ChatPrompt, tabID: string, eventId: string | undefined) {
161-
if (!this.isTestEnabled) {
162-
return
163-
}
164-
const testTabId = this.tabsStorage.getTabs().find((tab) => tab.type === 'testgen')?.id
165-
const realPromptText = chatPrompt.escapedPrompt?.trim() ?? ''
162+
// Set up the new tab
163+
this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, options.tabType)
164+
this.connector.onKnownTabOpen(affectedTabId)
165+
this.connector.onUpdateTabType(affectedTabId)
166166

167-
if (testTabId !== undefined) {
168-
this.mynahUI.selectTab(testTabId, eventId || '')
169-
this.connector.onTabChange(testTabId)
170-
this.connector.startTestGen(testTabId, realPromptText)
171-
return
172-
}
167+
// Reset chat history
168+
this.mynahUI.updateStore(affectedTabId, {
169+
chatItems: [],
170+
})
173171

174-
let affectedTabId: string | undefined = tabID
175-
// if there is no test tab, open a new one
176-
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
177-
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
178-
affectedTabId = this.mynahUI.updateStore('', {
179-
loadingChat: true,
180-
})
181-
}
172+
// Set tab data
173+
const isEmpty = options.promptText === undefined || options.promptText === ''
174+
this.mynahUI.updateStore(
175+
affectedTabId,
176+
this.tabDataGenerator.getTabData(options.tabType, isEmpty, options.taskName)
177+
)
182178

183-
if (affectedTabId === undefined) {
184-
this.mynahUI.notify({
185-
content: uiComponentsTexts.noMoreTabsTooltip,
186-
type: NotificationType.WARNING,
187-
})
188-
return
189-
} else {
190-
this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, 'testgen')
191-
this.connector.onKnownTabOpen(affectedTabId)
192-
this.connector.onUpdateTabType(affectedTabId)
179+
// Disable chat prompt while loading
180+
this.mynahUI.updateStore(affectedTabId, {
181+
loadingChat: true,
182+
})
193183

194-
// reset chat history
195-
this.mynahUI.updateStore(affectedTabId, {
196-
chatItems: [],
197-
})
184+
// Run the callback for the new tab
185+
options.onNewTab(affectedTabId)
186+
}
198187

199-
// creating a new tab and printing some title
200-
this.mynahUI.updateStore(
201-
affectedTabId,
202-
this.tabDataGenerator.getTabData('testgen', realPromptText === '', 'Q - Test')
203-
)
188+
private handleScanCommand(tabID: string, eventId: string | undefined) {
189+
this.handleSpecializedTabCommand({
190+
tabID,
191+
eventId,
192+
isEnabled: this.isScanEnabled,
193+
tabType: 'review',
194+
existingTabType: 'review',
195+
onExistingTab: (tabId) => {
196+
this.connector.scans(tabId)
197+
},
198+
onNewTab: (tabId) => {
199+
this.connector.scans(tabId)
200+
},
201+
})
202+
}
204203

205-
this.connector.startTestGen(affectedTabId, realPromptText)
206-
}
204+
private handleTestCommand(chatPrompt: ChatPrompt, tabID: string, eventId: string | undefined) {
205+
const realPromptText = chatPrompt.escapedPrompt?.trim() ?? ''
206+
207+
this.handleSpecializedTabCommand({
208+
tabID,
209+
eventId,
210+
isEnabled: this.isTestEnabled,
211+
tabType: 'testgen',
212+
existingTabType: 'testgen',
213+
taskName: 'Q - Test',
214+
promptText: realPromptText,
215+
onExistingTab: (tabId) => {
216+
this.connector.startTestGen(tabId, realPromptText)
217+
},
218+
onNewTab: (tabId) => {
219+
this.connector.startTestGen(tabId, realPromptText)
220+
},
221+
})
207222
}
208223

209224
private handleCommand(props: HandleCommandProps) {
@@ -272,7 +287,6 @@ export class QuickActionHandler {
272287

273288
this.mynahUI.updateStore(affectedTabId, {
274289
loadingChat: true,
275-
cancelButtonWhenLoading: false,
276290
promptInputDisabledState: true,
277291
})
278292

@@ -286,60 +300,19 @@ export class QuickActionHandler {
286300
}
287301

288302
private handleGumbyCommand(tabID: string, eventId: string | undefined) {
289-
if (!this.isGumbyEnabled) {
290-
return
291-
}
292-
293-
let gumbyTabId: string | undefined = undefined
294-
295-
for (const tab of this.tabsStorage.getTabs()) {
296-
if (tab.type === 'gumby') {
297-
gumbyTabId = tab.id
298-
}
299-
}
300-
301-
if (gumbyTabId !== undefined) {
302-
this.mynahUI.selectTab(gumbyTabId, eventId || '')
303-
this.connector.onTabChange(gumbyTabId)
304-
return
305-
}
306-
307-
let affectedTabId: string | undefined = tabID
308-
// if there is no gumby tab, open a new one
309-
const currentTabType = this.tabsStorage.getTab(affectedTabId)?.type
310-
if (currentTabType !== 'unknown' && currentTabType !== 'welcome') {
311-
affectedTabId = this.mynahUI.updateStore('', {
312-
loadingChat: true,
313-
cancelButtonWhenLoading: false,
314-
})
315-
}
316-
317-
if (affectedTabId === undefined) {
318-
this.mynahUI.notify({
319-
content: uiComponentsTexts.noMoreTabsTooltip,
320-
type: NotificationType.WARNING,
321-
})
322-
return
323-
} else {
324-
this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, 'gumby')
325-
this.connector.onKnownTabOpen(affectedTabId)
326-
this.connector.onUpdateTabType(affectedTabId)
327-
328-
// reset chat history
329-
this.mynahUI.updateStore(affectedTabId, {
330-
chatItems: [],
331-
})
332-
333-
this.mynahUI.updateStore(affectedTabId, this.tabDataGenerator.getTabData('gumby', true, undefined))
334-
335-
// disable chat prompt
336-
this.mynahUI.updateStore(affectedTabId, {
337-
loadingChat: true,
338-
cancelButtonWhenLoading: false,
339-
})
340-
341-
this.connector.transform(affectedTabId)
342-
}
303+
this.handleSpecializedTabCommand({
304+
tabID,
305+
eventId,
306+
isEnabled: this.isGumbyEnabled,
307+
tabType: 'gumby',
308+
existingTabType: 'gumby',
309+
onExistingTab: () => {
310+
// Nothing special to do for existing transform tab
311+
},
312+
onNewTab: (tabId) => {
313+
this.connector.transform(tabId)
314+
},
315+
})
343316
}
344317

345318
private handleClearCommand(tabID: string) {

0 commit comments

Comments
 (0)