Skip to content

Commit

Permalink
fix(amazonq): align /doc messages with vscode (#5191)
Browse files Browse the repository at this point in the history
* Aligns a few /doc chat messages with strings from the vscode extension
* Fixes a bug where the checklist progress view wasn't showing up 
  * As part of this, I added support for disabling the "Stop" button at the bottom of the chat window when an async event is in progress. Similar to this vscode commit: aws/aws-toolkit-vscode@9c89c53#diff-8eb911f0ec050013422c6b3bd03c793a30f8c6ecf0eb63297cf4f10611b0274dR3
  • Loading branch information
aggagen authored Dec 12, 2024
1 parent 74b27eb commit 29b1a6c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.updateFileCo
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.DocSession
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.PrepareDocGenerationState
import software.aws.toolkits.jetbrains.services.amazonqDoc.storage.ChatSessionStorage
import software.aws.toolkits.jetbrains.services.amazonqDoc.util.getFollowUpOptions
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.CodeIterationLimitException
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.MonthlyConversationLimitError
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated
Expand Down Expand Up @@ -813,7 +814,6 @@ class DocController(

when (session.sessionState.phase) {
SessionStatePhase.CODEGEN -> {
messenger.sendUpdatePromptProgress(tabId, inProgress(progress = 10))
onCodeGeneration(session, message, tabId, mode)
}
else -> null
Expand Down Expand Up @@ -904,29 +904,7 @@ class DocController(
messenger.sendAnswer(
messageType = DocMessageType.SystemPrompt,
tabId = followUpMessage.tabId,
followUp = listOf(
FollowUp(
pillText = message("amazonqDoc.prompt.review.accept"),
prompt = message("amazonqDoc.prompt.review.accept"),
status = FollowUpStatusType.Success,
type = FollowUpTypes.ACCEPT_CHANGES,
icon = FollowUpIcons.Ok,
),
FollowUp(
pillText = message("amazonqDoc.prompt.review.changes"),
prompt = message("amazonqDoc.prompt.review.changes"),
status = FollowUpStatusType.Info,
type = FollowUpTypes.MAKE_CHANGES,
icon = FollowUpIcons.Info,
),
FollowUp(
pillText = message("general.reject"),
prompt = message("general.reject"),
status = FollowUpStatusType.Error,
type = FollowUpTypes.REJECT_CHANGES,
icon = FollowUpIcons.Cancel,
)
)
followUp = getFollowUpOptions(session.sessionState.phase)
)

processOpenDiff(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package software.aws.toolkits.jetbrains.services.amazonqDoc.controller

import com.intellij.notification.NotificationAction
import software.aws.toolkits.jetbrains.services.amazonqDoc.inProgress
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.DocMessageType
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUp
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUpStatusType
Expand All @@ -14,19 +15,27 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendChatInpu
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendCodeResult
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendSystemPrompt
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePlaceholder
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.DocSession
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.PrepareDocGenerationState
import software.aws.toolkits.jetbrains.services.amazonqDoc.util.getFollowUpOptions
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendSystemPrompt
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.DeletedFileInfo
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFileZipInfo
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.InsertAction
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.getFollowUpOptions
import software.aws.toolkits.jetbrains.utils.notifyInfo
import software.aws.toolkits.resources.message

suspend fun DocController.onCodeGeneration(session: DocSession, message: String, tabId: String, mode: Mode) {
try {
messenger.sendAsyncEventProgress(tabId, inProgress = true)
messenger.sendUpdatePromptProgress(tabId, inProgress(progress = 10, message("amazonqDoc.progress_message.scanning")))
messenger.sendAnswer(
message = docGenerationProgressMessage(DocGenerationStep.UPLOAD_TO_S3, this.mode),
messageType = DocMessageType.AnswerPart,
tabId = tabId,
)

val sessionMessage = if (mode == Mode.CREATE) {
message(
"amazonqDoc.session.create"
Expand Down Expand Up @@ -80,25 +89,27 @@ suspend fun DocController.onCodeGeneration(session: DocSession, message: String,
return
}

messenger.sendAnswer(
message = docGenerationProgressMessage(DocGenerationStep.COMPLETE, mode),
messageType = DocMessageType.AnswerPart,
tabId = tabId,
)

messenger.sendCodeResult(tabId = tabId, uploadId = uploadId, filePaths = filePaths, deletedFiles = deletedFiles, references = references)

if (remainingIterations != null && totalIterations != null) {
messenger.sendAnswer(
tabId = tabId,
messageType = DocMessageType.Answer,
message = if (remainingIterations == 0) {
message("amazonqFeatureDev.code_generation.iteration_zero")
message = if (this.mode === Mode.CREATE) {
message("amazonqDoc.answer.readmeCreated")
} else {
message(
"amazonqFeatureDev.code_generation.iteration_counts",
remainingIterations,
totalIterations
)
"${message("amazonqDoc.answer.readmeUpdated")} ${message("amazonqDoc.answer.codeResult")}"
}
)
}

messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase, InsertAction.ALL))
messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase))

messenger.sendUpdatePlaceholder(tabId = tabId, newPlaceholder = message("amazonqFeatureDev.placeholder.after_code_generation"))
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@ fun getFollowUpOptions(phase: SessionStatePhase?): List<FollowUp> {
SessionStatePhase.CODEGEN -> {
return listOf(
FollowUp(
pillText = message("amazonqDoc.follow_up.insert_code"),
type = FollowUpTypes.INSERT_CODE,
pillText = message("amazonqDoc.prompt.review.accept"),
prompt = message("amazonqDoc.prompt.review.accept"),
status = FollowUpStatusType.Success,
type = FollowUpTypes.ACCEPT_CHANGES,
icon = FollowUpIcons.Ok,
status = FollowUpStatusType.Success
),
FollowUp(
pillText = message("amazonqDoc.follow_up.provide_feedback_and_regenerate"),
type = FollowUpTypes.PROVIDE_FEEDBACK_AND_REGENERATE_CODE,
icon = FollowUpIcons.Refresh,
status = FollowUpStatusType.Info
pillText = message("amazonqDoc.prompt.review.changes"),
prompt = message("amazonqDoc.prompt.review.changes"),
status = FollowUpStatusType.Info,
type = FollowUpTypes.MAKE_CHANGES,
icon = FollowUpIcons.Info,
),
FollowUp(
pillText = message("general.reject"),
prompt = message("general.reject"),
status = FollowUpStatusType.Error,
type = FollowUpTypes.REJECT_CHANGES,
icon = FollowUpIcons.Cancel,
)
)
}

else -> return emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ConnectorProps {
sendMessageToExtension: (message: ExtensionMessage) => void
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
onUpdatePromptProgress: (tabID: string, progressField: ProgressField) => void
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string) => void
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string, cancelButtonWhenLoading?: boolean) => void
onChatAnswerReceived?: (tabID: string, message: ChatItem) => void
sendFeedback?: (tabId: string, feedbackPayload: FeedbackPayload) => void | undefined
onError: (tabID: string, message: string, title: string) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ChatPayload {
export interface ConnectorProps {
sendMessageToExtension: (message: ExtensionMessage) => void
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string) => void
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string, cancelButtonWhenLoading?: boolean) => void
onChatAnswerReceived?: (tabID: string, message: ChatItem) => void
onChatAnswerUpdated?: (tabID: string, message: ChatItem) => void
sendFeedback?: (tabId: string, feedbackPayload: FeedbackPayload) => void | undefined
Expand Down Expand Up @@ -249,7 +249,7 @@ export class Connector {
}

if (messageData.type === 'asyncEventProgressMessage') {
this.onAsyncEventProgress(messageData.tabID, messageData.inProgress, messageData.message ?? undefined)
this.onAsyncEventProgress(messageData.tabID, messageData.inProgress, messageData.message ?? undefined, true)
return
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface ConnectorProps {
onCodeTransformMessageUpdate: (tabID: string, messageId: string, chatItem: Partial<ChatItem>) => void
onRunTestMessageReceived?: (tabID: string, showRunTestMessage: boolean) => void
onWelcomeFollowUpClicked: (tabID: string, welcomeFollowUpType: WelcomeFollowupType) => void
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined) => void
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined, cancelButtonWhenLoading?: boolean) => void
onCWCContextCommandMessage: (message: ChatItem, command?: string) => string | undefined
onCWCOnboardingPageInteractionMessage: (message: ChatItem) => string | undefined
onOpenSettingsMessage: (tabID: string) => void
Expand Down
4 changes: 2 additions & 2 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ export const createMynahUI = (
promptInputDisabledState: tabsStorage.isTabDead(tabID) || !enabled,
})
},
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined) => {
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined, cancelButtonWhenLoading: boolean = false) => {
if (inProgress) {
mynahUI.updateStore(tabID, {
loadingChat: true,
promptInputDisabledState: true,
cancelButtonWhenLoading: true,
cancelButtonWhenLoading,
})
if (message) {
mynahUI.updateLastChatAnswer(tabID, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ action.aws.toolkit.toolwindow.newConnection.text=Add Another Connection...
action.dynamic.open.text=Open Resource...
action.q.openchat.text=Open Chat Panel
amazonqChat.project_context.index_in_progress=By the way, I'm still indexing this project for full context from your workspace. I may have a better response in a few minutes when it's complete if you'd like to try again then.
amazonqDoc.edit.message=Please describe the changes you would like to make to your documentation. For example, you can ask me to add a section, remove a section, make a correction, expand upon something, etc.
amazonqDoc.edit.placeholder=Describe your documentation request
amazonqDoc.answer.codeResult=You can accept the changes to your files, or describe any additional changes you'd like me to make.
amazonqDoc.answer.readmeCreated=I've created a README for your code.
amazonqDoc.answer.readmeUpdated=I've updated your README.
amazonqDoc.edit.message=Okay, let's work on your README. Describe the changes you would like to make. For example, you can ask me to:\n- Correct something\n- Expand on something\n- Add a section\n- Remove a section
amazonqDoc.edit.placeholder=Describe documentation changes
amazonqDoc.error.generating=Unable to generate changes.
amazonqDoc.error_text=I'm sorry, I ran into an issue while trying to generate your documentation. Please try again.
amazonqDoc.exception.content_length_error=Your workspace is too large for me to review. Your workspace must be within the quota, even if you choose a smaller folder. For more information on quotas, see the <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/doc-generation.html#quotas" target="_blank">Amazon Q Developer documentation.</a>
Expand Down

0 comments on commit 29b1a6c

Please sign in to comment.