Skip to content

Commit d79750d

Browse files
committed
Fix
1 parent f0d0521 commit d79750d

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

packages/core/src/amazonq/session/sessionState.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,29 @@ export abstract class CodeGenBase {
5555
this.currentCodeGenerationId = config.currentCodeGenerationId || EmptyCodeGenID
5656
}
5757

58-
protected abstract handleProgress(messenger: BaseMessenger, detail?: string): void
58+
protected abstract handleProgress(messenger: BaseMessenger, action: SessionStateAction, detail?: string): void
5959
protected abstract getScheme(): string
60-
protected abstract handleGenerationComplete(messenger: BaseMessenger, newFileInfo: NewFileInfo[]): void
60+
protected abstract getTimeoutErrorCode(): string
61+
protected abstract handleGenerationComplete(
62+
messenger: BaseMessenger,
63+
newFileInfo: NewFileInfo[],
64+
action: SessionStateAction
65+
): void
6166

6267
async generateCode({
6368
messenger,
6469
fs,
6570
codeGenerationId,
6671
telemetry: telemetry,
6772
workspaceFolders,
73+
action,
6874
}: {
6975
messenger: BaseMessenger
7076
fs: VirtualFileSystem
7177
codeGenerationId: string
7278
telemetry: any
7379
workspaceFolders: CurrentWsFolders
80+
action: SessionStateAction
7481
}): Promise<{
7582
newFiles: NewFileInfo[]
7683
deletedFiles: DeletedFileInfo[]
@@ -106,7 +113,7 @@ export abstract class CodeGenBase {
106113
)
107114
telemetry.setNumberOfFilesGenerated(newFileInfo.length)
108115

109-
this.handleGenerationComplete(messenger, newFileInfo)
116+
this.handleGenerationComplete(messenger, newFileInfo, action)
110117

111118
return {
112119
newFiles: newFileInfo,
@@ -119,7 +126,7 @@ export abstract class CodeGenBase {
119126
case CodeGenerationStatus.PREDICT_READY:
120127
case CodeGenerationStatus.IN_PROGRESS: {
121128
if (codegenResult.codeGenerationStatusDetail) {
122-
this.handleProgress(messenger, codegenResult.codeGenerationStatusDetail)
129+
this.handleProgress(messenger, action, codegenResult.codeGenerationStatusDetail)
123130
}
124131
await new Promise((f) => globals.clock.setTimeout(f, this.requestDelay))
125132
break
@@ -138,7 +145,7 @@ export abstract class CodeGenBase {
138145

139146
if (!this.isCancellationRequested) {
140147
const errorMessage = i18n('AWS.amazonq.featureDev.error.codeGen.timeout')
141-
throw new ToolkitError(errorMessage, { code: 'CodeGenTimeout' })
148+
throw new ToolkitError(errorMessage, { code: this.getTimeoutErrorCode() })
142149
}
143150

144151
return {
@@ -210,7 +217,11 @@ export abstract class BasePrepareCodeGenState implements SessionState {
210217
)
211218
}
212219

220+
protected abstract preUpload(action: SessionStateAction): void
221+
protected abstract postUpload(action: SessionStateAction): void
222+
213223
async interact(action: SessionStateAction): Promise<SessionStateInteraction> {
224+
this.preUpload(action)
214225
const uploadId = await telemetry.amazonq_createUpload.run(async (span) => {
215226
span.record({
216227
amazonqConversationId: this.config.conversationId,
@@ -231,6 +242,7 @@ export abstract class BasePrepareCodeGenState implements SessionState {
231242
)
232243

233244
await uploadCode(uploadUrl, zipFileBuffer, zipFileChecksum, kmsKeyArn)
245+
this.postUpload(action)
234246

235247
return uploadId
236248
})
@@ -338,6 +350,7 @@ export abstract class BaseCodeGenState extends CodeGenBase implements SessionSta
338350
codeGenerationId,
339351
telemetry: action.telemetry,
340352
workspaceFolders: this.config.workspaceFolders,
353+
action,
341354
})
342355

343356
if (codeGeneration && !action.tokenSource?.token.isCancellationRequested) {

packages/core/src/amazonqDoc/session/sessionState.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import { BaseCodeGenState, BasePrepareCodeGenState, CreateNextStateParams } from
2525
import { Intent } from '../../amazonq/commons/types'
2626

2727
export class DocCodeGenState extends BaseCodeGenState {
28-
protected handleProgress(messenger: DocMessenger, detail?: string): void {
28+
protected handleProgress(messenger: DocMessenger, action: SessionStateAction, detail?: string): void {
2929
if (detail) {
3030
const progress = getFileSummaryPercentage(detail)
3131
messenger.sendDocProgress(
3232
this.tabID,
3333
progress === 100 ? DocGenerationStep.GENERATING_ARTIFACTS : DocGenerationStep.SUMMARIZING_FILES,
3434
progress,
35-
(messenger as any).mode
35+
action.mode
3636
)
3737
}
3838
}
@@ -41,8 +41,16 @@ export class DocCodeGenState extends BaseCodeGenState {
4141
return docScheme
4242
}
4343

44-
protected handleGenerationComplete(messenger: DocMessenger, newFileInfo: NewFileInfo[]): void {
45-
messenger.sendDocProgress(this.tabID, DocGenerationStep.GENERATING_ARTIFACTS + 1, 100, (messenger as any).mode)
44+
protected getTimeoutErrorCode(): string {
45+
return 'DocGenerationTimeout'
46+
}
47+
48+
protected handleGenerationComplete(
49+
messenger: DocMessenger,
50+
newFileInfo: NewFileInfo[],
51+
action: SessionStateAction
52+
): void {
53+
messenger.sendDocProgress(this.tabID, DocGenerationStep.GENERATING_ARTIFACTS + 1, 100, action.mode)
4654
}
4755

4856
protected handleError(messenger: DocMessenger, codegenResult: any): Error {
@@ -118,6 +126,14 @@ export class DocCodeGenState extends BaseCodeGenState {
118126
}
119127

120128
export class DocPrepareCodeGenState extends BasePrepareCodeGenState {
129+
protected preUpload(action: SessionStateAction): void {
130+
// Do nothing
131+
}
132+
133+
protected postUpload(action: SessionStateAction): void {
134+
// Do nothing
135+
}
136+
121137
protected override createNextState(config: SessionStateConfig): SessionState {
122138
return super.createNextState(config, DocCodeGenState)
123139
}

packages/core/src/amazonqFeatureDev/session/sessionState.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class MockCodeGenState implements SessionState {
147147
}
148148

149149
export class FeatureDevCodeGenState extends BaseCodeGenState {
150-
protected handleProgress(messenger: Messenger, detail?: string): void {
150+
protected handleProgress(messenger: Messenger, action: SessionStateAction, detail?: string): void {
151151
if (detail) {
152152
messenger.sendAnswer({
153153
message: i18n('AWS.amazonq.featureDev.pillText.generatingCode') + `\n\n${detail}`,
@@ -161,7 +161,15 @@ export class FeatureDevCodeGenState extends BaseCodeGenState {
161161
return featureDevScheme
162162
}
163163

164-
protected handleGenerationComplete(_messenger: Messenger, _newFileInfo: NewFileInfo[]): void {
164+
protected getTimeoutErrorCode(): string {
165+
return 'CodeGenTimeout'
166+
}
167+
168+
protected handleGenerationComplete(
169+
_messenger: Messenger,
170+
_newFileInfo: NewFileInfo[],
171+
action: SessionStateAction
172+
): void {
165173
// No special handling needed for feature dev
166174
}
167175

@@ -220,11 +228,40 @@ export class FeatureDevCodeGenState extends BaseCodeGenState {
220228
}
221229

222230
protected override createNextState(config: SessionStateConfig, params: CreateNextStateParams): SessionState {
223-
return super.createNextState(config, params, FeatureDevPrepareCodeGenState)
231+
return super.createNextState(
232+
{ ...config, currentCodeGenerationId: this.currentCodeGenerationId },
233+
params,
234+
FeatureDevPrepareCodeGenState
235+
)
224236
}
225237
}
226238

227239
export class FeatureDevPrepareCodeGenState extends BasePrepareCodeGenState {
240+
protected preUpload(action: SessionStateAction): void {
241+
action.messenger.sendAnswer({
242+
message: i18n('AWS.amazonq.featureDev.pillText.uploadingCode'),
243+
type: 'answer-part',
244+
tabID: this.tabID,
245+
})
246+
247+
action.messenger.sendUpdatePlaceholder(this.tabID, i18n('AWS.amazonq.featureDev.pillText.uploadingCode'))
248+
}
249+
250+
protected postUpload(action: SessionStateAction): void {
251+
if (!action.tokenSource?.token.isCancellationRequested) {
252+
action.messenger.sendAnswer({
253+
message: i18n('AWS.amazonq.featureDev.pillText.contextGatheringCompleted'),
254+
type: 'answer-part',
255+
tabID: this.tabID,
256+
})
257+
258+
action.messenger.sendUpdatePlaceholder(
259+
this.tabID,
260+
i18n('AWS.amazonq.featureDev.pillText.contextGatheringCompleted')
261+
)
262+
}
263+
}
264+
228265
protected override createNextState(config: SessionStateConfig): SessionState {
229266
return super.createNextState(config, FeatureDevCodeGenState)
230267
}

0 commit comments

Comments
 (0)