-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathstatic.ts
683 lines (641 loc) · 18.2 KB
/
static.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/*!
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { CheckboxAbstract, CheckboxProps } from './components/form-items/checkbox';
import { CustomIcon, MynahIcons, MynahIconsType } from './components/icon';
import { ChatItemBodyRenderer } from './helper/dom';
import {
SelectAbstract,
SelectProps,
RadioGroupAbstract,
RadioGroupProps,
ButtonAbstract,
ButtonProps,
TextInputProps,
TextInputAbstract,
TextAreaProps,
TextAreaAbstract,
ToggleOption,
} from './main';
export interface QuickActionCommand {
command: string;
id?: string;
label?: string;
disabled?: boolean;
icon?: MynahIcons | MynahIconsType;
description?: string;
placeholder?: string;
children?: QuickActionCommandGroup[];
route?: string[];
}
export interface QuickActionCommandGroup {
groupName?: string;
icon?: MynahIcons | MynahIconsType;
actions?: Action[];
commands: QuickActionCommand[];
}
/**
* data store model to update the mynah ui partially or fully
*/
export interface MynahUIDataModel {
/**
* Tab title
* */
tabTitle?: string;
/**
* Tab icon
* */
tabIcon?: MynahIcons | MynahIconsType | null;
/**
* is tab pinned
* */
pinned?: boolean;
/**
* Tab title
* */
tabBackground?: boolean;
/**
* If tab is running an action (loadingChat = true) this markdown will be shown before close in a popup
*/
tabCloseConfirmationMessage?: string | null;
/**
* Keep tab open button text
*/
tabCloseConfirmationKeepButton?: string | null;
/**
* Close tab button text
*/
tabCloseConfirmationCloseButton?: string | null;
/**
* Chat screen loading animation state (mainly use during the stream or getting the initial answer)
*/
loadingChat?: boolean;
/**
* Show chat avatars or not
* */
showChatAvatars?: boolean;
/**
* Show cancel button while loading the chat
* */
cancelButtonWhenLoading?: boolean;
/**
* Quick Action commands to show when user hits / to the input initially
*/
quickActionCommands?: QuickActionCommandGroup[];
/**
* Context commands to show when user hits @ to the input any point
*/
contextCommands?: QuickActionCommandGroup[];
/**
* Placeholder to be shown on prompt input
*/
promptInputPlaceholder?: string;
/**
* Prompt input text
*/
promptInputText?: string;
/**
* Label to be shown on top of the prompt input
*/
promptInputLabel?: string | null;
/**
* Label to be shown on top of the prompt input
*/
promptInputVisible?: boolean;
/**
* Info block to be shown under prompt input
*/
promptInputInfo?: string;
/**
* A sticky chat item card on top of the prompt input
*/
promptInputStickyCard?: Partial<ChatItem> | null;
/**
* Prompt input field disabled state, set to tru to disable it
*/
promptInputDisabledState?: boolean;
/**
* Prompt input progress field
*/
promptInputProgress?: ProgressField | null;
/**
* Prompt input options/form items
*/
promptInputOptions?: FilterOption[] | null;
/**
* List of chat item objects to be shown on the web suggestions search screen
*/
chatItems?: ChatItem[];
/**
* Attached code under the prompt input field
*/
selectedCodeSnippet?: string;
/**
* Tab bar buttons next to the tab items
*/
tabBarButtons?: TabBarMainAction[];
/**
* Tab content compact mode which keeps everything in the middle
*/
compactMode?: boolean;
/**
* Tab content header details, only visibile when showTabHeaderDetails is set to 'true'
*/
tabHeaderDetails?: TabHeaderDetails | null;
/**
* A lightweight key-value store for essential tab-specific primitive metadata.
* Not intended for storing large amounts of data - use appropriate
* application state management for that purpose.
*/
tabMetadata?: { [key: string]: string | boolean | number };
}
export interface MynahUITabStoreTab {
/**
* Is tab selected
*/
isSelected?: boolean;
/**
* Tab items data store
*/
store?: MynahUIDataModel;
}
/**
* tabs store model to update the tabs partially or fully
*/
export interface MynahUITabStoreModel {
[tabId: string]: MynahUITabStoreTab;
}
export enum MynahEventNames {
RESET_STORE = 'resetStore',
FEEDBACK_SET = 'feedbackSet',
ROOT_FOCUS = 'rootFocusStateChange',
CARD_VOTE = 'cardVote',
SOURCE_LINK_CLICK = 'sourceLinkClick',
INFO_LINK_CLICK = 'infoLinkClick',
FORM_LINK_CLICK = 'formLinkClick',
LINK_CLICK = 'linkClick',
CHAT_ITEM_ENGAGEMENT = 'chatItemEngagement',
COPY_CODE_TO_CLIPBOARD = 'copyCodeToClipboard',
CODE_BLOCK_ACTION = 'codeBlockAction',
CHAT_PROMPT = 'chatPrompt',
CHAT_ITEM_ADD = 'chatItemAdd',
FOLLOW_UP_CLICKED = 'followUpClicked',
BODY_ACTION_CLICKED = 'bodyActionClicked',
QUICK_COMMAND_GROUP_ACTION_CLICK = 'quickCommandGroupActionClicked',
TABBED_CONTENT_SWITCH = 'tabbedContentSwitch',
SHOW_MORE_WEB_RESULTS_CLICK = 'showMoreWebResultsClick',
SHOW_FEEDBACK_FORM = 'showFeedbackForm',
OPEN_SHEET = 'openSheet',
CLOSE_SHEET = 'closeSheet',
FILE_CLICK = 'fileClick',
FILE_ACTION_CLICK = 'fileActionClick',
TAB_FOCUS = 'tabFocus',
CUSTOM_FORM_ACTION_CLICK = 'customFormActionClick',
PROMPT_INPUT_OPTIONS_CHANGE = 'promptInputOptionsChange',
FORM_MODIFIER_ENTER_PRESS = 'formModifierEnterPress',
FORM_TEXTUAL_ITEM_KEYPRESS = 'formTextualItemKeyPress',
FORM_CHANGE = 'formChange',
ADD_ATTACHMENT = 'addAttachment',
CARD_DISMISS = 'cardDismiss',
REMOVE_ATTACHMENT = 'removeAttachment',
TAB_BAR_BUTTON_CLICK = 'tabBarButtonClick',
PROMPT_PROGRESS_ACTION_CLICK = 'promptProgressActionClick',
ROOT_RESIZE = 'rootResize',
CONTEXT_SELECTED = 'contextSelected'
};
export enum MynahPortalNames {
WRAPPER = 'wrapper',
SIDE_NAV = 'sideNav',
OVERLAY = 'overlay',
SHEET = 'sheet'
};
export type PromptAttachmentType = 'code' | 'markdown';
export interface SourceLinkMetaData {
stars?: number; // repo stars
forks?: number; // repo forks
answerCount?: number; // total answers if it is a question
isOfficialDoc?: boolean; // is suggestion comes from an official api doc
isAccepted?: boolean; // is accepted or not if it is an answer
score?: number; // relative score according to the up and down votes for a question or an answer
lastActivityDate?: number; // creation or last update date for question or answer
}
export interface SourceLink {
title: string;
id?: string;
url: string;
body?: string;
type?: string;
metadata?: Record<string, SourceLinkMetaData>;
}
export enum ChatItemType {
PROMPT = 'prompt',
DIRECTIVE = 'directive',
SYSTEM_PROMPT = 'system-prompt',
AI_PROMPT = 'ai-prompt',
ANSWER = 'answer',
ANSWER_STREAM = 'answer-stream',
ANSWER_PART = 'answer-part',
CODE_RESULT = 'code-result',
}
export interface DetailedList {
filterOptions?: FilterOption[] | null;
list?: DetailedListItemGroup[];
header?: {
title?: string;
icon?: MynahIcons | MynahIconsType;
description?: string;
};
selectable?: boolean;
textDirection?: 'row' | 'column';
}
export interface DetailedListItemGroup {
groupName?: string;
actions?: Action[];
icon?: MynahIcons | MynahIconsType;
children?: DetailedListItem[];
}
export interface DetailedListItem {
title?: string;
name?: string;
id?: string;
icon?: MynahIcons | MynahIconsType;
description?: string;
disabled?: boolean;
followupText?: string;
actions?: ChatItemButton[];
children?: DetailedListItemGroup[];
keywords?: string[];
}
export type Status = 'info' | 'success' | 'warning' | 'error';
export interface ProgressField {
/**
* Prompt input progress status
*/
status?: 'default' | Status;
/**
* Prompt input progress text
*/
text?: string;
/**
* Prompt input progress text for the current state (ie: 15%, 2min remaining)
*/
valueText?: string;
/**
* Prompt input progress value to show the inner bar state, -1 for infinite
*/
value?: number;
/**
* Prompt input progress actions
*/
actions?: ChatItemButton[];
}
export interface TreeNodeDetails {
status?: Status;
visibleName?: string;
icon?: MynahIcons | MynahIconsType | null;
iconForegroundStatus?: Status;
labelIcon?: MynahIcons | MynahIconsType | null;
labelIconForegroundStatus?: Status;
label?: string;
changes?: {
added?: number;
deleted?: number;
total?: number;
};
description?: string;
clickable?: boolean;
data?: Record<string, string>;
}
export interface ChatItemContent {
header?: (ChatItemContent & {
icon?: MynahIcons | MynahIconsType | CustomIcon;
iconStatus?: 'main' | 'primary' | 'clear' | Status;
iconForegroundStatus?: Status;
status?: {
status?: Status;
description?: string;
icon?: MynahIcons | MynahIconsType;
text?: string;
};
}) | null;
body?: string | null;
customRenderer?: string | ChatItemBodyRenderer | ChatItemBodyRenderer[] | null;
followUp?: {
text?: string;
options?: ChatItemAction[];
} | null;
relatedContent?: {
title?: string;
content: SourceLink[];
} | null;
codeReference?: ReferenceTrackerInformation[] | null;
fileList?: {
fileTreeTitle?: string;
rootFolderTitle?: string;
rootFolderStatusIcon?: MynahIcons | MynahIconsType;
rootFolderStatusIconForegroundStatus?: Status;
rootFolderLabel?: string;
filePaths?: string[];
deletedFiles?: string[];
flatList?: boolean;
folderIcon?: MynahIcons | MynahIconsType | null;
collapsed?: boolean;
hideFileCount?: boolean;
actions?: Record<string, FileNodeAction[]>;
details?: Record<string, TreeNodeDetails>;
} | null;
buttons?: ChatItemButton[] | null;
formItems?: ChatItemFormItem[] | null;
footer?: ChatItemContent | null;
informationCard?: {
title?: string;
status?: {
status?: Status;
icon?: MynahIcons | MynahIconsType;
body?: string;
};
description?: string;
icon?: MynahIcons | MynahIconsType;
content: ChatItemContent;
} | null;
tabbedContent?: Array<ToggleOption & {
content: ChatItemContent;
}> | null;
codeBlockActions?: CodeBlockActions | null;
}
export interface ChatItem extends ChatItemContent {
type: ChatItemType;
messageId?: string;
snapToTop?: boolean;
autoCollapse?: boolean;
contentHorizontalAlignment?: 'default' | 'center';
canBeVoted?: boolean;
canBeDismissed?: boolean;
title?: string;
fullWidth?: boolean;
padding?: boolean;
muted?: boolean;
icon?: MynahIcons | MynahIconsType | CustomIcon;
iconForegroundStatus?: Status;
iconStatus?: 'main' | 'primary' | 'clear' | Status;
hoverEffect?: boolean;
status?: Status;
shimmer?: boolean;
}
export interface ValidationPattern {
pattern: string | RegExp;
errorMessage?: string;
}
interface BaseFormItem {
id: string;
mandatory?: boolean;
title?: string;
placeholder?: string;
value?: string;
description?: string;
tooltip?: string;
icon?: MynahIcons | MynahIconsType;
}
export type TextBasedFormItem = BaseFormItem & {
type: 'textarea' | 'textinput' | 'numericinput' | 'email';
autoFocus?: boolean;
checkModifierEnterKeyPress?: boolean;
validationPatterns?: {
operator?: 'and' | 'or';
genericValidationErrorMessage?: string;
patterns: ValidationPattern[];
};
};
type OtherFormItem = BaseFormItem & {
type: 'select' | 'stars';
options?: Array<{
value: string;
label: string;
}>;
};
type RadioGroupFormItem = BaseFormItem & {
type: 'radiogroup' | 'toggle';
options?: Array<{
value: string;
label?: string;
icon?: MynahIcons | MynahIconsType;
}>;
};
type CheckboxFormItem = BaseFormItem & {
type: 'switch' | 'checkbox';
value?: 'true' | 'false';
label?: string;
alternateTooltip?: string;
};
export type ChatItemFormItem = TextBasedFormItem | OtherFormItem | RadioGroupFormItem | CheckboxFormItem;
export type FilterOption = ChatItemFormItem;
export interface ChatPrompt {
prompt?: string;
escapedPrompt?: string;
command?: string;
options?: Record<string, string>;
context?: string[] | QuickActionCommand[];
}
export interface ChatItemAction extends ChatPrompt {
type?: string;
pillText: string;
disabled?: boolean;
description?: string;
status?: 'primary' | Status;
icon?: MynahIcons | MynahIconsType;
}
export interface ChatItemButton extends Omit<Action, 'status'> {
keepCardAfterClick?: boolean;
waitMandatoryFormItems?: boolean;
status?: 'main' | 'primary' | 'clear' | Status;
flash?: 'infinite' | 'once';
fillState?: 'hover' | 'always';
position?: 'inside' | 'outside';
}
export interface Action {
text?: string;
id: string;
disabled?: boolean;
description?: string;
status?: Status;
icon?: MynahIcons | MynahIconsType;
}
export interface TabBarAction extends Action {}
export interface TabBarMainAction extends TabBarAction {
items?: TabBarAction[];
}
export interface FileNodeAction {
name: string;
label?: string;
disabled?: boolean;
description?: string;
status?: Status;
icon: MynahIcons | MynahIconsType;
}
export enum KeyMap {
ESCAPE = 'Escape',
ENTER = 'Enter',
BACKSPACE = 'Backspace',
SPACE = ' ',
DELETE = 'Delete',
ARROW_UP = 'ArrowUp',
ARROW_DOWN = 'ArrowDown',
ARROW_LEFT = 'ArrowLeft',
ARROW_RIGHT = 'ArrowRight',
PAGE_UP = 'PageUp',
PAGED_OWN = 'PageDown',
HOME = 'Home',
END = 'End',
META = 'Meta',
TAB = 'Tab',
SHIFT = 'Shift',
CONTROL = 'Control',
ALT = 'Alt',
AT = '@',
SLASH = '/',
BACK_SLASH = '\\'
}
export interface ReferenceTrackerInformation {
licenseName?: string;
repository?: string;
url?: string;
recommendationContentSpan?: {
start: number;
end: number;
};
information: string;
}
export type CodeSelectionType = 'selection' | 'block';
export type OnCopiedToClipboardFunction = (type?: CodeSelectionType, text?: string, referenceTrackerInformation?: ReferenceTrackerInformation[], codeBlockIndex?: number, totalCodeBlocks?: number) => void;
export type OnCodeBlockActionFunction = (actionId: string, data?: any, type?: CodeSelectionType, text?: string, referenceTrackerInformation?: ReferenceTrackerInformation[], codeBlockIndex?: number, totalCodeBlocks?: number) => void;
export enum RelevancyVoteType {
UP = 'upvote',
DOWN = 'downvote',
}
/**
* 'interaction' will be set if there was a potential text selection or a click input was triggered by the user.
* If this is a selection selectionDistanceTraveled object will also be filled
* 'timespend' will be set basically if there is no interaction except mouse movements in a time spent longer than the ENGAGEMENT_DURATION_LIMIT
* Don't forget that in 'timespend' case, user should leave the suggestion card at some point to count it as an interaction.
* (They need to go back to the code or move to another card instead)
*/
export enum EngagementType {
INTERACTION = 'interaction',
TIME = 'timespend',
}
export interface Engagement {
/**
* Engagement type
*/
engagementType: EngagementType;
/**
* Total duration in ms till the engagement triggered.
*/
engagementDurationTillTrigger: number;
/**
* Total mouse movement in x and y directions till the engagement triggered.
* To avoid confusion: this is not the distance between start and end points, this is the total traveled distance.
*/
totalMouseDistanceTraveled: { x: number; y: number };
/**
* If the engagementType is "interaction" and this object has a value, you can assume it as a text selection.
* If the engagementType is "interaction" but this object is not defined, you can assume it as a click
*/
selectionDistanceTraveled?: { x: number; y: number; selectedText?: string };
}
export interface FeedbackPayload {
messageId: string;
tabId: string;
selectedOption: string;
comment?: string;
}
export enum NotificationType {
INFO = MynahIcons.INFO,
SUCCESS = MynahIcons.OK_CIRCLED,
WARNING = MynahIcons.WARNING,
ERROR = MynahIcons.ERROR,
}
export interface TabHeaderDetails {
icon?: MynahIcons | MynahIconsType;
title?: string;
description?: string;
}
export interface CodeBlockAction {
id: 'copy' | 'insert-to-cursor' | string;
label: string;
description?: string;
icon?: MynahIcons | MynahIconsType;
data?: any;
flash?: 'infinite' | 'once';
acceptedLanguages?: string[];
}
export type CodeBlockActions = Record<'copy' | 'insert-to-cursor' | string, CodeBlockAction | undefined | null>;
export interface ConfigTexts {
mainTitle: string;
feedbackFormTitle: string;
feedbackFormDescription: string;
feedbackFormOptionsLabel: string;
feedbackFormCommentLabel: string;
feedbackThanks: string;
feedbackReportButtonLabel: string;
codeSuggestions: string;
clickFileToViewDiff: string;
files: string;
changes: string;
insertAtCursorLabel: string;
copy: string;
showMore: string;
save: string;
cancel: string;
submit: string;
pleaseSelect: string;
stopGenerating: string;
copyToClipboard: string;
noMoreTabsTooltip: string;
codeSuggestionWithReferenceTitle: string;
spinnerText: string;
tabCloseConfirmationMessage: string;
tabCloseConfirmationKeepButton: string;
tabCloseConfirmationCloseButton: string;
noTabsOpen: string;
openNewTab: string;
commandConfirmation: string;
};
type PickMatching<T, V> = {
[K in keyof T as T[K] extends V ? K : never]: T[K];
};
type ExtractMethods<T> = PickMatching<T, any>;
export interface ComponentOverrides {
Button?: new(props: ButtonProps) => ExtractMethods<ButtonAbstract>;
RadioGroup?: new(props: RadioGroupProps) => ExtractMethods<RadioGroupAbstract>;
Checkbox?: new(props: CheckboxProps) => ExtractMethods<CheckboxAbstract>;
Select?: new(props: SelectProps) => ExtractMethods<SelectAbstract>;
TextInput?: new(props: TextInputProps) => ExtractMethods<TextInputAbstract>;
TextArea?: new(props: TextAreaProps) => ExtractMethods<TextAreaAbstract>;
};
export interface ConfigOptions {
feedbackOptions: Array<{
label: string;
value: string;
}>;
tabBarButtons?: TabBarMainAction[];
maxTabs: number;
maxTabsTooltipDuration?: number;
noMoreTabsTooltip?: string;
showPromptField: boolean;
autoFocus: boolean;
maxUserInput: number;
userInputLengthWarningThreshold: number;
codeBlockActions?: CodeBlockActions;
codeInsertToCursorEnabled?: boolean;
codeCopyToClipboardEnabled?: boolean;
test?: boolean;
}
export interface ConfigModel extends ConfigOptions {
texts: Partial<ConfigTexts>;
componentOverrides: Partial<ComponentOverrides>;
}
export interface CardRenderDetails {
totalNumberOfCodeBlocks?: number;
}