Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amazonq): Add UI Update for Progress bar and New button for Canc… #6247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Add Progress Bar UI changes and new button for cancelling code generation to /dev"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChatItem, ChatItemType, FeedbackPayload } from '@aws/mynah-ui'
import { ChatItem, ChatItemType, FeedbackPayload, ProgressField } from '@aws/mynah-ui'
import { TabType } from '../storages/tabsStorage'
import { getActions } from '../diffTree/actions'
import { DiffTreeFileInfo } from '../diffTree/types'
Expand Down Expand Up @@ -31,6 +31,9 @@
onChatInputEnabled: (tabID: string, enabled: boolean) => void
onUpdateAuthentication: (featureDevEnabled: boolean, authenticatingTabIDs: string[]) => void
onNewTab: (tabType: TabType) => void
onUpdatePromptProgress: (tabID: string, progressField: ProgressField | null) => void;

Check failure on line 34 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `;`
onCustomFormAction?: (tabID: string, action: any) => void

Check failure on line 35 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `⏎`

}

export class Connector extends BaseConnector {
Expand All @@ -41,6 +44,8 @@
private readonly chatInputEnabled
private readonly onUpdateAuthentication
private readonly onNewTab
private readonly onUpdatePromptProgress

Check failure on line 47 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `⏎`


override getTabType(): TabType {
return 'featuredev'
Expand All @@ -55,6 +60,12 @@
this.onUpdateAuthentication = props.onUpdateAuthentication
this.onNewTab = props.onNewTab
this.onChatAnswerUpdated = props.onChatAnswerUpdated
this.onUpdatePromptProgress = props.onUpdatePromptProgress;

Check failure on line 63 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `;`
}

Check failure on line 65 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `····`
sendProgressUpdate(tabID: string, progressField: ProgressField | null): void {
this.onUpdatePromptProgress(tabID, progressField);

Check failure on line 67 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `;⏎····`

}

onOpenDiff = (tabID: string, filePath: string, deleted: boolean, messageId?: string): void => {
Expand Down Expand Up @@ -199,6 +210,10 @@
this.onNewTab('featuredev')
return
}
if (messageData.type === 'updatePromptProgress') {
this.sendProgressUpdate(messageData.tabID, messageData.progressField);

Check failure on line 214 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `;`
return;

Check failure on line 215 in packages/core/src/amazonq/webview/ui/apps/featureDevChatConnector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `;`
}

// For other message types, call the base class handleMessageReceive
await this.baseHandleMessageReceive(messageData)
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/amazonq/webview/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
disableFileActions: boolean
) => void
onUpdatePlaceholder: (tabID: string, newPlaceholder: string) => void
onUpdatePromptProgress: (tabID: string, progressField: ProgressField) => void
onUpdatePromptProgress: (tabID: string, progressField: ProgressField | null) => void;

Check failure on line 83 in packages/core/src/amazonq/webview/ui/connector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `;`
onChatInputEnabled: (tabID: string, enabled: boolean) => void
onUpdateAuthentication: (featureDevEnabled: boolean, authenticatingTabIDs: string[]) => void
onNewTab: (tabType: TabType) => void
Expand Down Expand Up @@ -129,8 +129,7 @@
this.cwChatConnector.onSourceLinkClick(tabID, messageId, link)
break
}
}

}

