Skip to content

Commit 40e3f3d

Browse files
committed
fix for opening prompt while agentic loop and lint fix for duplicate
1 parent f6f30e4 commit 40e3f3d

File tree

3 files changed

+99
-124
lines changed

3 files changed

+99
-124
lines changed

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/messages/controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export class MessageController {
119119

120120
this.mynahUI.updateStore(newTabID, {
121121
loadingChat: true,
122-
// cancelButtonWhenLoading: false,
123122
promptInputDisabledState: true,
124123
})
125124

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

Lines changed: 98 additions & 122 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) {
@@ -285,58 +300,19 @@ export class QuickActionHandler {
285300
}
286301

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

342318
private handleClearCommand(tabID: string) {

0 commit comments

Comments
 (0)