@carbon/ai-chat 0.4.0-rc.2 → 0.4.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/dist/es/aiChatEntry.js +220 -14
  2. package/dist/es/chat.AppContainer.js +6491 -0
  3. package/dist/es/chat.AppState.js +40 -0
  4. package/dist/es/{chat/shared/components/BasePanelComponent.js → chat.BasePanelComponent.js} +3 -3
  5. package/dist/es/{chat/shared/components/panels/BodyAndFooterPanelComponent.js → chat.BodyAndFooterPanelComponent.js} +92 -9
  6. package/dist/es/chat.BodyWithFooterComponent.js +140 -0
  7. package/dist/es/{chat/shared/components/header/BotHeader.js → chat.BotHeader.js} +7 -9
  8. package/dist/es/{chat/shared/components/responseTypes/carousel/Carousel.js → chat.Carousel.js} +3 -3
  9. package/dist/es/chat.CatastrophicError.js +381 -0
  10. package/dist/es/chat.Chat.js +2009 -0
  11. package/dist/es/chat.Disclaimer.js +553 -0
  12. package/dist/es/chat.Header.js +1025 -0
  13. package/dist/es/{chat/shared/components/util/HideComponent.js → chat.HideComponent.js} +9 -2
  14. package/dist/es/{types/config/HomeScreenConfig.js → chat.HomeScreenConfig.js} +1 -1
  15. package/dist/es/{chat/shared/components/homeScreen/HomeScreen.js → chat.HomeScreenContainer.js} +159 -14
  16. package/dist/es/{chat/shared/components/homeScreen/HomeScreenHeader.js → chat.HomeScreenHeader.js} +3 -3
  17. package/dist/es/{chat/shared/services/haa/HumanAgentServiceImpl.js → chat.HumanAgentServiceImpl.js} +215 -17
  18. package/dist/es/{chat/shared/components/responseTypes/iframe/IFrameComponent.js → chat.IFrameComponent.js} +4 -8
  19. package/dist/es/chat.IFramePanel.js +151 -0
  20. package/dist/es/{chat/shared/components/input/Input.js → chat.Input.js} +214 -18
  21. package/dist/es/{types/config/ServiceDeskConfig.js → chat.LocalMessageItem.js} +17 -1
  22. package/dist/es/chat.MessageTypeComponent.js +3580 -0
  23. package/dist/es/{types/messaging/Messages.js → chat.Messages.js} +1 -1
  24. package/dist/es/chat.MountChildrenOnDelay.js +97 -0
  25. package/dist/es/{chat/shared/components/OverlayPanel.js → chat.PageObjectId.js} +70 -4
  26. package/dist/es/{chat/web-components/components/markdownText/src/markdownText.scss.js → chat.RichText.js} +347 -1
  27. package/dist/es/chat.TourContainer.js +524 -0
  28. package/dist/es/{chat/languages/en.json.js → chat.VideoComponent.js} +561 -1
  29. package/dist/es/chat.ViewSourcePanel.js +187 -0
  30. package/dist/es/{chat/shared/store/actions.js → chat.actions.js} +2 -2
  31. package/dist/es/{chat/shared/utils/browserUtils.js → chat.browserUtils.js} +1 -1
  32. package/dist/es/{types/utilities/carbonTypes.js → chat.carbonTypes.js} +2 -2
  33. package/dist/es/{chat/web-components/components/codeElement/src/codeElement.scss.js → chat.cds-aichat-code.js} +64 -1
  34. package/dist/es/{chat/shared/utils/constants.js → chat.constants.js} +4 -7
  35. package/dist/es/{types/events/eventBusTypes.js → chat.customElement.js} +32 -1
  36. package/dist/es/chat.dynamic-imports.js +192 -0
  37. package/dist/es/{chat/shared/utils/htmlUtils.js → chat.htmlUtils.js} +16 -2
  38. package/dist/es/{chat/shared/utils/messageUtils.js → chat.messageUtils.js} +54 -7
  39. package/dist/es/{chat/shared/utils/miscUtils.js → chat.miscUtils.js} +24 -5
  40. package/dist/es/chat.resolvablePromise.js +315 -0
  41. package/dist/es/{chat/shared/store/selectors.js → chat.selectors.js} +1 -1
  42. package/dist/es/{chat/shared/utils/lang/stringUtils.js → chat.stringUtils.js} +2 -2
  43. package/dist/es/{chat/shared/hooks/useCounter.js → chat.useCounter.js} +1 -1
  44. package/dist/es/{chat/shared/hooks/useOnMount.js → chat.useOnMount.js} +1 -1
  45. package/dist/es/{chat/shared/utils/domUtils.js → chat.usePrevious.js} +47 -1
  46. package/dist/es/{chat/shared/utils/lang/UUIDType.js → chat.uuid.js} +15 -3
  47. package/dist/es/web-components/cds-aichat-container/index.js +73 -4
  48. package/dist/es/web-components/cds-aichat-custom-element/index.js +1 -3
  49. package/package.json +2 -2
  50. package/dist/es/chat/dynamic-imports/dynamic-imports.js +0 -96
  51. package/dist/es/chat/react/components/AppContainer.js +0 -197
  52. package/dist/es/chat/react/components/UserDefinedResponsePortalsContainer.js +0 -31
  53. package/dist/es/chat/react/components/WriteableElementsPortalsContainer.js +0 -28
  54. package/dist/es/chat/react/components/chainOfThought/ChainOfThought.js +0 -20
  55. package/dist/es/chat/react/components/chatHeader/ChatHeaderAvatar.js +0 -20
  56. package/dist/es/chat/react/components/chatHeader/ChatHeaderLink.js +0 -22
  57. package/dist/es/chat/react/components/chatHeader/ChatHeaderMenu.js +0 -27
  58. package/dist/es/chat/react/components/chatHeader/ChatHeaderMenuButton.js +0 -60
  59. package/dist/es/chat/react/components/chatHeader/ChatHeaderMenuItem.js +0 -24
  60. package/dist/es/chat/react/components/chatHeader/ChatHeaderMenuItemRadioGroup.js +0 -28
  61. package/dist/es/chat/react/components/chatHeader/ChatHeaderOverflowMenu.js +0 -69
  62. package/dist/es/chat/react/components/chatHeader/ChatHeaderTitle.js +0 -22
  63. package/dist/es/chat/react/components/feedback/FeedbackButtonsComponent.js +0 -20
  64. package/dist/es/chat/react/components/feedback/FeedbackComponent.js +0 -20
  65. package/dist/es/chat/react/components/inlineLoading/InlineLoadingComponent.js +0 -20
  66. package/dist/es/chat/react/components/markdownText/MarkdownText.js +0 -20
  67. package/dist/es/chat/react/components/stopStreamingButton/StopStreamingButton.js +0 -20
  68. package/dist/es/chat/react/components/table/Table.js +0 -20
  69. package/dist/es/chat/shared/Chat.js +0 -115
  70. package/dist/es/chat/shared/ChatInstanceImpl.js +0 -360
  71. package/dist/es/chat/shared/chatEntryFunctions.js +0 -46
  72. package/dist/es/chat/shared/components/Avatar.js +0 -286
  73. package/dist/es/chat/shared/components/BodyWithFooterComponent.js +0 -56
  74. package/dist/es/chat/shared/components/CatastrophicError.js +0 -77
  75. package/dist/es/chat/shared/components/Chat.js +0 -244
  76. package/dist/es/chat/shared/components/ChatBubbleDark.js +0 -124
  77. package/dist/es/chat/shared/components/ChatBubbleLight.js +0 -216
  78. package/dist/es/chat/shared/components/Disclaimer.js +0 -86
  79. package/dist/es/chat/shared/components/ErrorIcon.js +0 -20
  80. package/dist/es/chat/shared/components/ErrorMessageDark.js +0 -89
  81. package/dist/es/chat/shared/components/ErrorMessageLight.js +0 -135
  82. package/dist/es/chat/shared/components/HydrationPanel.js +0 -58
  83. package/dist/es/chat/shared/components/LatestWelcomeNodes.js +0 -26
  84. package/dist/es/chat/shared/components/ResponseStopped.js +0 -19
  85. package/dist/es/chat/shared/components/SkeletonPicker.js +0 -32
  86. package/dist/es/chat/shared/components/WriteableElement.js +0 -22
  87. package/dist/es/chat/shared/components/agent/AgentAvatar.js +0 -54
  88. package/dist/es/chat/shared/components/agent/AgentBanner.js +0 -109
  89. package/dist/es/chat/shared/components/agent/AgentBannerContainer.js +0 -28
  90. package/dist/es/chat/shared/components/agent/AvailabilityMessage.js +0 -49
  91. package/dist/es/chat/shared/components/aria/AriaAnnouncerComponent.js +0 -122
  92. package/dist/es/chat/shared/components/aria/AriaAnnouncerProvider.js +0 -48
  93. package/dist/es/chat/shared/components/aria/AriaLiveMessage.js +0 -22
  94. package/dist/es/chat/shared/components/header/AISlug.js +0 -22
  95. package/dist/es/chat/shared/components/header/Header.js +0 -460
  96. package/dist/es/chat/shared/components/header/SimpleHeader.js +0 -27
  97. package/dist/es/chat/shared/components/homeScreen/HomeScreenContainer.js +0 -68
  98. package/dist/es/chat/shared/components/launcher/Launcher.js +0 -88
  99. package/dist/es/chat/shared/components/launcher/LauncherComplex.js +0 -63
  100. package/dist/es/chat/shared/components/launcher/LauncherContainer.js +0 -73
  101. package/dist/es/chat/shared/components/launcher/LauncherDesktopContainer.js +0 -221
  102. package/dist/es/chat/shared/components/launcher/LauncherExtended.js +0 -244
  103. package/dist/es/chat/shared/components/launcher/LauncherMobileContainer.js +0 -175
  104. package/dist/es/chat/shared/components/launcher/launcherUtils.js +0 -16
  105. package/dist/es/chat/shared/components/modals/ConfirmModal.js +0 -67
  106. package/dist/es/chat/shared/components/modals/EndAgentChatModal.js +0 -46
  107. package/dist/es/chat/shared/components/modals/RequestScreenShareModal.js +0 -43
  108. package/dist/es/chat/shared/components/notifications/Notifications.js +0 -58
  109. package/dist/es/chat/shared/components/panels/CustomPanel.js +0 -136
  110. package/dist/es/chat/shared/components/responseTypes/agent/ConnectToAgent.js +0 -30
  111. package/dist/es/chat/shared/components/responseTypes/agent/RealConnectToAgent.js +0 -102
  112. package/dist/es/chat/shared/components/responseTypes/audio/AudioComponent.js +0 -26
  113. package/dist/es/chat/shared/components/responseTypes/buttonItem/BaseButtonItemComponent.js +0 -69
  114. package/dist/es/chat/shared/components/responseTypes/buttonItem/ButtonItemComponent.js +0 -48
  115. package/dist/es/chat/shared/components/responseTypes/buttonItem/ButtonItemCustomEventComponent.js +0 -42
  116. package/dist/es/chat/shared/components/responseTypes/buttonItem/ButtonItemPostBackComponent.js +0 -54
  117. package/dist/es/chat/shared/components/responseTypes/buttonItem/ButtonItemShowPanelComponent.js +0 -36
  118. package/dist/es/chat/shared/components/responseTypes/buttonItem/ButtonItemURLComponent.js +0 -42
  119. package/dist/es/chat/shared/components/responseTypes/card/CardItemComponent.js +0 -34
  120. package/dist/es/chat/shared/components/responseTypes/carousel/CarouselItemComponent.js +0 -39
  121. package/dist/es/chat/shared/components/responseTypes/conversationalSearch/ConversationalSearch.js +0 -92
  122. package/dist/es/chat/shared/components/responseTypes/conversationalSearch/ConversationalSearchText.js +0 -158
  123. package/dist/es/chat/shared/components/responseTypes/custom/UserDefinedResponse.js +0 -33
  124. package/dist/es/chat/shared/components/responseTypes/datePicker/DatePickerComponent.js +0 -176
  125. package/dist/es/chat/shared/components/responseTypes/error/InlineError.js +0 -32
  126. package/dist/es/chat/shared/components/responseTypes/grid/GridItemComponent.js +0 -109
  127. package/dist/es/chat/shared/components/responseTypes/iframe/IFrameMessage.js +0 -32
  128. package/dist/es/chat/shared/components/responseTypes/iframe/IFramePanel.js +0 -51
  129. package/dist/es/chat/shared/components/responseTypes/iframe/IFramePreviewCard.js +0 -64
  130. package/dist/es/chat/shared/components/responseTypes/iframe/InlineIFrame.js +0 -55
  131. package/dist/es/chat/shared/components/responseTypes/image/Image.js +0 -120
  132. package/dist/es/chat/shared/components/responseTypes/options/OptionComponent.js +0 -83
  133. package/dist/es/chat/shared/components/responseTypes/options/SelectComponent.js +0 -84
  134. package/dist/es/chat/shared/components/responseTypes/table/TableContainer.js +0 -96
  135. package/dist/es/chat/shared/components/responseTypes/text/TextArea.js +0 -68
  136. package/dist/es/chat/shared/components/responseTypes/tour/TourCard.js +0 -73
  137. package/dist/es/chat/shared/components/responseTypes/util/BodyMessageComponents.js +0 -65
  138. package/dist/es/chat/shared/components/responseTypes/util/ClickableImage.js +0 -36
  139. package/dist/es/chat/shared/components/responseTypes/util/Description.js +0 -21
  140. package/dist/es/chat/shared/components/responseTypes/util/FooterButtonComponents.js +0 -36
  141. package/dist/es/chat/shared/components/responseTypes/util/MediaPlayer.js +0 -157
  142. package/dist/es/chat/shared/components/responseTypes/util/Metablock.js +0 -27
  143. package/dist/es/chat/shared/components/responseTypes/util/RichText.js +0 -31
  144. package/dist/es/chat/shared/components/responseTypes/util/SearchResultBody.js +0 -53
  145. package/dist/es/chat/shared/components/responseTypes/util/StreamingRichText.js +0 -38
  146. package/dist/es/chat/shared/components/responseTypes/util/TextHolderTile.js +0 -35
  147. package/dist/es/chat/shared/components/responseTypes/util/citations/CitationCard.js +0 -65
  148. package/dist/es/chat/shared/components/responseTypes/util/citations/CitationCardContent.js +0 -62
  149. package/dist/es/chat/shared/components/responseTypes/util/citations/CitationClickableCard.js +0 -23
  150. package/dist/es/chat/shared/components/responseTypes/util/citations/ExpandToPanelCard.js +0 -50
  151. package/dist/es/chat/shared/components/responseTypes/util/citations/ViewSourcePanel.js +0 -57
  152. package/dist/es/chat/shared/components/responseTypes/video/VideoComponent.js +0 -23
  153. package/dist/es/chat/shared/components/tour/TourCloseMinimizeComponent.js +0 -44
  154. package/dist/es/chat/shared/components/tour/TourContainer.js +0 -212
  155. package/dist/es/chat/shared/components/tour/TourControlsComponent.js +0 -98
  156. package/dist/es/chat/shared/components/tour/TourStepContentComponent.js +0 -156
  157. package/dist/es/chat/shared/components/tour/TourStepSkeletonComponent.js +0 -20
  158. package/dist/es/chat/shared/components/util/AnnounceOnMountComponent.js +0 -42
  159. package/dist/es/chat/shared/components/util/IconHolder.js +0 -16
  160. package/dist/es/chat/shared/components/util/ImageWithFallback.js +0 -31
  161. package/dist/es/chat/shared/components/util/MaybeDangerouslySetInnerHTML.js +0 -42
  162. package/dist/es/chat/shared/components/util/MountChildrenOnDelay.js +0 -40
  163. package/dist/es/chat/shared/components/util/VisuallyHidden.js +0 -18
  164. package/dist/es/chat/shared/containers/App.js +0 -181
  165. package/dist/es/chat/shared/containers/MessageComponent.js +0 -465
  166. package/dist/es/chat/shared/containers/MessageTypeComponent.js +0 -496
  167. package/dist/es/chat/shared/containers/MessagesComponent.js +0 -469
  168. package/dist/es/chat/shared/containers/ModalPortal.js +0 -53
  169. package/dist/es/chat/shared/containers/main/MainWindow.js +0 -708
  170. package/dist/es/chat/shared/contexts/AriaAnnouncerContext.js +0 -12
  171. package/dist/es/chat/shared/contexts/HideComponentContext.js +0 -12
  172. package/dist/es/chat/shared/contexts/LanguagePackContext.js +0 -12
  173. package/dist/es/chat/shared/contexts/ModalPortalRootContext.js +0 -12
  174. package/dist/es/chat/shared/contexts/ServiceManagerContext.js +0 -12
  175. package/dist/es/chat/shared/contexts/WindowSizeContext.js +0 -12
  176. package/dist/es/chat/shared/environmentVariables.js +0 -13
  177. package/dist/es/chat/shared/events/ChatActionsImpl.js +0 -783
  178. package/dist/es/chat/shared/events/EventBus.js +0 -161
  179. package/dist/es/chat/shared/hocs/withAriaAnnouncer.js +0 -25
  180. package/dist/es/chat/shared/hocs/withServiceManager.js +0 -25
  181. package/dist/es/chat/shared/hooks/useAriaAnnouncer.js +0 -16
  182. package/dist/es/chat/shared/hooks/useCSSCustomProperties.js +0 -21
  183. package/dist/es/chat/shared/hooks/useCallbackOnChange.js +0 -24
  184. package/dist/es/chat/shared/hooks/useEffectDidUpdate.js +0 -21
  185. package/dist/es/chat/shared/hooks/useLanguagePack.js +0 -16
  186. package/dist/es/chat/shared/hooks/usePrevious.js +0 -18
  187. package/dist/es/chat/shared/hooks/useServiceManager.js +0 -16
  188. package/dist/es/chat/shared/hooks/useShouldSanitizeHTML.js +0 -15
  189. package/dist/es/chat/shared/hooks/useUUID.js +0 -22
  190. package/dist/es/chat/shared/hooks/useWindowSize.js +0 -16
  191. package/dist/es/chat/shared/loadServices.js +0 -72
  192. package/dist/es/chat/shared/schema/historyToMessages.js +0 -231
  193. package/dist/es/chat/shared/schema/inputItemToLocalItem.js +0 -30
  194. package/dist/es/chat/shared/schema/outputItemToLocalItem.js +0 -124
  195. package/dist/es/chat/shared/services/CustomPanelInstance.js +0 -26
  196. package/dist/es/chat/shared/services/CustomPanelManager.js +0 -23
  197. package/dist/es/chat/shared/services/HistoryService.js +0 -59
  198. package/dist/es/chat/shared/services/MessageService.js +0 -351
  199. package/dist/es/chat/shared/services/NamespaceService.js +0 -26
  200. package/dist/es/chat/shared/services/ServiceManager.js +0 -19
  201. package/dist/es/chat/shared/services/UserSessionStorageService.js +0 -89
  202. package/dist/es/chat/shared/services/haa/agentStatusMessage.js +0 -108
  203. package/dist/es/chat/shared/services/haa/humanAgentUtils.js +0 -114
  204. package/dist/es/chat/shared/services/mockStorage.js +0 -30
  205. package/dist/es/chat/shared/store/agentActions.js +0 -125
  206. package/dist/es/chat/shared/store/agentReducers.js +0 -215
  207. package/dist/es/chat/shared/store/doCreateStore.js +0 -142
  208. package/dist/es/chat/shared/store/reducerUtils.js +0 -320
  209. package/dist/es/chat/shared/store/reducers.js +0 -871
  210. package/dist/es/chat/shared/store/subscriptions.js +0 -55
  211. package/dist/es/chat/shared/store/tourReducerUtils.js +0 -51
  212. package/dist/es/chat/shared/utils/ListenerList.js +0 -26
  213. package/dist/es/chat/shared/utils/PageObjectId.js +0 -25
  214. package/dist/es/chat/shared/utils/animationUtils.js +0 -77
  215. package/dist/es/chat/shared/utils/colors.js +0 -71
  216. package/dist/es/chat/shared/utils/customizers.js +0 -16
  217. package/dist/es/chat/shared/utils/dateUtils.js +0 -38
  218. package/dist/es/chat/shared/utils/homeScreenUtils.js +0 -27
  219. package/dist/es/chat/shared/utils/intlUtils.js +0 -21
  220. package/dist/es/chat/shared/utils/lang/arrayUtils.js +0 -53
  221. package/dist/es/chat/shared/utils/lang/langUtils.js +0 -13
  222. package/dist/es/chat/shared/utils/lang/objectUtils.js +0 -19
  223. package/dist/es/chat/shared/utils/lang/promiseUtils.js +0 -25
  224. package/dist/es/chat/shared/utils/lang/uuid.js +0 -16
  225. package/dist/es/chat/shared/utils/languages.js +0 -156
  226. package/dist/es/chat/shared/utils/memoizerUtils.js +0 -38
  227. package/dist/es/chat/shared/utils/messageServiceUtils.js +0 -36
  228. package/dist/es/chat/shared/utils/resolvablePromise.js +0 -32
  229. package/dist/es/chat/shared/utils/styleUtils.js +0 -231
  230. package/dist/es/chat/shared/utils/timeUtils.js +0 -14
  231. package/dist/es/chat/shared/utils/viewStateUtils.js +0 -38
  232. package/dist/es/chat/web-components/components/chainOfThought/cds-aichat-chain-of-thought.js +0 -26
  233. package/dist/es/chat/web-components/components/chainOfThought/src/ChainOfThoughtElement.js +0 -130
  234. package/dist/es/chat/web-components/components/chainOfThought/src/chainOfThoughtElement.scss.js +0 -3
  235. package/dist/es/chat/web-components/components/chainOfThought/src/chainOfThoughtElement.template.js +0 -186
  236. package/dist/es/chat/web-components/components/chatHeader/chatHeaderAvatar/cds-aichat-chat-header-avatar.js +0 -26
  237. package/dist/es/chat/web-components/components/chatHeader/chatHeaderAvatar/src/chatHeaderAvatar.template.js +0 -32
  238. package/dist/es/chat/web-components/components/chatHeader/chatHeaderAvatar/src/chatHeaderAvatarElement.js +0 -52
  239. package/dist/es/chat/web-components/components/chatHeader/chatHeaderAvatar/src/chatHeaderAvatarElement.scss.js +0 -3
  240. package/dist/es/chat/web-components/components/chatHeader/chatHeaderLink/cds-aichat-chat-header-link.js +0 -44
  241. package/dist/es/chat/web-components/components/chatHeader/chatHeaderLink/src/chatHeaderLinkElement.template.js +0 -28
  242. package/dist/es/chat/web-components/components/chatHeader/chatHeaderTitle/cds-aichat-chat-header-title.js +0 -42
  243. package/dist/es/chat/web-components/components/chatHeader/chatHeaderTitle/src/chatHeaderTitle.scss.js +0 -3
  244. package/dist/es/chat/web-components/components/chatHeader/chatHeaderTitle/src/chatHeaderTitle.template.js +0 -20
  245. package/dist/es/chat/web-components/components/codeElement/cds-aichat-code.js +0 -66
  246. package/dist/es/chat/web-components/components/feedbackButtonsElement/cds-aichat-feedback-buttons.js +0 -26
  247. package/dist/es/chat/web-components/components/feedbackButtonsElement/src/FeedbackButtonsElement.js +0 -93
  248. package/dist/es/chat/web-components/components/feedbackButtonsElement/src/feedbackButtonsElement.scss.js +0 -3
  249. package/dist/es/chat/web-components/components/feedbackButtonsElement/src/feedbackButtonsElement.template.js +0 -84
  250. package/dist/es/chat/web-components/components/feedbackElement/cds-aichat-feedback.js +0 -30
  251. package/dist/es/chat/web-components/components/feedbackElement/src/FeedbackElement.js +0 -157
  252. package/dist/es/chat/web-components/components/feedbackElement/src/feedbackElement.scss.js +0 -3
  253. package/dist/es/chat/web-components/components/feedbackElement/src/feedbackElement.template.js +0 -95
  254. package/dist/es/chat/web-components/components/inlineLoadingElement/cds-aichat-inline-loading.js +0 -85
  255. package/dist/es/chat/web-components/components/inlineLoadingElement/src/styles.scss.js +0 -3
  256. package/dist/es/chat/web-components/components/markdownText/cds-aichat-markdown-text.js +0 -32
  257. package/dist/es/chat/web-components/components/markdownText/markdown/markdownToHTML.js +0 -28
  258. package/dist/es/chat/web-components/components/markdownText/markdown/utils/renderTokenTree.js +0 -191
  259. package/dist/es/chat/web-components/components/markdownText/markdown/workers/workerManager.js +0 -16
  260. package/dist/es/chat/web-components/components/markdownText/src/MarkdownElement.js +0 -70
  261. package/dist/es/chat/web-components/components/markdownText/src/markdownElement.template.js +0 -19
  262. package/dist/es/chat/web-components/components/roundedButton/cds-aichat-rounded-button.js +0 -29
  263. package/dist/es/chat/web-components/components/stopStreamingButton/cds-aichat-stop-streaming-button.js +0 -26
  264. package/dist/es/chat/web-components/components/stopStreamingButton/src/StopStreamingButtonElement.js +0 -49
  265. package/dist/es/chat/web-components/components/stopStreamingButton/src/stopStreamingButton.scss.js +0 -3
  266. package/dist/es/chat/web-components/components/stopStreamingButton/src/stopStreamingButton.template.js +0 -44
  267. package/dist/es/chat/web-components/components/table/cds-aichat-table.js +0 -229
  268. package/dist/es/chat/web-components/components/table/src/table.scss.js +0 -3
  269. package/dist/es/chat/web-components/components/table/src/table.template.js +0 -81
  270. package/dist/es/chat/web-components/components/table/src/tablePagination.template.js +0 -43
  271. package/dist/es/chat/web-components/components/table/src/tableSkeleton.template.js +0 -17
  272. package/dist/es/chat/web-components/components/tagListElement/cds-aichat-tag-list.js +0 -28
  273. package/dist/es/chat/web-components/components/tagListElement/src/TagListElement.js +0 -70
  274. package/dist/es/chat/web-components/components/tagListElement/src/tagListElement.scss.js +0 -3
  275. package/dist/es/chat/web-components/components/tagListElement/src/tagListElement.template.js +0 -40
  276. package/dist/es/chat/web-components/decorators/customElement.js +0 -33
  277. package/dist/es/chat/web-components/internal/cds-aichat-internal.js +0 -78
  278. package/dist/es/chat/web-components/settings.js +0 -13
  279. package/dist/es/node_modules/@carbon/colors/es/index.js +0 -11
  280. package/dist/es/react/ChatContainer.js +0 -162
  281. package/dist/es/react/ChatCustomElement.js +0 -58
  282. package/dist/es/types/config/ChatHeaderConfig.js +0 -18
  283. package/dist/es/types/config/CornersType.js +0 -16
  284. package/dist/es/types/config/LauncherConfig.js +0 -19
  285. package/dist/es/types/config/PublicConfig.js +0 -36
  286. package/dist/es/types/instance/ChatInstance.js +0 -31
  287. package/dist/es/types/instance/apiTypes.js +0 -33
  288. package/dist/es/types/messaging/LocalMessageItem.js +0 -18
  289. package/dist/es/types/state/AppState.js +0 -18
  290. package/dist/es/types/utilities/Animation.js +0 -31
  291. package/dist/es/types/utilities/HasAddRemoveClassName.js +0 -27
  292. /package/dist/es/{chat/shared/styles/export.carbon.scss.js → chat.export.carbon.js} +0 -0
  293. /package/dist/es/{chat/shared/styles/export.scss.js → chat.export.js} +0 -0
  294. /package/dist/es/{chat/web-components/components/markdownText/markdown/utils/markdown.js → chat.markdown.js} +0 -0
  295. /package/dist/es/{chat/web-components/components/markdownText/markdown/utils/tokenTree.js → chat.tokenTree.js} +0 -0
