Skip to content

Commit 43cd8ca

Browse files
committed
chore: migrate types constants and errors files for doc
1 parent 629bc04 commit 43cd8ca

File tree

4 files changed

+292
-0
lines changed

4 files changed

+292
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
//TODO: extend the toolkit error once ready
7+
// import { ClientError, ContentLengthError as CommonContentLengthError } from '../shared/errors'
8+
import { i18n } from '../shared/i18n'
9+
10+
export class DocClientError {
11+
remainingIterations?: number
12+
constructor(message: string, code: string, remainingIterations?: number) {
13+
// super(message, { code })
14+
this.remainingIterations = remainingIterations
15+
}
16+
}
17+
18+
export class ReadmeTooLargeError extends DocClientError {
19+
constructor() {
20+
super(i18n('AWS.amazonq.doc.error.readmeTooLarge'), ReadmeTooLargeError.name)
21+
}
22+
}
23+
24+
export class ReadmeUpdateTooLargeError extends DocClientError {
25+
constructor(remainingIterations: number) {
26+
super(i18n('AWS.amazonq.doc.error.readmeUpdateTooLarge'), ReadmeUpdateTooLargeError.name, remainingIterations)
27+
}
28+
}
29+
30+
export class WorkspaceEmptyError extends DocClientError {
31+
constructor() {
32+
super(i18n('AWS.amazonq.doc.error.workspaceEmpty'), WorkspaceEmptyError.name)
33+
}
34+
}
35+
36+
export class NoChangeRequiredException extends DocClientError {
37+
constructor() {
38+
super(i18n('AWS.amazonq.doc.error.noChangeRequiredException'), NoChangeRequiredException.name)
39+
}
40+
}
41+
42+
export class PromptRefusalException extends DocClientError {
43+
constructor(remainingIterations: number) {
44+
super(i18n('AWS.amazonq.doc.error.promptRefusal'), PromptRefusalException.name, remainingIterations)
45+
}
46+
}
47+
48+
// TODO: move the common content length error to shared folder
49+
// export class ContentLengthError extends CommonContentLengthError {
50+
// constructor() {
51+
// super(i18n('AWS.amazonq.doc.error.contentLengthError'), { code: ContentLengthError.name })
52+
// }
53+
// }
54+
export class PromptTooVagueError extends DocClientError {
55+
constructor(remainingIterations: number) {
56+
super(i18n('AWS.amazonq.doc.error.promptTooVague'), PromptTooVagueError.name, remainingIterations)
57+
}
58+
}
59+
60+
export class PromptUnrelatedError extends DocClientError {
61+
constructor(remainingIterations: number) {
62+
super(i18n('AWS.amazonq.doc.error.promptUnrelated'), PromptUnrelatedError.name, remainingIterations)
63+
}
64+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function i18n(text: string): string {
2+
return text
3+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { WorkspaceFolder } from '@aws/language-server-runtimes/protocol'
7+
8+
//TODO: May not be needed follow up with flare
9+
export enum FollowUpTypes {
10+
// UnitTestGeneration
11+
ViewDiff = 'ViewDiff',
12+
AcceptCode = 'AcceptCode',
13+
RejectCode = 'RejectCode',
14+
BuildAndExecute = 'BuildAndExecute',
15+
ModifyCommands = 'ModifyCommands',
16+
SkipBuildAndFinish = 'SkipBuildAndFinish',
17+
InstallDependenciesAndContinue = 'InstallDependenciesAndContinue',
18+
ContinueBuildAndExecute = 'ContinueBuildAndExecute',
19+
ViewCodeDiffAfterIteration = 'ViewCodeDiffAfterIteration',
20+
// FeatureDev
21+
GenerateCode = 'GenerateCode',
22+
InsertCode = 'InsertCode',
23+
ProvideFeedbackAndRegenerateCode = 'ProvideFeedbackAndRegenerateCode',
24+
Retry = 'Retry',
25+
ModifyDefaultSourceFolder = 'ModifyDefaultSourceFolder',
26+
DevExamples = 'DevExamples',
27+
NewTask = 'NewTask',
28+
CloseSession = 'CloseSession',
29+
SendFeedback = 'SendFeedback',
30+
AcceptAutoBuild = 'AcceptAutoBuild',
31+
DenyAutoBuild = 'DenyAutoBuild',
32+
GenerateDevFile = 'GenerateDevFile',
33+
// Doc
34+
CreateDocumentation = 'CreateDocumentation',
35+
ChooseFolder = 'ChooseFolder',
36+
UpdateDocumentation = 'UpdateDocumentation',
37+
SynchronizeDocumentation = 'SynchronizeDocumentation',
38+
EditDocumentation = 'EditDocumentation',
39+
AcceptChanges = 'AcceptChanges',
40+
RejectChanges = 'RejectChanges',
41+
MakeChanges = 'MakeChanges',
42+
ProceedFolderSelection = 'ProceedFolderSelection',
43+
CancelFolderSelection = 'CancelFolderSelection',
44+
}
45+
46+
export type DiffTreeFileInfo = {
47+
zipFilePath: string
48+
relativePath: string
49+
rejected: boolean
50+
changeApplied: boolean
51+
}
52+
53+
export type NewFileZipContents = { zipFilePath: string; fileContent: string }
54+
55+
export type DeletedFileInfo = DiffTreeFileInfo & {
56+
workspaceFolder: WorkspaceFolder
57+
}
58+
59+
export type NewFileInfo = DiffTreeFileInfo &
60+
NewFileZipContents & {
61+
virtualMemoryUri: string
62+
workspaceFolder: WorkspaceFolder
63+
}

0 commit comments

Comments
 (0)