/*! * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import { RelevancyVoteType, FeedbackPayload, MynahUIDataModel, NotificationType, ChatItem, ChatItemAction, ChatPrompt, MynahUITabStoreModel, MynahUITabStoreTab, ConfigModel, ReferenceTrackerInformation, CodeSelectionType, Engagement, ChatItemFormItem, ChatItemButton, CardRenderDetails, PromptAttachmentType, QuickActionCommand, DetailedList, TreeNodeDetails, Action, DropdownListOption } from './static'; import { DetailedListSheetProps } from './components/detailed-list/detailed-list-sheet'; import { MynahUIDataStore } from './helper/store'; import { TopBarButtonOverlayProps } from './components/chat-item/prompt-input/prompt-top-bar/top-bar-button'; export { generateUID } from './helper/guid'; export { ChatItemBodyRenderer, } from './helper/dom'; export { AllowedAttributesInCustomRenderer, AllowedTagsInCustomRenderer } from './helper/sanitize'; export * from './static'; export { ToggleOption } from './components/tabs'; export { MynahIcons, MynahIconsType } from './components/icon'; export { DomBuilder, DomBuilderObject, ExtendedHTMLElement, } from './helper/dom'; export { ButtonProps, ButtonAbstract } from './components/button'; export { RadioGroupProps, RadioGroupAbstract } from './components/form-items/radio-group'; export { SelectProps, SelectAbstract } from './components/form-items/select'; export { TextInputProps, TextInputAbstract } from './components/form-items/text-input'; export { TextAreaProps, TextAreaAbstract } from './components/form-items/text-area'; export { ChatItemCardContent, ChatItemCardContentProps } from './components/chat-item/chat-item-card-content'; export { default as MynahUITestIds } from './helper/test-ids'; export interface MynahUIProps { rootSelector?: string; loadStyles?: boolean; defaults?: MynahUITabStoreTab; splashScreenInitialStatus?: { visible: boolean; text?: string; actions?: Action[]; }; tabs?: MynahUITabStoreModel; config?: Partial; onShowMoreWebResultsClick?: (tabId: string, messageId: string, eventId?: string) => void; onReady?: () => void; onFocusStateChanged?: (focusState: boolean) => void; onVote?: (tabId: string, messageId: string, vote: RelevancyVoteType, eventId?: string) => void; onStopChatResponse?: (tabId: string, eventId?: string) => void; onResetStore?: (tabId: string) => void; onChatPrompt?: (tabId: string, prompt: ChatPrompt, eventId?: string) => void; onChatPromptProgressActionButtonClicked?: (tabId: string, action: { id: string; text?: string; }, eventId?: string) => void; onFollowUpClicked?: (tabId: string, messageId: string, followUp: ChatItemAction, eventId?: string) => void; onInBodyButtonClicked?: (tabId: string, messageId: string, action: { id: string; text?: string; formItemValues?: Record; }, eventId?: string) => void; onTabbedContentTabChange?: (tabId: string, messageId: string, contentTabId: string, eventId?: string) => void; onTabChange?: (tabId: string, eventId?: string) => void; onTabAdd?: (tabId: string, eventId?: string) => void; onContextSelected?: (contextItem: QuickActionCommand, tabId: string, eventId?: string) => boolean; /** * Called when the user types in the `@` context picker. * The host should send the search term to the server for filtering * and update the store's `contextCommands` with the server response. * If not provided, client-side filtering is used as a fallback. */ onContextCommandFilter?: (tabId: string, searchTerm: string) => void; onTabRemove?: (tabId: string, eventId?: string) => void; onSearchShortcut?: (tabId: string, eventId?: string) => void; /** * @param tabId tabId which the close button triggered * @returns boolean -> If you want to close the tab immediately send true */ onBeforeTabRemove?: (tabId: string, eventId?: string) => boolean; onChatItemEngagement?: (tabId: string, messageId: string, engagement: Engagement) => void; onCodeBlockActionClicked?: (tabId: string, messageId: string, actionId: string, data?: string, code?: string, type?: CodeSelectionType, referenceTrackerInformation?: ReferenceTrackerInformation[], eventId?: string, codeBlockIndex?: number, totalCodeBlocks?: number) => void; /** * @deprecated since version 4.14.0. It will be only used for keyboard, context menu copy actions, not for button actions after version 5.x.x. Use {@link onCodeBlockActionClicked} instead */ onCopyCodeToClipboard?: (tabId: string, messageId: string, code?: string, type?: CodeSelectionType, referenceTrackerInformation?: ReferenceTrackerInformation[], eventId?: string, codeBlockIndex?: number, totalCodeBlocks?: number, data?: any) => void; /** * @deprecated since version 4.14.0. Will be dropped after version 5.x.x. Use {@link onCodeBlockActionClicked} instead */ onCodeInsertToCursorPosition?: (tabId: string, messageId: string, code?: string, type?: CodeSelectionType, referenceTrackerInformation?: ReferenceTrackerInformation[], eventId?: string, codeBlockIndex?: number, totalCodeBlocks?: number, data?: any) => void; onSourceLinkClick?: (tabId: string, messageId: string, link: string, mouseEvent?: MouseEvent, eventId?: string) => void; onLinkClick?: (tabId: string, messageId: string, link: string, mouseEvent?: MouseEvent, eventId?: string) => void; onInfoLinkClick?: (tabId: string, link: string, mouseEvent?: MouseEvent, eventId?: string) => void; onFormLinkClick?: (link: string, mouseEvent?: MouseEvent, eventId?: string) => void; onSendFeedback?: (tabId: string, feedbackPayload: FeedbackPayload, eventId?: string) => void; onFormModifierEnterPress?: (formData: Record, tabId: string, eventId?: string) => void; onFormTextualItemKeyPress?: (event: KeyboardEvent, formData: Record, itemId: string, tabId: string, eventId?: string) => boolean; onFormChange?: (formData: Record, isValid: boolean, tabId: string) => void; onCustomFormAction?: (tabId: string, action: { id: string; text?: string; formItemValues?: Record; }, eventId?: string) => void; onDropDownOptionChange?: (tabId: string, messageId: string, value: DropdownListOption[]) => void; onDropDownLinkClick?: (tabId: string, actionId: string, destination: string) => void; onPromptInputOptionChange?: (tabId: string, optionsValues: Record, eventId?: string) => void; onPromptInputButtonClick?: (tabId: string, buttonId: string, eventId?: string) => void; onPromptTopBarItemAdded?: (tabId: string, item: QuickActionCommand, eventId?: string) => void; onPromptTopBarItemRemoved?: (tabId: string, item: QuickActionCommand, eventId?: string) => void; onPromptTopBarButtonClick?: (tabId: string, button: ChatItemButton, eventId?: string) => void; /** * @deprecated since version 4.6.3. Will be dropped after version 5.x.x. Use {@link onFileClick} instead */ onOpenDiff?: (tabId: string, filePath: string, deleted: boolean, messageId?: string, eventId?: string) => void; onFileClick?: (tabId: string, filePath: string, deleted: boolean, messageId?: string, eventId?: string, fileDetails?: TreeNodeDetails) => void; onMessageDismiss?: (tabId: string, messageId: string, eventId?: string) => void; onFileActionClick?: (tabId: string, messageId: string, filePath: string, actionName: string, eventId?: string) => void; onTabBarButtonClick?: (tabId: string, buttonId: string, eventId?: string) => void; onQuickCommandGroupActionClick?: (tabId: string, action: { id: string; }, eventId?: string) => void; onSplashLoaderActionClick?: (action: Action, eventId?: string) => void; onOpenFileDialogClick?: (tabId: string, fileType: string, insertPosition: number) => void; onFilesDropped?: (tabId: string, files: FileList, insertPosition: number) => void; } export declare class MynahUI { private readonly render; private lastEventId; private readonly props; private readonly splashLoader; private readonly splashLoaderText; private readonly splashLoaderActions; private readonly tabsWrapper; private readonly tabContentsWrapper; private readonly feedbackForm?; private readonly sheet?; private readonly chatWrappers; constructor(props: MynahUIProps); private readonly getSplashLoaderActions; private readonly getUserEventId; private readonly focusToInput; private readonly addGlobalListeners; addToUserPrompt: (tabId: string, attachmentContent: string, type?: PromptAttachmentType) => void; /** * Adds a new item to the chat window * @param tabId Corresponding tab ID. * @param answer ChatItem object. */ addChatItem: (tabId: string, chatItem: ChatItem) => void; addCustomContextToPrompt: (tabId: string, contextItem: QuickActionCommand[], insertPosition?: number) => void; /** * Updates the last ChatItemType.ANSWER_STREAM chat item * @param tabId Corresponding tab ID. * @param updateWith ChatItem object to update with. */ updateLastChatAnswer: (tabId: string, updateWith: Partial) => void; /** * Updates the chat item with the given messageId * @param tabId Corresponding tab ID. * @param messageId Corresponding tab ID. * @param updateWith ChatItem object to update with. */ updateChatAnswerWithMessageId: (tabId: string, messageId: string, updateWith: Partial) => void; /** * Serialize all (non-empty) chat messages in a tab into a string * @param tabId Corresponding tab ID. * @param format Whether to serialize to markdown or HTML format */ serializeChat: (tabId: string, format: 'markdown' | 'html') => string; /** * Converts a card to an ANSWER if it is an ANSWER_STREAM * @param tabId Corresponding tab ID. * @param messageId Corresponding tab ID. * @param updateWith Optional, if you like update the card while converting it to * a normal ANSWER instead of a stream one, you can send a ChatItem object to update with. */ endMessageStream: (tabId: string, messageId: string, updateWith?: Partial) => CardRenderDetails; /** * If exists, switch to a different tab * @param tabId Tab ID to switch to * @param eventId last action's user event ID passed from an event binded to mynahUI. * Without user intent you cannot switch to a different tab */ selectTab: (tabId: string, eventId?: string) => void; /** * If exists, close the given tab * @param tabId Tab ID to switch to * @param eventId last action's user event ID passed from an event binded to mynahUI. * Without user intent you cannot switch to a different tab */ removeTab: (tabId: string, eventId: string) => void; /** * Updates only the UI with the given data for the given tab * Send tab id as an empty string to open a new tab! * If max tabs reached, will not return tabId * @param data A full or partial set of data with values. */ updateStore: (tabId: string | '', data: MynahUIDataModel) => string | undefined; /** * Updates defaults of the tab store * @param defaults MynahUITabStoreTab */ updateTabDefaults: (defaults: MynahUITabStoreTab) => void; /** * Updates defaults of the tab store * @param defaults MynahUITabStoreTab */ getTabDefaults: () => MynahUITabStoreTab; /** * This function returns the selected tab id if there is any, otherwise returns undefined * @returns string selectedTabId or undefined */ getSelectedTabId: () => string | undefined; /** * Returns all tabs with their store information * @returns string selectedTabId or undefined */ getAllTabs: () => MynahUITabStoreModel; getTabData: (tabId: string) => MynahUIDataStore; /** * Sets the drag overlay visibility for a specific tab * @param tabId The tab ID to set the drag overlay visibility for * @param visible Whether the drag overlay should be visible */ setDragOverlayVisible: (tabId: string, visible: boolean) => void; /** * Programmatically resets topBarClicked for the specified tab by dispatching a RESET_TOP_BAR_CLICKED event. * @param tabId The tab ID */ resetTopBarClicked: (tabId: string) => void; /** * Toggles the visibility of the splash loader screen */ toggleSplashLoader: (visible: boolean, text?: string, actions?: Action[]) => void; /** * Simply creates and shows a notification * @param props NotificationProps */ notify: (props: { /** * -1 for infinite */ duration?: number | undefined; type?: NotificationType | undefined; title?: string | undefined; content: string; onNotificationClick?: ((eventId: string) => void) | undefined; onNotificationHide?: ((eventId: string) => void) | undefined; }) => void; /** * Simply creates and shows a custom form */ showCustomForm: (tabId: string, formItems?: ChatItemFormItem[], buttons?: ChatItemButton[], title?: string, description?: string) => void; openTopBarButtonOverlay: (data: TopBarButtonOverlayProps) => { update: (data: DetailedList) => void; close: () => void; }; openDetailedList: (data: DetailedListSheetProps, showBackButton?: boolean) => { update: (data: DetailedList, showBackButton?: boolean) => void; close: () => void; changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void; getTargetElementId: () => string | undefined; }; destroy: () => void; }