@@ -1,783 +0,0 @@
1
- import cloneDeep from "lodash-es/cloneDeep.js";
2
-
3
- import isEqual from "lodash-es/isEqual.js";
4
-
5
- import merge from "lodash-es/merge.js";
6
-
7
- import inputItemToLocalItem from "../schema/inputItemToLocalItem.js";
8
-
9
- import { outputItemToLocalItem, createLocalMessageItemsForNestedMessageItems } from "../schema/outputItemToLocalItem.js";
10
-
11
- import { AgentsOnlineStatus } from "../../../types/config/ServiceDeskConfig.js";
12
-
13
- import actions from "../store/actions.js";
14
-
15
- import { agentUpdateIsSuspended } from "../store/agentActions.js";
16
-
17
- import { DEFAULT_PERSISTED_TO_BROWSER, VIEW_STATE_LAUNCHER_OPEN } from "../store/reducerUtils.js";
18
-
19
- import "../../../types/state/AppState.js";
20
-
21
- import { arrayLastValue, asyncForEach } from "../utils/lang/arrayUtils.js";
22
-
23
- import { deepFreeze } from "../utils/lang/objectUtils.js";
24
-
25
- import { sleep } from "../utils/lang/promiseUtils.js";
26
-
27
- import { uuid } from "../utils/lang/uuid.js";
28
-
29
- import { createWelcomeRequest, isLiveAgentMessage, isRequest, createMessageRequestForText, addDefaultsToMessage, isResponse, createMessageResponseForText, isStreamCompleteItem, isStreamPartialItem, isStreamFinalResponse, renderAsUserDefinedMessage, isResponseWithNestedItems, streamItemID, isPause, isConnectToAgent, hasTourUserDefinedType, hasServiceDesk, isTyping } from "../utils/messageUtils.js";
30
-
31
- import { debugLog, isEnableDebugLog, consoleError, consoleWarn, callOnError } from "../utils/miscUtils.js";
32
-
33
- import { resolvablePromise } from "../utils/resolvablePromise.js";
34
-
35
- import { mergeCSSVariables } from "../utils/styleUtils.js";
36
-
37
- import { constructViewState, validateViewState } from "../utils/viewStateUtils.js";
38
-
39
- import { MessageResponseTypes } from "../../../types/messaging/Messages.js";
40
-
41
- import { BusEventType, MessageSendSource, TourStartReason, MainWindowCloseReason, ViewChangeReason, MainWindowOpenReason } from "../../../types/events/eventBusTypes.js";
42
-
43
- import { CSSVariable } from "../../../types/instance/ChatInstance.js";
44
-
45
- import { OnErrorType } from "../../../types/config/PublicConfig.js";
46
-
47
- import { setIntl } from "../utils/intlUtils.js";
48
-
49
- import { UUIDType } from "../utils/lang/UUIDType.js";
50
-
51
- import { ViewType } from "../../../types/instance/apiTypes.js";
52
-
53
- /*
54
- * Copyright IBM Corp. 2025
55
- *
56
- * This source code is licensed under the Apache-2.0 license found in the
57
- * LICENSE file in the root directory of this source tree.
58
- *
59
- * @license
60
- */ const VALID_PUBLIC_VARS_IN_AI_THEME_SET = new Set(Object.values(CSSVariable));
61
-
62
- const UPDATE_CSS_VARS_AI_THEME_WARNING_MESSAGE = `[updateCSSVariables] The AI theme is enabled and only ${Object.values(CSSVariable).join(", ")} can be updated.`;
63
-
64
- class ChatActionsImpl {
65
- constructor(serviceManager) {
66
- this.hydrating = false;
67
- this.restarting = false;
68
- this.alreadyHydrated = false;
69
- this.chunkQueue = [];
70
- this.serviceManager = serviceManager;
71
- }
72
- async hydrateChat(alternateWelcomeRequest, alternateWelcomeRequestSource, alternateOptions) {
73
- let fireReady = false;
74
- try {
75
- if (!this.hydrationPromise) {
76
- this.hydrating = true;
77
- this.hydrationPromise = this.doHydrateChat(alternateWelcomeRequest, alternateWelcomeRequestSource, alternateOptions);
78
- fireReady = true;
79
- }
80
- await this.hydrationPromise;
81
- } finally {
82
- this.hydrating = false;
83
- }
84
- if (fireReady) {
85
- await this.serviceManager.fire({
86
- type: BusEventType.CHAT_READY
87
- });
88
- }
89
- }
90
- async doHydrateChat(alternateWelcomeRequest, alternateWelcomeRequestSource, alternateOptions) {
91
- debugLog("Hydrating Carbon AI chat", alternateWelcomeRequest, alternateWelcomeRequestSource, alternateOptions);
92
- let history;
93
- const {serviceManager: serviceManager} = this;
94
- serviceManager.store.dispatch(actions.addIsHydratingCounter(1));
95
- if (!this.alreadyHydrated) {
96
- history = await this.serviceManager.historyService.loadHistory();
97
- if (serviceManager.humanAgentService) {
98
- debugLog("Initializing the human agent service");
99
- await serviceManager.humanAgentService.initialize();
100
- } else {
101
- debugLog("No service desk integrations present");
102
- }
103
- }
104
- const {config: config} = serviceManager.store.getState();
105
- if (!history) {
106
- if (!alternateWelcomeRequest) {
107
- const state = serviceManager.store.getState();
108
- if (state.homeScreenConfig?.is_on) {
109
- serviceManager.store.dispatch(actions.setHomeScreenIsOpen(true));
110
- } else if (!config.public.messaging?.skipWelcome) {
111
- await serviceManager.actions.send(createWelcomeRequest(), MessageSendSource.WELCOME_REQUEST, {
112
- returnBeforeStreaming: true
113
- }, true);
114
- }
115
- }
116
- } else {
117
- serviceManager.store.dispatch(actions.hydrateMessageHistory(history.messageHistory));
118
- await this.createElementsForUserDefinedResponses(history.messageHistory);
119
- if (history.latestPanelLocalMessageItem) {
120
- this.openResponsePanel(history.latestPanelLocalMessageItem, true);
121
- }
122
- }
123
- if (alternateWelcomeRequest) {
124
- serviceManager.store.dispatch(actions.setHomeScreenIsOpen(false));
125
- await serviceManager.actions.send(alternateWelcomeRequest, alternateWelcomeRequestSource, alternateOptions, true);
126
- }
127
- serviceManager.store.dispatch(actions.chatWasHydrated());
128
- serviceManager.store.dispatch(actions.addIsHydratingCounter(-1));
129
- if (history) {
130
- const lastMessageID = arrayLastValue(history.messageHistory.botMessageState.localMessageIDs);
131
- const lastMessage = history.messageHistory.allMessageItemsByID[lastMessageID];
132
- const lastOriginalMessage = history.messageHistory.allMessagesByID[lastMessage?.fullMessageID];
133
- if (!isLiveAgentMessage(lastMessage) && isRequest(lastOriginalMessage)) {
134
- serviceManager.messageService.resendMessage(lastOriginalMessage, lastMessage.ui_state.id);
135
- }
136
- }
137
- const allowReconnect = config.public.serviceDesk.allowReconnect ?? true;
138
- this.serviceManager?.humanAgentService?.handleHydration(allowReconnect, Boolean(history));
139
- this.alreadyHydrated = true;
140
- }
141
- getPublicWebChatState() {
142
- const state = this.serviceManager.store.getState();
143
- const {persistedToBrowserStorage: persistedToBrowserStorage} = state;
144
- const {chatState: chatState, launcherState: launcherState} = persistedToBrowserStorage;
145
- const publicWebChatState = {
146
- isConnectedWithHumanAgent: chatState.agentState.isConnected,
147
- isWebChatOpen: launcherState.viewState.mainWindow,
148
- isConnectingWithHumanAgent: state.agentState.isConnecting,
149
- isHomeScreenOpen: chatState.homeScreenState.isHomeScreenOpen,
150
- isDebugEnabled: isEnableDebugLog(),
151
- hasUserSentMessage: chatState.hasSentNonWelcomeMessage,
152
- isTourActive: launcherState.activeTour,
153
- viewState: {
154
- ...launcherState.viewState
155
- },
156
- serviceDesk: {
157
- isConnected: chatState.agentState.isConnected,
158
- isConnecting: state.agentState.isConnecting,
159
- isSuspended: chatState.agentState.isSuspended ?? false
160
- },
161
- locale: this.serviceManager.store.getState().locale,
162
- intl: this.serviceManager.intl
163
- };
164
- return publicWebChatState;
165
- }
166
- async sendWithCatch(message, source, options = {}, ignoreHydration = false) {
167
- try {
168
- await this.send(message, source, options, ignoreHydration);
169
- } catch (error) {
170
- consoleError("An error occurred sending the message", error);
171
- }
172
- }
173
- async send(message, source, options = {}, ignoreHydration = false) {
174
- const messageRequest = typeof message === "string" ? createMessageRequestForText(message) : message;
175
- if (this.serviceManager.store.getState().persistedToBrowserStorage.chatState.homeScreenState.isHomeScreenOpen) {
176
- this.serviceManager.store.dispatch(actions.setHomeScreenIsOpen(false));
177
- }
178
- if (this.serviceManager.store.getState().responsePanelState.isOpen) {
179
- this.serviceManager.store.dispatch(actions.setResponsePanelIsOpen(false));
180
- }
181
- if (this.hydrationPromise || ignoreHydration) {
182
- if (!ignoreHydration) {
183
- await this.hydrationPromise;
184
- }
185
- await this.doSend(messageRequest, source, options);
186
- } else {
187
- await this.hydrateChat(messageRequest, source, options);
188
- }
189
- }
190
- async doSend(message, source, options = {}) {
191
- const {store: store} = this.serviceManager;
192
- addDefaultsToMessage(message);
193
- const originalUserText = message.history?.label || message.input.text;
194
- if (options.silent) {
195
- message.history.silent = true;
196
- }
197
- const localMessage = inputItemToLocalItem(message, originalUserText);
198
- if (!message.history.silent) {
199
- store.dispatch(actions.addLocalMessageItem(localMessage, message, true));
200
- } else {
201
- store.dispatch(actions.addMessage(message));
202
- }
203
- if (options.setValueSelectedForMessageID) {
204
- store.dispatch(actions.messageSetOptionSelected(options.setValueSelectedForMessageID, message));
205
- }
206
- deepFreeze(message);
207
- await this.serviceManager.messageService.send(cloneDeep(message), source, localMessage.ui_state.id, options);
208
- }
209
- async receive(message, isLatestWelcomeNode = false, requestMessage, requestOptions) {
210
- const {restartCount: initialRestartCount} = this.serviceManager;
211
- if (!message.id) {
212
- message.id = uuid(UUIDType.MESSAGE);
213
- }
214
- const preReceiveEvent = {
215
- type: BusEventType.PRE_RECEIVE,
216
- data: message
217
- };
218
- await this.serviceManager.fire(preReceiveEvent);
219
- if (initialRestartCount !== this.serviceManager.restartCount) {
220
- return;
221
- }
222
- if (!isLatestWelcomeNode) {
223
- this.serviceManager.store.dispatch(actions.updateHasSentNonWelcomeMessage(true));
224
- }
225
- if (initialRestartCount !== this.serviceManager.restartCount) {
226
- return;
227
- }
228
- const {languagePack: languagePack} = this.serviceManager.store.getState();
229
- if (isResponse(message)) {
230
- this.processMessageResponse(message, isLatestWelcomeNode, requestMessage, requestOptions).catch(error => {
231
- consoleError("Error processing the message response", error);
232
- });
233
- } else {
234
- const inlineError = createMessageResponseForText(languagePack.errors_singleMessage, message.thread_id, MessageResponseTypes.INLINE_ERROR);
235
- this.receive(inlineError, false);
236
- }
237
- deepFreeze(message);
238
- await this.serviceManager.fire({
239
- type: BusEventType.RECEIVE,
240
- data: message
241
- });
242
- }
243
- async removeMessages(messageIDs) {
244
- this.serviceManager.store.dispatch(actions.removeMessages(messageIDs));
245
- }
246
- async insertHistory(messages) {
247
- const scrollBottom = this.serviceManager.mainWindow?.getMessagesScrollBottom();
248
- const state = this.serviceManager.store.getState();
249
- const notes = {
250
- notes: [ {
251
- body: messages
252
- } ]
253
- };
254
- const history = await this.serviceManager.historyService.loadHistory(notes);
255
- const currentAppStateMessages = {
256
- allMessageItemsByID: state.allMessageItemsByID,
257
- allMessagesByID: state.allMessagesByID,
258
- botMessageState: state.botMessageState
259
- };
260
- const newAppStateMessages = merge({}, history.messageHistory, currentAppStateMessages);
261
- newAppStateMessages.botMessageState.messageIDs = [ ...history.messageHistory.botMessageState.messageIDs, ...currentAppStateMessages.botMessageState.messageIDs ];
262
- newAppStateMessages.botMessageState.localMessageIDs = [ ...history.messageHistory.botMessageState.localMessageIDs, ...currentAppStateMessages.botMessageState.localMessageIDs ];
263
- this.serviceManager.store.dispatch(actions.hydrateMessageHistory(newAppStateMessages));
264
- await this.createElementsForUserDefinedResponses(history.messageHistory);
265
- this.serviceManager.mainWindow?.doAutoScroll({
266
- scrollToBottom: scrollBottom
267
- });
268
- }
269
- async receiveChunk(chunk, messageID, options = {}) {
270
- const chunkPromise = resolvablePromise();
271
- this.chunkQueue.push({
272
- chunk: chunk,
273
- messageID: messageID,
274
- options: options,
275
- chunkPromise: chunkPromise
276
- });
277
- if (this.chunkQueue.length === 1) {
278
- this.processChunkQueue();
279
- }
280
- return chunkPromise;
281
- }
282
- async processChunkQueue() {
283
- const {chunk: chunk, options: options, chunkPromise: chunkPromise} = this.chunkQueue[0];
284
- let {messageID: messageID} = this.chunkQueue[0];
285
- const isCompleteItem = isStreamCompleteItem(chunk);
286
- const isPartialItem = isStreamPartialItem(chunk);
287
- const {store: store} = this.serviceManager;
288
- const isStopGeneratingVisible = store.getState().botInputState.stopStreamingButtonState.isVisible;
289
- if (isPartialItem) {
290
- const streamingData = chunk.partial_item.streaming_metadata;
291
- if (streamingData.cancellable && !isStopGeneratingVisible) {
292
- store.dispatch(actions.setStopStreamingButtonVisible(true));
293
- }
294
- }
295
- if (isCompleteItem || isPartialItem) {
296
- if (!messageID) {
297
- messageID = chunk.streaming_metadata.response_id;
298
- }
299
- if (!store.getState().allMessagesByID[messageID]) {
300
- store.dispatch(actions.streamingStart(messageID));
301
- }
302
- const item = chunk.partial_item || chunk.complete_item;
303
- store.dispatch(actions.streamingAddChunk(messageID, item, isCompleteItem, options.disableFadeAnimation ?? true));
304
- if (chunk.partial_response?.history) {
305
- if (Object.keys(chunk.partial_response).length > 1) {
306
- throw new Error(`The partial_response object only supports the "history" property.`);
307
- }
308
- store.dispatch(actions.streamingMergeHistory(messageID, chunk.partial_response?.history));
309
- }
310
- await this.handleUserDefinedResponseItemsChunk(messageID, chunk, item);
311
- } else if (isStreamFinalResponse(chunk)) {
312
- this.receive(chunk.final_response, options.isLatestWelcomeNode, null, {
313
- disableFadeAnimation: true
314
- });
315
- }
316
- if ((isCompleteItem || isStreamFinalResponse(chunk)) && isStopGeneratingVisible) {
317
- store.dispatch(actions.setStopStreamingButtonDisabled(false));
318
- store.dispatch(actions.setStopStreamingButtonVisible(false));
319
- }
320
- this.chunkQueue.shift();
321
- chunkPromise.doResolve();
322
- if (this.chunkQueue[0]) {
323
- this.processChunkQueue();
324
- }
325
- }
326
- getOrCreateUserDefinedElement(messageItemID) {
327
- let userDefinedItem = this.serviceManager.userDefinedElementRegistry.get(messageItemID);
328
- if (!userDefinedItem) {
329
- userDefinedItem = {
330
- element: document.createElement("div"),
331
- slotName: `slot-user-defined-${uuid()}`
332
- };
333
- userDefinedItem.element.setAttribute("slot", userDefinedItem.slotName);
334
- this.serviceManager.userDefinedElementRegistry.set(messageItemID, userDefinedItem);
335
- }
336
- return userDefinedItem;
337
- }
338
- async handleUserDefinedResponseItems(localMessage, originalMessage) {
339
- if (renderAsUserDefinedMessage(localMessage.item)) {
340
- let element;
341
- let slotName;
342
- if (!localMessage.item.user_defined?.silent) {
343
- ({element: element, slotName: slotName} = this.getOrCreateUserDefinedElement(localMessage.ui_state.id));
344
- }
345
- const userDefinedResponseEvent = {
346
- type: BusEventType.USER_DEFINED_RESPONSE,
347
- data: {
348
- message: localMessage.item,
349
- fullMessage: originalMessage,
350
- element: element,
351
- slot: slotName,
352
- fullWidth: false
353
- }
354
- };
355
- await this.serviceManager.fire(userDefinedResponseEvent);
356
- if (userDefinedResponseEvent.data.fullWidth) {
357
- this.serviceManager.store.dispatch(actions.setMessageUIProperty(localMessage.ui_state.id, "fullWidth", true));
358
- }
359
- } else if (isResponseWithNestedItems(localMessage.item)) {
360
- const {itemsLocalMessageItemIDs: itemsLocalMessageItemIDs, bodyLocalMessageItemIDs: bodyLocalMessageItemIDs, footerLocalMessageItemIDs: footerLocalMessageItemIDs, gridLocalMessageItemIDs: gridLocalMessageItemIDs} = localMessage.ui_state;
361
- const {allMessageItemsByID: allMessageItemsByID} = this.serviceManager.store.getState();
362
- const createElementForNestedUserDefinedResponse = localMessageItemID => {
363
- const nestedLocalMessage = allMessageItemsByID[localMessageItemID];
364
- return this.handleUserDefinedResponseItems(nestedLocalMessage, originalMessage);
365
- };
366
- if (gridLocalMessageItemIDs?.length) {
367
- await asyncForEach(gridLocalMessageItemIDs, row => asyncForEach(row, cell => asyncForEach(cell, itemID => createElementForNestedUserDefinedResponse(itemID))));
368
- }
369
- if (itemsLocalMessageItemIDs?.length) {
370
- await asyncForEach(itemsLocalMessageItemIDs, createElementForNestedUserDefinedResponse);
371
- }
372
- if (bodyLocalMessageItemIDs?.length) {
373
- await asyncForEach(bodyLocalMessageItemIDs, createElementForNestedUserDefinedResponse);
374
- }
375
- if (footerLocalMessageItemIDs?.length) {
376
- await asyncForEach(footerLocalMessageItemIDs, createElementForNestedUserDefinedResponse);
377
- }
378
- }
379
- }
380
- async handleUserDefinedResponseItemsChunk(messageID, chunk, messageItem) {
381
- if (renderAsUserDefinedMessage(messageItem)) {
382
- const {store: store} = this.serviceManager;
383
- const itemID = streamItemID(messageID, messageItem);
384
- let element;
385
- let slotName;
386
- if (!messageItem.user_defined?.silent) {
387
- ({element: element, slotName: slotName} = this.getOrCreateUserDefinedElement(itemID));
388
- }
389
- const userDefinedResponseEvent = {
390
- type: BusEventType.CHUNK_USER_DEFINED_RESPONSE,
391
- data: {
392
- messageItem: messageItem,
393
- chunk: chunk,
394
- element: element,
395
- slot: slotName,
396
- fullWidth: false
397
- }
398
- };
399
- await this.serviceManager.fire(userDefinedResponseEvent);
400
- if (store.getState().allMessageItemsByID[itemID].ui_state.fullWidth !== userDefinedResponseEvent.data.fullWidth) {
401
- store.dispatch(actions.setMessageUIProperty(itemID, "fullWidth", userDefinedResponseEvent.data.fullWidth));
402
- }
403
- }
404
- }
405
- async processMessageResponse(fullMessage, isLatestWelcomeNode, requestMessage, requestOptions = {}) {
406
- const {store: store} = this.serviceManager;
407
- const {config: config} = store.getState();
408
- const initialRestartCount = this.serviceManager.restartCount;
409
- const output = fullMessage.output.generic;
410
- fullMessage.request_id = requestMessage?.id;
411
- addDefaultsToMessage(fullMessage);
412
- store.dispatch(actions.addMessage(fullMessage));
413
- let previousItemID = null;
414
- for (let index = 0; index < output.length && initialRestartCount === this.serviceManager.restartCount; index++) {
415
- const messageItem = output[index];
416
- if (messageItem) {
417
- const pause = isPause(messageItem);
418
- const agent = isConnectToAgent(messageItem);
419
- const tour = hasTourUserDefinedType(messageItem);
420
- const localMessageItem = outputItemToLocalItem(messageItem, fullMessage, isLatestWelcomeNode, requestOptions.disableFadeAnimation);
421
- if (tour && (requestOptions.skipTourCard || messageItem.user_defined?.skip_card)) {
422
- const startTourReason = requestOptions.skipTourCard ? TourStartReason.START_TOUR_METHOD : TourStartReason.SKIP_CARD;
423
- const {viewState: viewState} = store.getState().persistedToBrowserStorage.launcherState;
424
- if (viewState.mainWindow) {
425
- const mainWindowCloseReason = requestOptions.skipTourCard ? MainWindowCloseReason.CALLED_START_TOUR : MainWindowCloseReason.TOUR_SKIP_CARD;
426
- this.startTour(localMessageItem, startTourReason, {
427
- mainWindowCloseReason: mainWindowCloseReason
428
- }).catch(error => {
429
- consoleError("Error starting the tour", error);
430
- });
431
- } else {
432
- const viewChangeReason = requestOptions.skipTourCard ? ViewChangeReason.CALLED_START_TOUR : ViewChangeReason.TOUR_SKIP_CARD;
433
- this.startTour(localMessageItem, startTourReason, {
434
- viewChangeReason: viewChangeReason
435
- }).catch(error => {
436
- consoleError("Error starting the tour", error);
437
- });
438
- }
439
- } else if (!tour && requestOptions.skipTourCard) {
440
- consoleError("The message response received was not a tour, so the tour card was not skipped nor was a tour started by the startTour() call.");
441
- }
442
- const nestedLocalMessageItems = [];
443
- createLocalMessageItemsForNestedMessageItems(localMessageItem, fullMessage, false, nestedLocalMessageItems, true);
444
- store.dispatch(actions.addNestedMessages(nestedLocalMessageItems));
445
- if (agent && isResponse(fullMessage)) {
446
- store.dispatch(actions.addIsTypingCounter(1));
447
- if (!hasServiceDesk(config)) {
448
- const message = 'Web chat received a "connect_to_agent" message but there is no service desk configured. Check your chat configuration.';
449
- this.errorOccurred({
450
- errorType: OnErrorType.INTEGRATION_ERROR,
451
- message: message
452
- });
453
- store.dispatch(actions.setMessageHistoryProperty(localMessageItem.fullMessageID, "agent_no_service_desk", true));
454
- }
455
- const agentAvailability = await (this.serviceManager.humanAgentService?.checkAreAnyAgentsOnline(fullMessage));
456
- if (initialRestartCount === this.serviceManager.restartCount) {
457
- store.dispatch(actions.setMessageHistoryProperty(localMessageItem.fullMessageID, "agent_availability", agentAvailability));
458
- let shouldAutoRequestAgent = false;
459
- if (config.public.serviceDesk?.skipConnectAgentCard) {
460
- shouldAutoRequestAgent = true;
461
- }
462
- store.dispatch(actions.addIsTypingCounter(-1));
463
- if (shouldAutoRequestAgent && agentAvailability === AgentsOnlineStatus.ONLINE) {
464
- this.serviceManager.humanAgentService.startChat(localMessageItem, fullMessage);
465
- }
466
- }
467
- }
468
- if (pause) {
469
- const showIsTyping = isTyping(messageItem);
470
- if (showIsTyping) {
471
- store.dispatch(actions.addIsTypingCounter(1));
472
- }
473
- await sleep(messageItem.time);
474
- if (showIsTyping && initialRestartCount === this.serviceManager.restartCount) {
475
- store.dispatch(actions.addIsTypingCounter(-1));
476
- }
477
- } else {
478
- await this.handleUserDefinedResponseItems(localMessageItem, fullMessage);
479
- if (!localMessageItem.item.user_defined?.silent && initialRestartCount === this.serviceManager.restartCount) {
480
- this.serviceManager.store.dispatch(actions.addLocalMessageItem(localMessageItem, fullMessage, false, previousItemID));
481
- previousItemID = localMessageItem.ui_state.id;
482
- }
483
- }
484
- }
485
- }
486
- }
487
- openResponsePanel(localMessageItem, isMessageForInput) {
488
- this.serviceManager.store.dispatch(actions.setResponsePanelContent(localMessageItem, isMessageForInput));
489
- this.serviceManager.store.dispatch(actions.setResponsePanelIsOpen(true));
490
- }
491
- async insertLocalMessageResponse(message) {
492
- message.id = uuid(UUIDType.MESSAGE);
493
- await this.processMessageResponse(message, false, null, {});
494
- }
495
- updateLanguagePack(changes) {
496
- const {languagePack: languagePack, locale: locale} = this.serviceManager.store.getState();
497
- const messages = {
498
- ...languagePack,
499
- ...changes
500
- };
501
- setIntl(this.serviceManager, locale, messages);
502
- }
503
- addNotification(notification) {
504
- this.serviceManager.store.dispatch(actions.addNotification(notification));
505
- }
506
- removeNotification(groupID) {
507
- this.serviceManager.store.dispatch(actions.removeNotifications({
508
- groupID: groupID
509
- }));
510
- }
511
- removeAllNotifications() {
512
- this.serviceManager.store.dispatch(actions.removeAllNotifications());
513
- }
514
- updateCSSVariables(publicVars, whiteLabelVariables = {}) {
515
- const {store: store} = this.serviceManager;
516
- const {theme: theme} = store.getState();
517
- const {carbonTheme: carbonTheme, useAITheme: useAITheme} = theme;
518
- if (useAITheme) {
519
- const usePublicVars = publicVars;
520
- publicVars = {};
521
- whiteLabelVariables = {};
522
- usePublicVars && Object.entries(usePublicVars).forEach(([variable]) => {
523
- if (VALID_PUBLIC_VARS_IN_AI_THEME_SET.has(variable)) {
524
- publicVars[variable] = usePublicVars[variable];
525
- } else {
526
- consoleWarn(UPDATE_CSS_VARS_AI_THEME_WARNING_MESSAGE);
527
- }
528
- });
529
- } else {
530
- publicVars = {
531
- ...publicVars
532
- };
533
- whiteLabelVariables = {
534
- ...whiteLabelVariables
535
- };
536
- }
537
- const allVariables = mergeCSSVariables(publicVars, whiteLabelVariables, carbonTheme, useAITheme);
538
- store.dispatch(actions.updateCSSVariables(allVariables, publicVars, whiteLabelVariables));
539
- }
540
- updateBotName(name) {
541
- this.serviceManager.store.dispatch(actions.updateBotName(name));
542
- }
543
- updateMainHeaderTitle(title) {
544
- this.serviceManager.store.dispatch(actions.updateMainHeaderTitle(title));
545
- }
546
- updateBotAvatarURL(url) {
547
- this.serviceManager.store.dispatch(actions.updateBotAvatarURL(url));
548
- }
549
- updateHomeScreenConfig(homeScreenConfig) {
550
- this.serviceManager.store.dispatch(actions.updateHomeScreenConfig(homeScreenConfig));
551
- }
552
- updateLauncherConfig(launcherConfig) {
553
- this.serviceManager.store.dispatch(actions.updateLauncherConfig(launcherConfig));
554
- }
555
- async changeView(newView, reason, tryHydrating = true, forceViewChange = false) {
556
- const {store: store} = this.serviceManager;
557
- const {viewState: viewState} = store.getState().persistedToBrowserStorage.launcherState;
558
- let newViewState = constructViewState(newView, store.getState());
559
- if (!validateViewState(newViewState, store.getState())) {
560
- return viewState;
561
- }
562
- if (!isEqual(newViewState, viewState) || forceViewChange) {
563
- await this.fireViewChangeEventsAndChangeView(newViewState, reason);
564
- newViewState = store.getState().persistedToBrowserStorage.launcherState.viewState;
565
- if (tryHydrating && (newViewState.mainWindow || newViewState.tour) && !store.getState().isHydrated) {
566
- this.hydrateChat().catch(error => {
567
- consoleError("Error hydrating the chat", error);
568
- });
569
- }
570
- }
571
- return newViewState;
572
- }
573
- async fireViewChangeEventsAndChangeView(newViewState, reason) {
574
- const {store: store} = this.serviceManager;
575
- if (store.getState().viewChanging) {
576
- throw new Error("The view may not be changed while a view change event is already running. Please make sure to resolve any promises from these events.");
577
- }
578
- store.dispatch(actions.setViewChanging(true));
579
- const {viewState: viewState} = store.getState().persistedToBrowserStorage.launcherState;
580
- const {viewChangeReason: viewChangeReason} = reason;
581
- const oldViewState = deepFreeze(viewState);
582
- try {
583
- const preViewChangeEvent = {
584
- type: BusEventType.VIEW_PRE_CHANGE,
585
- reason: viewChangeReason,
586
- oldViewState: oldViewState,
587
- newViewState: newViewState,
588
- cancelViewChange: false
589
- };
590
- await this.serviceManager.fire(preViewChangeEvent);
591
- if (preViewChangeEvent.cancelViewChange) {
592
- debugLog("The view changing was cancelled by a view:pre:change event.");
593
- return;
594
- }
595
- if (!validateViewState(preViewChangeEvent.newViewState, store.getState())) {
596
- return;
597
- }
598
- newViewState = preViewChangeEvent.newViewState;
599
- store.dispatch(actions.setViewState(deepFreeze(newViewState)));
600
- const viewChangeEvent = {
601
- type: BusEventType.VIEW_CHANGE,
602
- reason: viewChangeReason,
603
- oldViewState: oldViewState,
604
- newViewState: newViewState,
605
- cancelViewChange: false
606
- };
607
- await this.serviceManager.fire(viewChangeEvent);
608
- if (viewChangeEvent.cancelViewChange) {
609
- store.dispatch(actions.setViewState(oldViewState));
610
- debugLog("The view changing was cancelled by a view:change event.");
611
- return;
612
- }
613
- if (!validateViewState(viewChangeEvent.newViewState, store.getState())) {
614
- store.dispatch(actions.setViewState(oldViewState));
615
- return;
616
- }
617
- newViewState = viewChangeEvent.newViewState;
618
- store.dispatch(actions.setViewState(deepFreeze(newViewState)));
619
- } finally {
620
- store.dispatch(actions.setViewChanging(false));
621
- }
622
- }
623
- async startTour(message, startTourReason, changeViewReason) {
624
- this.serviceManager.store.dispatch(actions.setTourData(message.fullMessageID));
625
- const newViewState = await this.changeView(ViewType.TOUR, changeViewReason);
626
- if (newViewState.tour) {
627
- await this.serviceManager.fire({
628
- type: BusEventType.TOUR_START,
629
- reason: startTourReason
630
- });
631
- await this.serviceManager.fire({
632
- type: BusEventType.TOUR_STEP,
633
- step: this.serviceManager.store.getState().tourState.activeTourStepItems[0]
634
- });
635
- }
636
- }
637
- async endTour(reason) {
638
- const {viewState: viewState} = this.serviceManager.store.getState().persistedToBrowserStorage.launcherState;
639
- let newViewState = viewState;
640
- if (viewState.tour) {
641
- newViewState = await this.changeView(ViewType.LAUNCHER, reason);
642
- }
643
- if (!newViewState.tour) {
644
- this.serviceManager.store.dispatch(actions.clearTourData());
645
- return true;
646
- }
647
- return false;
648
- }
649
- goToSpecificTourStep(stepId) {
650
- const {activeTourStepItems: activeTourStepItems} = this.serviceManager.store.getState().tourState;
651
- const newStepIndex = activeTourStepItems.findIndex(stepItem => stepItem.step_id === stepId);
652
- if (newStepIndex) {
653
- this.changeStepInTour({
654
- newStepIndex: newStepIndex
655
- });
656
- } else {
657
- consoleError(`No step with the id "${stepId}" was found within the current tour. As a result, goToTourStep() did not change the current tour step.`);
658
- }
659
- }
660
- async changeStepInTour(changeStepOptions) {
661
- const {store: store} = this.serviceManager;
662
- const {activeTourStepItems: activeTourStepItems} = store.getState().tourState;
663
- const {activeTourCurrentStepIndex: activeTourCurrentStepIndex} = store.getState().persistedToBrowserStorage.chatState.persistedTourState;
664
- let {newStepIndex: newStepIndex} = changeStepOptions;
665
- if (changeStepOptions.nextStep) {
666
- newStepIndex = activeTourCurrentStepIndex + 1;
667
- } else if (changeStepOptions.previousStep) {
668
- newStepIndex = activeTourCurrentStepIndex - 1;
669
- }
670
- store.dispatch(actions.changeStepInTour(newStepIndex));
671
- const actualNewStepIndex = store.getState().persistedToBrowserStorage.chatState.persistedTourState.activeTourCurrentStepIndex;
672
- if (actualNewStepIndex === newStepIndex) {
673
- await this.serviceManager.fire({
674
- type: BusEventType.TOUR_STEP,
675
- step: activeTourStepItems[actualNewStepIndex]
676
- });
677
- } else {
678
- consoleWarn("The tour tried to change to a step that was out of bounds for the step array, so no step change was made.");
679
- }
680
- }
681
- errorOccurred(error) {
682
- consoleError("An error has occurred", error);
683
- if (error.catastrophicErrorType) {
684
- this.serviceManager.store.dispatch(actions.setAppStateValue("catastrophicErrorType", error.catastrophicErrorType));
685
- }
686
- callOnError(this.serviceManager.additionalChatParameters.onError, error);
687
- }
688
- async restartConversation(options = {}) {
689
- const {skipHydration: skipHydration = false, endAgentConversation: endAgentConversation = true, fireEvents: fireEvents = true} = options;
690
- debugLog("Restarting conversation");
691
- if (this.restarting) {
692
- consoleWarn("You cannot restart a conversation while a previous restart is still pending.");
693
- return;
694
- }
695
- this.restarting = true;
696
- try {
697
- const {serviceManager: serviceManager} = this;
698
- const {store: store} = serviceManager;
699
- if (fireEvents) {
700
- await serviceManager.fire({
701
- type: BusEventType.PRE_RESTART_CONVERSATION
702
- });
703
- }
704
- serviceManager.restartCount++;
705
- if (this.hydrating) {
706
- await this.hydrationPromise;
707
- }
708
- const currentState = store.getState();
709
- const {persistedToBrowserStorage: persistedToBrowserStorage} = currentState;
710
- const {viewState: viewState} = persistedToBrowserStorage.launcherState;
711
- const {isConnecting: isConnecting} = currentState.agentState;
712
- const {isConnected: isConnected} = currentState.persistedToBrowserStorage.chatState.agentState;
713
- if ((isConnected || isConnecting) && endAgentConversation) {
714
- await serviceManager.humanAgentService.endChat(true, false, false);
715
- }
716
- if (viewState.tour) {
717
- await this.serviceManager.actions.changeView(ViewType.MAIN_WINDOW, {
718
- mainWindowOpenReason: MainWindowOpenReason.CALLED_RESTART_CONVERSATION
719
- }, false);
720
- }
721
- this.serviceManager.instance.updateAssistantInputFieldVisibility(true);
722
- this.serviceManager.messageService.cancelAllMessageRequests();
723
- store.dispatch(actions.restartConversation());
724
- if (!skipHydration) {
725
- this.hydrationPromise = null;
726
- }
727
- if (fireEvents) {
728
- await serviceManager.fire({
729
- type: BusEventType.RESTART_CONVERSATION
730
- });
731
- }
732
- if (this.hydrating) {
733
- await this.hydrationPromise;
734
- }
735
- if (!skipHydration && !serviceManager.store.getState().isHydrated) {
736
- this.hydrationPromise = null;
737
- if (store.getState().persistedToBrowserStorage.launcherState.viewState.mainWindow) {
738
- await serviceManager.actions.hydrateChat();
739
- }
740
- } else {
741
- store.dispatch(actions.chatWasHydrated());
742
- }
743
- } finally {
744
- this.restarting = false;
745
- }
746
- }
747
- async destroySession(keepOpenState) {
748
- const {store: store} = this.serviceManager;
749
- const {persistedToBrowserStorage: persistedToBrowserStorage} = store.getState();
750
- const originalViewState = persistedToBrowserStorage.launcherState.viewState;
751
- const newPersistedToBrowserStorage = cloneDeep(DEFAULT_PERSISTED_TO_BROWSER);
752
- if (keepOpenState) {
753
- newPersistedToBrowserStorage.launcherState.viewState = originalViewState;
754
- if (originalViewState.tour) {
755
- newPersistedToBrowserStorage.launcherState.viewState = {
756
- ...originalViewState,
757
- tour: false,
758
- mainWindow: true
759
- };
760
- }
761
- } else {
762
- newPersistedToBrowserStorage.launcherState.viewState = VIEW_STATE_LAUNCHER_OPEN;
763
- }
764
- this.serviceManager.messageService.cancelAllMessageRequests();
765
- this.serviceManager.userSessionStorageService.clearLauncherSession();
766
- this.serviceManager.userSessionStorageService.clearChatSession();
767
- this.serviceManager.store.dispatch(actions.setAppStateValue("persistedToBrowserStorage", newPersistedToBrowserStorage));
768
- }
769
- agentEndConversation(endedByUser) {
770
- return this.serviceManager.humanAgentService.endChat(endedByUser);
771
- }
772
- agentUpdateIsSuspended(isSuspended) {
773
- this.serviceManager.store.dispatch(agentUpdateIsSuspended(isSuspended));
774
- }
775
- async createElementsForUserDefinedResponses(messages) {
776
- await asyncForEach(Object.values(messages.allMessageItemsByID), localMessage => {
777
- const originalMessage = messages.allMessagesByID[localMessage.fullMessageID];
778
- return this.handleUserDefinedResponseItems(localMessage, originalMessage);
779
- });
780
- }
781
- }
782
-
783
- export { ChatActionsImpl };