|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { MynahIcons, Status } from '@aws/mynah-ui' |
| 7 | +import { FollowUpTypes, NewFileInfo } from '../shared/types' |
| 8 | +import { i18n } from '../shared/i18n' |
| 9 | + |
| 10 | +// For uniquely identifiying which chat messages should be routed to Doc |
| 11 | +export const docChat = 'docChat' |
| 12 | + |
| 13 | +export const docScheme = 'aws-doc' |
| 14 | + |
| 15 | +export const featureName = 'Amazon Q Doc Generation' |
| 16 | + |
| 17 | +export function getFileSummaryPercentage(input: string): number { |
| 18 | + // Split the input string by newline characters |
| 19 | + const lines = input.split('\n') |
| 20 | + |
| 21 | + // Find the line containing "summarized:" |
| 22 | + const summaryLine = lines.find(line => line.includes('summarized:')) |
| 23 | + |
| 24 | + // If the line is not found, return null |
| 25 | + if (!summaryLine) { |
| 26 | + return -1 |
| 27 | + } |
| 28 | + |
| 29 | + // Extract the numbers from the summary line |
| 30 | + const [summarized, total] = summaryLine.split(':')[1].trim().split(' of ').map(Number) |
| 31 | + |
| 32 | + // Calculate the percentage |
| 33 | + const percentage = (summarized / total) * 100 |
| 34 | + |
| 35 | + return percentage |
| 36 | +} |
| 37 | + |
| 38 | +const checkIcons = { |
| 39 | + wait: '☐', |
| 40 | + current: '☐', |
| 41 | + done: '☑', |
| 42 | +} |
| 43 | + |
| 44 | +const getIconForStep = (targetStep: number, currentStep: number) => { |
| 45 | + return currentStep === targetStep |
| 46 | + ? checkIcons.current |
| 47 | + : currentStep > targetStep |
| 48 | + ? checkIcons.done |
| 49 | + : checkIcons.wait |
| 50 | +} |
| 51 | + |
| 52 | +export enum DocGenerationStep { |
| 53 | + UPLOAD_TO_S3, |
| 54 | + SUMMARIZING_FILES, |
| 55 | + GENERATING_ARTIFACTS, |
| 56 | +} |
| 57 | + |
| 58 | +export const docGenerationProgressMessage = (currentStep: DocGenerationStep, mode: Mode) => ` |
| 59 | +${mode === Mode.CREATE ? i18n('AWS.amazonq.doc.answer.creating') : i18n('AWS.amazonq.doc.answer.updating')} |
| 60 | +
|
| 61 | +${getIconForStep(DocGenerationStep.UPLOAD_TO_S3, currentStep)} ${i18n('AWS.amazonq.doc.answer.scanning')} |
| 62 | +
|
| 63 | +${getIconForStep(DocGenerationStep.SUMMARIZING_FILES, currentStep)} ${i18n('AWS.amazonq.doc.answer.summarizing')} |
| 64 | +
|
| 65 | +${getIconForStep(DocGenerationStep.GENERATING_ARTIFACTS, currentStep)} ${i18n('AWS.amazonq.doc.answer.generating')} |
| 66 | +
|
| 67 | +
|
| 68 | +` |
| 69 | + |
| 70 | +export const docGenerationSuccessMessage = (mode: Mode) => |
| 71 | + mode === Mode.CREATE ? i18n('AWS.amazonq.doc.answer.readmeCreated') : i18n('AWS.amazonq.doc.answer.readmeUpdated') |
| 72 | + |
| 73 | +export const docRejectConfirmation = 'Your changes have been discarded.' |
| 74 | + |
| 75 | +export const FolderSelectorFollowUps = [ |
| 76 | + { |
| 77 | + icon: 'ok' as MynahIcons, |
| 78 | + pillText: 'Yes', |
| 79 | + prompt: 'Yes', |
| 80 | + status: 'success' as Status, |
| 81 | + type: FollowUpTypes.ProceedFolderSelection, |
| 82 | + }, |
| 83 | + { |
| 84 | + icon: 'refresh' as MynahIcons, |
| 85 | + pillText: 'Change folder', |
| 86 | + prompt: 'Change folder', |
| 87 | + status: 'info' as Status, |
| 88 | + type: FollowUpTypes.ChooseFolder, |
| 89 | + }, |
| 90 | + { |
| 91 | + icon: 'cancel' as MynahIcons, |
| 92 | + pillText: 'Cancel', |
| 93 | + prompt: 'Cancel', |
| 94 | + status: 'error' as Status, |
| 95 | + type: FollowUpTypes.CancelFolderSelection, |
| 96 | + }, |
| 97 | +] |
| 98 | + |
| 99 | +export const CodeChangeFollowUps = [ |
| 100 | + { |
| 101 | + pillText: i18n('AWS.amazonq.doc.pillText.accept'), |
| 102 | + prompt: i18n('AWS.amazonq.doc.pillText.accept'), |
| 103 | + type: FollowUpTypes.AcceptChanges, |
| 104 | + icon: 'ok' as MynahIcons, |
| 105 | + status: 'success' as Status, |
| 106 | + }, |
| 107 | + { |
| 108 | + pillText: i18n('AWS.amazonq.doc.pillText.makeChanges'), |
| 109 | + prompt: i18n('AWS.amazonq.doc.pillText.makeChanges'), |
| 110 | + type: FollowUpTypes.MakeChanges, |
| 111 | + icon: 'refresh' as MynahIcons, |
| 112 | + status: 'info' as Status, |
| 113 | + }, |
| 114 | + { |
| 115 | + pillText: i18n('AWS.amazonq.doc.pillText.reject'), |
| 116 | + prompt: i18n('AWS.amazonq.doc.pillText.reject'), |
| 117 | + type: FollowUpTypes.RejectChanges, |
| 118 | + icon: 'cancel' as MynahIcons, |
| 119 | + status: 'error' as Status, |
| 120 | + }, |
| 121 | +] |
| 122 | + |
| 123 | +export const NewSessionFollowUps = [ |
| 124 | + { |
| 125 | + pillText: i18n('AWS.amazonq.doc.pillText.newTask'), |
| 126 | + type: FollowUpTypes.NewTask, |
| 127 | + status: 'info' as Status, |
| 128 | + }, |
| 129 | + { |
| 130 | + pillText: i18n('AWS.amazonq.doc.pillText.closeSession'), |
| 131 | + type: FollowUpTypes.CloseSession, |
| 132 | + status: 'info' as Status, |
| 133 | + }, |
| 134 | +] |
| 135 | + |
| 136 | +export const SynchronizeDocumentation = { |
| 137 | + pillText: i18n('AWS.amazonq.doc.pillText.update'), |
| 138 | + prompt: i18n('AWS.amazonq.doc.pillText.update'), |
| 139 | + type: FollowUpTypes.SynchronizeDocumentation, |
| 140 | +} |
| 141 | + |
| 142 | +export const EditDocumentation = { |
| 143 | + pillText: i18n('AWS.amazonq.doc.pillText.makeChange'), |
| 144 | + prompt: i18n('AWS.amazonq.doc.pillText.makeChange'), |
| 145 | + type: FollowUpTypes.EditDocumentation, |
| 146 | +} |
| 147 | + |
| 148 | +export enum Mode { |
| 149 | + NONE = 'None', |
| 150 | + CREATE = 'Create', |
| 151 | + SYNC = 'Sync', |
| 152 | + EDIT = 'Edit', |
| 153 | +} |
| 154 | + |
| 155 | +/** |
| 156 | + * |
| 157 | + * @param paths file paths |
| 158 | + * @returns the path to a README.md, or undefined if none exist |
| 159 | + */ |
| 160 | +export const findReadmePath = (paths?: NewFileInfo[]) => { |
| 161 | + return paths?.find(path => /readme\.md$/i.test(path.relativePath)) |
| 162 | +} |
0 commit comments