Skip to content

Commit 1dcf5f7

Browse files
dhasani23David Hasani
andauthored
feat(amazonq): show users estimated cost of /transform (#5423)
* feat(amazonq): show users estimated cost of /transform * search table instead of using [0] * localize string * update changelog * add unit test * update text * use string interpolation * move constant to constants file * remove unneeded function --------- Co-authored-by: David Hasani <[email protected]>
1 parent c87f980 commit 1dcf5f7

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Amazon Q Code Transformation: show pro tier users estimated cost of /transform on projects over 100K lines"
4+
}

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ export const codeTransformTroubleshootDownloadError =
400400
export const codeTransformPrereqDoc =
401401
'https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html#prerequisites'
402402

403+
export const codeTransformBillingText = (linesOfCode: number) =>
404+
`<p>${linesOfCode} lines of code were submitted for transformation. If you reach the quota for lines of code included in your subscription, you will be charged $${codeTransformBillingRate} for each additional line of code. You might be charged up to $${(linesOfCode * codeTransformBillingRate).toFixed(2)} for this transformation. To avoid being charged, stop the transformation job before it completes. For more information on pricing and quotas, see [Amazon Q Developer pricing](${linkToBillingInfo}).</p>`
405+
406+
export const codeTransformBillingRate = 0.003
407+
408+
export const codeTransformLocThreshold = 100000
409+
403410
export const jobStartedChatMessage =
404411
'I am starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your project. To monitor progress, go to the Transformation Hub. If I run into any issues, I might pause the transformation to get input from you on how to proceed.'
405412

@@ -571,9 +578,7 @@ export const noJavaProjectsFoundChatMessage = `Sorry, I couldn\'t find a project
571578

572579
export const linkToDocsHome = 'https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
573580

574-
export const linkToPrerequisites = ''
575-
576-
export const linkToMavenTroubleshooting = ''
581+
export const linkToBillingInfo = 'https://aws.amazon.com/q/developer/pricing/'
577582

578583
export const linkToUploadZipTooLarge =
579584
'https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#project-size-limit'

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ export async function getTransformationPlan(jobId: string) {
619619
const arrowIcon = getTransformationIcon('upArrow')
620620

621621
let plan = `<style>table {border: 1px solid #424750;}</style>\n\n<a id="top"></a><br><p style="font-size: 24px;"><img src="${logoIcon}" style="margin-right: 15px; vertical-align: middle;"></img><b>${CodeWhispererConstants.planTitle}</b></p><br>`
622+
const authType = await getAuthType()
623+
const linesOfCode = Number(
624+
jobStatistics.find((stat: { name: string; value: string }) => stat.name === 'linesOfCode').value
625+
)
626+
if (authType === 'iamIdentityCenter' && linesOfCode > CodeWhispererConstants.codeTransformLocThreshold) {
627+
plan += CodeWhispererConstants.codeTransformBillingText(linesOfCode)
628+
}
622629
plan += `<div style="display: flex;"><div style="flex: 1; border: 1px solid #424750; border-radius: 8px; padding: 10px;"><p>${
623630
CodeWhispererConstants.planIntroductionMessage
624631
}</p></div>${getJobStatisticsHtml(jobStatistics)}</div>`

packages/core/src/test/codewhisperer/commands/transformByQ.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ describe('transformByQ', function () {
298298
assert.deepStrictEqual(actual, expected)
299299
})
300300

301+
it(`WHEN codeTransformBillingText on small project THEN correct string returned`, async function () {
302+
const expected =
303+
'<p>376 lines of code were submitted for transformation. If you reach the quota for lines of code included in your subscription, you will be charged $0.003 for each additional line of code. You might be charged up to $1.13 for this transformation. To avoid being charged, stop the transformation job before it completes. For more information on pricing and quotas, see [Amazon Q Developer pricing](https://aws.amazon.com/q/developer/pricing/).</p>'
304+
const actual = CodeWhispererConstants.codeTransformBillingText(376)
305+
assert.strictEqual(actual, expected)
306+
})
307+
301308
it(`WHEN parseBuildFile on pom.xml with absolute path THEN absolute path detected`, async function () {
302309
const dirPath = await createTestWorkspaceFolder()
303310
transformByQState.setProjectPath(dirPath.uri.fsPath)

0 commit comments

Comments
 (0)