Skip to content

Commit 9c54540

Browse files
author
David Hasani
committed
dms setup
1 parent 5237855 commit 9c54540

File tree

5 files changed

+63
-22
lines changed

5 files changed

+63
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class QuickActionGenerator {
3737
? [
3838
{
3939
command: '/transform',
40-
description: 'Transform your Java 8 or 11 Maven project to Java 17',
40+
description: 'Transform your Java project',
4141
},
4242
]
4343
: []),

packages/core/src/amazonq/webview/ui/tabs/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ What would you like to work on?`,
3535
placeholder: 'Open a new tab to chat with Q',
3636
welcome: `Welcome to Code Transformation!
3737
38-
I can help you upgrade your Java 8 and 11 codebases to Java 17.`,
38+
I can help you upgrade your Java 8 and 11 codebases to Java 17 ("language upgrade") &
39+
I can also convert embedded SQL from Oracle to PostgreSQL ("SQL conversion"). What would you like to do?`,
3940
},
4041
}

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,17 @@ export class GumbyController {
184184

185185
private async transformInitiated(message: any) {
186186
// Start /transform chat flow
187-
const session: Session = this.sessionStorage.getSession()
188187
CodeTransformTelemetryState.instance.setSessionId()
189188

189+
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_OBJECTIVE
190+
this.messenger.sendStaticTextResponse('choose-transformation-objective', 'ai-prompt', message.tabID)
191+
this.messenger.sendChatInputEnabled(message.tabID, true)
192+
this.messenger.sendUpdatePlaceholder(message.tabID, "Enter 'language upgrade' or 'SQL conversion'")
193+
}
194+
195+
private async handleLanguageUpgrade(message: any) {
196+
const session: Session = this.sessionStorage.getSession()
197+
this.messenger.sendStaticTextResponse('language-upgrade-selected', 'prompt', message.tabID)
190198
try {
191199
await telemetry.codeTransform_initiateTransform.run(async () => {
192200
const authType = await getAuthType()
@@ -195,14 +203,6 @@ export class GumbyController {
195203
credentialSourceId: authType,
196204
})
197205

198-
// check that a project is open
199-
const workspaceFolders = vscode.workspace.workspaceFolders
200-
if (workspaceFolders === undefined || workspaceFolders.length === 0) {
201-
this.messenger.sendUnrecoverableErrorResponse('no-project-found', message.tabID)
202-
telemetry.record({ result: MetadataResult.Fail, reason: 'no-project-found' })
203-
return
204-
}
205-
206206
// check that the session is authenticated
207207
const authState = await AuthUtil.instance.getChatAuthState()
208208
if (authState.amazonQ !== 'connected') {
@@ -212,8 +212,17 @@ export class GumbyController {
212212
return
213213
}
214214

215+
// check that a project is open
216+
const workspaceFolders = vscode.workspace.workspaceFolders
217+
if (workspaceFolders === undefined || workspaceFolders.length === 0) {
218+
this.messenger.sendUnrecoverableErrorResponse('no-project-found', message.tabID)
219+
telemetry.record({ result: MetadataResult.Fail, reason: 'no-project-found' })
220+
return
221+
}
222+
215223
// If previous transformation was already running
216224
switch (this.sessionStorage.getSession().conversationState) {
225+
// TODO: figure out if/when to set these states for SQL conversions
217226
case ConversationState.JOB_SUBMITTED:
218227
this.messenger.sendAsyncEventProgress(
219228
message.tabID,
@@ -236,8 +245,8 @@ export class GumbyController {
236245
this.messenger.sendTransformationIntroduction(message.tabID)
237246
})
238247
} catch (e: any) {
239-
// if there was an issue getting the list of valid projects, the error message will be shown here
240248
this.messenger.sendErrorMessage(e.message, message.tabID)
249+
return
241250
}
242251

243252
try {
@@ -247,11 +256,16 @@ export class GumbyController {
247256
await this.messenger.sendProjectPrompt(validProjects, message.tabID)
248257
}
249258
} catch (err: any) {
250-
// if there was an issue getting the list of valid projects, the error message will be shown here
259+
// if there was an issue showing the list of valid projects, the error message will be shown here
251260
this.messenger.sendErrorMessage(err.message, message.tabID)
261+
return
252262
}
253263
}
254264

265+
private async handleSQLConversion(message: any) {
266+
this.messenger.sendStaticTextResponse('sql-conversion-selected', 'prompt', message.tabID)
267+
}
268+
255269
private async validateProjectsWithReplyOnError(message: any): Promise<TransformationCandidateProject[]> {
256270
let telemetryJavaVersion = JDKToTelemetryValue(JDKVersion.UNSUPPORTED) as CodeTransformJavaSourceVersionsAllowed
257271
try {
@@ -443,7 +457,7 @@ export class GumbyController {
443457
} catch (err: any) {
444458
if (err instanceof JavaHomeNotSetError) {
445459
this.sessionStorage.getSession().conversationState = ConversationState.PROMPT_JAVA_HOME
446-
this.messenger.sendStaticTextResponse('java-home-not-set', message.tabID)
460+
this.messenger.sendStaticTextResponse('java-home-not-set', 'ai-prompt', message.tabID)
447461
this.messenger.sendChatInputEnabled(message.tabID, true)
448462
this.messenger.sendUpdatePlaceholder(message.tabID, 'Enter the path to your Java installation.')
449463
// const fileUri = await vscode.window.showOpenDialog({
@@ -478,7 +492,7 @@ export class GumbyController {
478492
}
479493

480494
private startHILIntervention(data: { tabID: string; codeSnippet: string }) {
481-
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_INPUT
495+
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_HIL_INPUT
482496
this.messenger.sendHumanInTheLoopInitialMessage(data.tabID, data.codeSnippet)
483497
}
484498

@@ -500,7 +514,6 @@ export class GumbyController {
500514
switch (session.conversationState) {
501515
case ConversationState.PROMPT_JAVA_HOME: {
502516
const pathToJavaHome = extractPath(data.message)
503-
504517
if (pathToJavaHome) {
505518
await this.prepareProjectForSubmission({
506519
pathToJavaHome,
@@ -509,6 +522,23 @@ export class GumbyController {
509522
} else {
510523
this.messenger.sendUnrecoverableErrorResponse('invalid-java-home', data.tabID)
511524
}
525+
break
526+
}
527+
528+
case ConversationState.WAITING_FOR_OBJECTIVE: {
529+
const objective = data.message.trim().toLowerCase()
530+
if (objective === 'language upgrade') {
531+
vscode.window.showInformationMessage('You chose language upgrade!')
532+
this.handleLanguageUpgrade(data)
533+
} else if (objective === 'sql conversion') {
534+
vscode.window.showInformationMessage('You chose SQL conversion!')
535+
this.handleSQLConversion(data)
536+
} else {
537+
vscode.window.showInformationMessage('You did not enter a valid objective')
538+
// keep prompting user until they enter a valid option
539+
this.transformInitiated(data)
540+
}
541+
break
512542
}
513543
}
514544
}
@@ -557,7 +587,7 @@ export class GumbyController {
557587
this.transformationFinished({ tabID: message.tabID, message: (err as Error).message })
558588
}
559589

560-
this.messenger.sendStaticTextResponse('end-HIL-early', message.tabID)
590+
this.messenger.sendStaticTextResponse('end-HIL-early', 'ai-prompt', message.tabID)
561591
}
562592
}
563593

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export type StaticTextResponseType =
3535
| 'start-transformation-confirmed'
3636
| 'job-transmitted'
3737
| 'end-HIL-early'
38+
| 'choose-transformation-objective'
39+
| 'language-upgrade-selected'
40+
| 'sql-conversion-selected'
3841

3942
export type UnrecoverableErrorType =
4043
| 'no-project-found'
@@ -315,23 +318,29 @@ export class Messenger {
315318
)
316319
}
317320

318-
public sendStaticTextResponse(type: StaticTextResponseType, tabID: string) {
321+
public sendStaticTextResponse(messageType: StaticTextResponseType, itemType: ChatItemType, tabID: string) {
319322
let message = '...'
320323

321-
switch (type) {
324+
switch (messageType) {
322325
case 'java-home-not-set':
323326
message = MessengerUtils.createJavaHomePrompt()
324327
break
325328
case 'end-HIL-early':
326-
message = `I will continue transforming your code without upgrading this dependency.`
329+
message = 'I will continue transforming your code without upgrading this dependency.'
330+
break
331+
case 'choose-transformation-objective':
332+
message = 'Choose your transformation objective.'
333+
break
334+
case 'language-upgrade-selected':
335+
message = 'Got it! I can upgrade your Java 8 or 11 project to Java 17.'
327336
break
328337
}
329338

330339
this.dispatcher.sendChatMessage(
331340
new ChatMessage(
332341
{
333342
message,
334-
messageType: 'ai-prompt',
343+
messageType: itemType,
335344
},
336345
tabID
337346
)

packages/core/src/amazonqGumby/chat/session/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export enum ConversationState {
1010
PROMPT_JAVA_HOME,
1111
COMPILING,
1212
JOB_SUBMITTED,
13-
WAITING_FOR_INPUT,
13+
WAITING_FOR_HIL_INPUT,
14+
WAITING_FOR_OBJECTIVE,
1415
}
1516

1617
export interface ProjectDetails {

0 commit comments

Comments
 (0)