Check failure on line 132 in packages/core/src/amazonq/webview/ui/connector.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Delete `···`
onResponseBodyLinkClick = (tabID: string, messageId: string, link: string): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand Down Expand Up @@ -625,6 +624,11 @@
eventId: string | undefined = undefined
): void | undefined => {
switch (this.tabsStorage.getTab(tabId)?.type) {
case 'featuredev':
if (action.id === 'cancel-running-task') {
this.onStopChatResponse(tabId);
}
break
case 'gumby':
this.gumbyChatConnector.onCustomFormAction(tabId, action)
break
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/amazonq/webview/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export const createMynahUI = (
promptInputDisabledState: tabsStorage.isTabDead(tabID) || !enabled,
})
},
onUpdatePromptProgress(tabID: string, progressField: ProgressField) {
onUpdatePromptProgress(tabID: string, progressField: ProgressField | null) {
mynahUI.updateStore(tabID, {
promptInputProgress: progressField,
})
Expand All @@ -266,7 +266,6 @@ export const createMynahUI = (
mynahUI.updateStore(tabID, {
loadingChat: true,
promptInputDisabledState: true,
cancelButtonWhenLoading: enableStopAction,
})

if (message && messageId) {
Expand Down Expand Up @@ -364,7 +363,6 @@ export const createMynahUI = (
) {
mynahUI.updateStore(tabID, {
loadingChat: true,
cancelButtonWhenLoading: false,
promptInputDisabledState: true,
})

Expand Down Expand Up @@ -672,11 +670,10 @@ export const createMynahUI = (
}
}
},
onCustomFormAction: (tabId, action, eventId) => {
connector.onCustomFormAction(tabId, undefined, action, eventId)
},
onChatPromptProgressActionButtonClicked: (tabID, action) => {
connector.onCustomFormAction(tabID, undefined, action)
if (action.id === 'cancel-running-task') {
connector.onStopChatResponse(tabID);
}
},
onSendFeedback: (tabId, feedbackPayload) => {
connector.sendFeedback(tabId, feedbackPayload)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/amazonqFeatureDev/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function init(appContext: AmazonQAppInitContext) {
insertCodeAtPositionClicked: new vscode.EventEmitter<any>(),
fileClicked: new vscode.EventEmitter<any>(),
storeCodeResultMessageId: new vscode.EventEmitter<any>(),
processCustomFormAction: new vscode.EventEmitter<any>(),
}

const messenger = new Messenger(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { MynahIcons } from '@aws/mynah-ui'
import { MynahIcons, ProgressField } from '@aws/mynah-ui'
import * as path from 'path'
import * as vscode from 'vscode'
import { EventEmitter } from 'vscode'
Expand Down Expand Up @@ -65,6 +65,8 @@ export interface ChatControllerEventEmitters {
readonly insertCodeAtPositionClicked: EventEmitter<any>
readonly fileClicked: EventEmitter<any>
readonly storeCodeResultMessageId: EventEmitter<any>
readonly processCustomFormAction: EventEmitter<any>

}

type OpenDiffMessage = {
Expand Down Expand Up @@ -116,7 +118,12 @@ export class FeatureDevController {
onDidChangeAmazonQVisibility((visible) => {
this.isAmazonQVisible = visible
})

this.chatControllerMessageListeners.processCustomFormAction.event((data) => {
if (data.action?.id === 'cancel-running-task') {
this.stopResponse({ tabID: data.tabID });
}
});

this.chatControllerMessageListeners.processHumanChatMessage.event((data) => {
this.processUserChatMessage(data).catch((e) => {
getLogger().error('processUserChatMessage failed: %s', (e as Error).message)
Expand Down Expand Up @@ -396,7 +403,23 @@ export class FeatureDevController {
* Handle a regular incoming message when a user is in the code generation phase
*/
private async onCodeGeneration(session: Session, message: string, tabID: string) {
// lock the UI/show loading bubbles

const updateProgress = (text: string) => {
const progressField: ProgressField = {
status: 'default',
text: text,
value: -1,
actions: [{
id: 'cancel-running-task',
text: 'Cancel',
icon: 'cancel' as MynahIcons,
disabled: false,
}]
};
this.messenger.sendUpdatePromptProgress(tabID, progressField);
this.messenger.sendAsyncEventProgress(tabID, true, text);
};

this.messenger.sendAsyncEventProgress(
tabID,
true,
Expand All @@ -405,13 +428,21 @@ export class FeatureDevController {
: i18n('AWS.amazonq.featureDev.pillText.awaitMessageRetry')
)

updateProgress(session.retries === codeGenRetryLimit
? i18n('AWS.amazonq.featureDev.pillText.awaitMessage')
: i18n('AWS.amazonq.featureDev.pillText.awaitMessageRetry'));

try {

updateProgress(i18n('AWS.amazonq.featureDev.pillText.requestingChanges'));
this.messenger.sendAnswer({
message: i18n('AWS.amazonq.featureDev.pillText.requestingChanges'),
type: 'answer-stream',
tabID,
canBeVoted: true,
})

updateProgress(i18n('AWS.amazonq.featureDev.pillText.generatingCode'));
this.messenger.sendUpdatePlaceholder(tabID, i18n('AWS.amazonq.featureDev.pillText.generatingCode'))
await session.send(message)
const filePaths = session.state.filePaths ?? []
Expand Down Expand Up @@ -447,6 +478,7 @@ export class FeatureDevController {
return
}

updateProgress(i18n('AWS.amazonq.featureDev.pillText.processingChanges'));
this.messenger.sendCodeResult(
filePaths,
deletedFiles,
Expand Down Expand Up @@ -487,7 +519,7 @@ export class FeatureDevController {
}
this.messenger.sendUpdatePlaceholder(tabID, i18n('AWS.amazonq.featureDev.pillText.selectOption'))
} finally {
// Finish processing the event
this.hideProgress(tabID);

if (session?.state?.tokenSource?.token.isCancellationRequested) {
this.workOnNewTask(
Expand Down Expand Up @@ -849,6 +881,7 @@ export class FeatureDevController {
i18n('AWS.amazonq.featureDev.pillText.stoppingCodeGeneration')
)
this.messenger.sendChatInputEnabled(message.tabID, false)
this.hideProgress(message.tabID);

const session = await this.sessionStorage.getSession(message.tabID)
if (session.state?.tokenSource) {
Expand Down Expand Up @@ -940,6 +973,11 @@ export class FeatureDevController {
})
}

private hideProgress(tabID: string) {
this.messenger.sendUpdatePromptProgress(tabID, null);
this.messenger.sendAsyncEventProgress(tabID, false, undefined);
}

private sendFeedback() {
void submitFeedback(placeholder, 'Amazon Q')
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/test/amazonqFeatureDev/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function createMockChatEmitters(): ChatControllerEventEmitters {
insertCodeAtPositionClicked: new vscode.EventEmitter<any>(),
fileClicked: new vscode.EventEmitter<any>(),
storeCodeResultMessageId: new vscode.EventEmitter<any>(),
processCustomFormAction: new vscode.EventEmitter<any>(),

}
}

Expand Down
Loading