@cometchat/chat-uikit-react-native 5.1.1 → 5.2.0

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 (227) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  3. package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.d.ts +40 -0
  4. package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.js +467 -0
  5. package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.js.map +1 -0
  6. package/lib/CometChatAIAssistantChatHistory/Skeleton.d.ts +24 -0
  7. package/lib/CometChatAIAssistantChatHistory/Skeleton.js +130 -0
  8. package/lib/CometChatAIAssistantChatHistory/Skeleton.js.map +1 -0
  9. package/lib/CometChatAIAssistantChatHistory/index.d.ts +1 -0
  10. package/lib/CometChatAIAssistantChatHistory/index.js +2 -0
  11. package/lib/CometChatAIAssistantChatHistory/index.js.map +1 -0
  12. package/lib/CometChatAIAssistantChatHistory/style.d.ts +30 -0
  13. package/lib/CometChatAIAssistantChatHistory/style.js +122 -0
  14. package/lib/CometChatAIAssistantChatHistory/style.js.map +1 -0
  15. package/lib/CometChatConversations/CometChatConversations.js +26 -5
  16. package/lib/CometChatConversations/CometChatConversations.js.map +1 -1
  17. package/lib/CometChatMessageComposer/CometChatMessageComposer.d.ts +7 -0
  18. package/lib/CometChatMessageComposer/CometChatMessageComposer.js +101 -13
  19. package/lib/CometChatMessageComposer/CometChatMessageComposer.js.map +1 -1
  20. package/lib/CometChatMessageHeader/CometChatMessageHeader.d.ts +16 -0
  21. package/lib/CometChatMessageHeader/CometChatMessageHeader.js +63 -13
  22. package/lib/CometChatMessageHeader/CometChatMessageHeader.js.map +1 -1
  23. package/lib/CometChatMessageList/CometChatMessageList.d.ts +33 -0
  24. package/lib/CometChatMessageList/CometChatMessageList.js +535 -76
  25. package/lib/CometChatMessageList/CometChatMessageList.js.map +1 -1
  26. package/lib/CometChatMessageList/style.js +74 -2
  27. package/lib/CometChatMessageList/style.js.map +1 -1
  28. package/lib/calls/CometChatIncomingCall/CometChatIncomingCall.js +6 -12
  29. package/lib/calls/CometChatIncomingCall/CometChatIncomingCall.js.map +1 -1
  30. package/lib/calls/CometChatOutgoingCall/CometChatOutgoingCall.js +4 -3
  31. package/lib/calls/CometChatOutgoingCall/CometChatOutgoingCall.js.map +1 -1
  32. package/lib/extensions/Polls/Polls.js +38 -17
  33. package/lib/extensions/Polls/Polls.js.map +1 -1
  34. package/lib/index.d.ts +5 -1
  35. package/lib/index.js +6 -2
  36. package/lib/index.js.map +1 -1
  37. package/lib/shared/constants/UIKitConstants.d.ts +16 -0
  38. package/lib/shared/constants/UIKitConstants.js +16 -0
  39. package/lib/shared/constants/UIKitConstants.js.map +1 -1
  40. package/lib/shared/events/CometChatMessageEvents/index.d.ts +3 -0
  41. package/lib/shared/events/CometChatMessageEvents/index.js +3 -0
  42. package/lib/shared/events/CometChatMessageEvents/index.js.map +1 -1
  43. package/lib/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.js +3 -0
  44. package/lib/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.js.map +1 -1
  45. package/lib/shared/events/CometChatUIEventHandler/Listener.d.ts +3 -1
  46. package/lib/shared/events/CometChatUIEventHandler/Listener.js +4 -1
  47. package/lib/shared/events/CometChatUIEventHandler/Listener.js.map +1 -1
  48. package/lib/shared/events/ListenerInitializer.d.ts +3 -1
  49. package/lib/shared/events/ListenerInitializer.js +5 -1
  50. package/lib/shared/events/ListenerInitializer.js.map +1 -1
  51. package/lib/shared/events/messages.d.ts +2 -1
  52. package/lib/shared/events/messages.js +1 -0
  53. package/lib/shared/events/messages.js.map +1 -1
  54. package/lib/shared/framework/DataSource.d.ts +3 -1
  55. package/lib/shared/framework/DataSourceDecorator.d.ts +3 -1
  56. package/lib/shared/framework/DataSourceDecorator.js +8 -2
  57. package/lib/shared/framework/DataSourceDecorator.js.map +1 -1
  58. package/lib/shared/framework/MessageDataSource.d.ts +6 -0
  59. package/lib/shared/framework/MessageDataSource.js +64 -1
  60. package/lib/shared/framework/MessageDataSource.js.map +1 -1
  61. package/lib/shared/icons/components/ai-chat-history.d.ts +8 -0
  62. package/lib/shared/icons/components/ai-chat-history.js +9 -0
  63. package/lib/shared/icons/components/ai-chat-history.js.map +1 -0
  64. package/lib/shared/icons/components/ai-copy-option.d.ts +8 -0
  65. package/lib/shared/icons/components/ai-copy-option.js +9 -0
  66. package/lib/shared/icons/components/ai-copy-option.js.map +1 -0
  67. package/lib/shared/icons/components/ai-new-chat.d.ts +8 -0
  68. package/lib/shared/icons/components/ai-new-chat.js +9 -0
  69. package/lib/shared/icons/components/ai-new-chat.js.map +1 -0
  70. package/lib/shared/icons/components/ai-send-button.d.ts +8 -0
  71. package/lib/shared/icons/components/ai-send-button.js +9 -0
  72. package/lib/shared/icons/components/ai-send-button.js.map +1 -0
  73. package/lib/shared/icons/components/right-arrow.d.ts +3 -0
  74. package/lib/shared/icons/components/right-arrow.js +6 -0
  75. package/lib/shared/icons/components/right-arrow.js.map +1 -0
  76. package/lib/shared/icons/components/stop-fill.js +8 -7
  77. package/lib/shared/icons/components/stop-fill.js.map +1 -1
  78. package/lib/shared/icons/icon-mapping.d.ts +11 -0
  79. package/lib/shared/icons/icon-mapping.js +11 -0
  80. package/lib/shared/icons/icon-mapping.js.map +1 -1
  81. package/lib/shared/modals/CometChatAIAssistantTools.d.ts +47 -0
  82. package/lib/shared/modals/CometChatAIAssistantTools.js +44 -0
  83. package/lib/shared/modals/CometChatAIAssistantTools.js.map +1 -0
  84. package/lib/shared/modals/StreamMessage.d.ts +4 -0
  85. package/lib/shared/modals/StreamMessage.js +11 -0
  86. package/lib/shared/modals/StreamMessage.js.map +1 -0
  87. package/lib/shared/modals/index.d.ts +3 -1
  88. package/lib/shared/modals/index.js +3 -1
  89. package/lib/shared/modals/index.js.map +1 -1
  90. package/lib/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.d.ts +126 -0
  91. package/lib/shared/resources/CometChatLocalizeNew/resources/de/translation.json +7 -1
  92. package/lib/shared/resources/CometChatLocalizeNew/resources/en/translation.json +7 -1
  93. package/lib/shared/resources/CometChatLocalizeNew/resources/es/translation.json +7 -1
  94. package/lib/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +7 -1
  95. package/lib/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +7 -1
  96. package/lib/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +7 -1
  97. package/lib/shared/resources/CometChatLocalizeNew/resources/it/translation.json +7 -1
  98. package/lib/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +7 -1
  99. package/lib/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +7 -1
  100. package/lib/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +7 -1
  101. package/lib/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +7 -1
  102. package/lib/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +7 -1
  103. package/lib/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +7 -1
  104. package/lib/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +7 -1
  105. package/lib/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +7 -1
  106. package/lib/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +7 -1
  107. package/lib/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +7 -1
  108. package/lib/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +7 -1
  109. package/lib/shared/services/stream-message.service.d.ts +84 -0
  110. package/lib/shared/services/stream-message.service.js +406 -0
  111. package/lib/shared/services/stream-message.service.js.map +1 -0
  112. package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.d.ts +9 -0
  113. package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.js +248 -0
  114. package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.js.map +1 -0
  115. package/lib/shared/views/CometChatAIAssistantMessageBubble/index.d.ts +3 -0
  116. package/lib/shared/views/CometChatAIAssistantMessageBubble/index.js +4 -0
  117. package/lib/shared/views/CometChatAIAssistantMessageBubble/index.js.map +1 -0
  118. package/lib/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.js +5 -2
  119. package/lib/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.js.map +1 -1
  120. package/lib/shared/views/CometChatImageBubble/CometChatImageLoader.js +1 -1
  121. package/lib/shared/views/CometChatImageBubble/CometChatImageLoader.js.map +1 -1
  122. package/lib/shared/views/CometChatImageViewerModal/ImageViewerModal.js +52 -32
  123. package/lib/shared/views/CometChatImageViewerModal/ImageViewerModal.js.map +1 -1
  124. package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.d.ts +10 -0
  125. package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.js +54 -0
  126. package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.js.map +1 -0
  127. package/lib/shared/views/CometChatSendButtonView/index.d.ts +1 -0
  128. package/lib/shared/views/CometChatSendButtonView/index.js +2 -0
  129. package/lib/shared/views/CometChatSendButtonView/index.js.map +1 -0
  130. package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.d.ts +8 -0
  131. package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.js +436 -0
  132. package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.js.map +1 -0
  133. package/lib/shared/views/CometChatStreamMessageBubble/index.d.ts +3 -0
  134. package/lib/shared/views/CometChatStreamMessageBubble/index.js +3 -0
  135. package/lib/shared/views/CometChatStreamMessageBubble/index.js.map +1 -0
  136. package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.d.ts +14 -6
  137. package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.js +82 -57
  138. package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.js.map +1 -1
  139. package/lib/theme/context.d.ts +96 -15
  140. package/lib/theme/type.d.ts +14 -1
  141. package/package.json +6 -3
  142. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +627 -0
  143. package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +228 -0
  144. package/src/CometChatAIAssistantChatHistory/index.ts +2 -0
  145. package/src/CometChatAIAssistantChatHistory/style.ts +160 -0
  146. package/src/CometChatConversations/CometChatConversations.tsx +36 -10
  147. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +137 -19
  148. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +106 -18
  149. package/src/CometChatMessageList/CometChatMessageList.tsx +721 -116
  150. package/src/CometChatMessageList/style.ts +74 -2
  151. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +13 -29
  152. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +8 -5
  153. package/src/extensions/Polls/Polls.tsx +50 -22
  154. package/src/index.ts +31 -1
  155. package/src/shared/constants/UIKitConstants.ts +17 -0
  156. package/src/shared/events/CometChatMessageEvents/index.ts +3 -1
  157. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +3 -0
  158. package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -0
  159. package/src/shared/events/ListenerInitializer.ts +6 -1
  160. package/src/shared/events/messages.ts +1 -0
  161. package/src/shared/framework/DataSource.ts +4 -2
  162. package/src/shared/framework/DataSourceDecorator.tsx +10 -2
  163. package/src/shared/framework/MessageDataSource.tsx +75 -2
  164. package/src/shared/icons/Icon.tsx +1 -1
  165. package/src/shared/icons/components/ai-chat-history.tsx +21 -0
  166. package/src/shared/icons/components/ai-copy-option.tsx +21 -0
  167. package/src/shared/icons/components/ai-new-chat.tsx +21 -0
  168. package/src/shared/icons/components/ai-send-button.tsx +24 -0
  169. package/src/shared/icons/components/right-arrow.tsx +13 -0
  170. package/src/shared/icons/components/stop-fill.tsx +14 -12
  171. package/src/shared/icons/icon-mapping.tsx +14 -0
  172. package/src/shared/modals/CometChatAIAssistantTools.ts +65 -0
  173. package/src/shared/modals/StreamMessage.ts +12 -0
  174. package/src/shared/modals/index.ts +5 -1
  175. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +7 -1
  176. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +7 -1
  177. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +7 -1
  178. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +7 -1
  179. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +7 -2
  180. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +7 -1
  181. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +7 -1
  182. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +7 -1
  183. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +7 -1
  184. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +7 -1
  185. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +7 -1
  186. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +7 -1
  187. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +7 -1
  188. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +7 -1
  189. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +7 -1
  190. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +7 -1
  191. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +7 -1
  192. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +7 -1
  193. package/src/shared/services/stream-message.service.ts +470 -0
  194. package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +262 -0
  195. package/src/shared/views/CometChatAIAssistantMessageBubble/index.ts +4 -0
  196. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -1
  197. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +1 -0
  198. package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +57 -45
  199. package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +86 -0
  200. package/src/shared/views/CometChatSendButtonView/index.ts +1 -0
  201. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +493 -0
  202. package/src/shared/views/CometChatStreamMessageBubble/index.ts +9 -0
  203. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +121 -74
  204. package/src/theme/type.ts +14 -1
  205. package/lib/shared/resources/CometChatLocalize/CometChatLocalize.d.ts +0 -79
  206. package/lib/shared/resources/CometChatLocalize/CometChatLocalize.js +0 -152
  207. package/lib/shared/resources/CometChatLocalize/CometChatLocalize.js.map +0 -1
  208. package/lib/shared/resources/CometChatLocalize/index.d.ts +0 -2
  209. package/lib/shared/resources/CometChatLocalize/index.js +0 -3
  210. package/lib/shared/resources/CometChatLocalize/index.js.map +0 -1
  211. package/lib/shared/resources/CometChatLocalize/resources/ar/translation.json +0 -447
  212. package/lib/shared/resources/CometChatLocalize/resources/de/translation.json +0 -447
  213. package/lib/shared/resources/CometChatLocalize/resources/en/translation.json +0 -447
  214. package/lib/shared/resources/CometChatLocalize/resources/es/translation.json +0 -447
  215. package/lib/shared/resources/CometChatLocalize/resources/fr/translation.json +0 -446
  216. package/lib/shared/resources/CometChatLocalize/resources/hi/translation.json +0 -447
  217. package/lib/shared/resources/CometChatLocalize/resources/hu/translation.json +0 -447
  218. package/lib/shared/resources/CometChatLocalize/resources/lt/translation.json +0 -447
  219. package/lib/shared/resources/CometChatLocalize/resources/ms/translation.json +0 -447
  220. package/lib/shared/resources/CometChatLocalize/resources/pt/translation.json +0 -447
  221. package/lib/shared/resources/CometChatLocalize/resources/ru/translation.json +0 -447
  222. package/lib/shared/resources/CometChatLocalize/resources/sv/translation.json +0 -447
  223. package/lib/shared/resources/CometChatLocalize/resources/zh/translation.json +0 -447
  224. package/lib/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +0 -446
  225. package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.d.ts +0 -29
  226. package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js +0 -29
  227. package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js.map +0 -1
@@ -28,10 +28,28 @@ import { ExtensionConstants } from "../extensions";
28
28
  //@ts-ignore
29
29
  import { getExtensionData } from "../shared/helper/functions";
30
30
  import { CometChatDateSeparator } from "../shared/views/CometChatDateSeperator";
31
+ import { handleWebsocketMessage, setAIAssistantTools, setStreamSpeed, setQueueCompletionCallback, onConnected as streamOnConnected, onDisconnected as streamOnDisconnected, checkAndTriggerQueueCompletion, storeAIAssistantMessage } from "../shared/services/stream-message.service";
32
+ import { StreamMessage } from "../shared/modals";
33
+ import { internalMessageDataSource } from "../shared/framework/MessageDataSource";
31
34
  import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
32
35
  let _defaultRequestBuilder;
33
36
  export const CometChatMessageList = memo(forwardRef((props, ref) => {
34
- const { parentMessageId, user, group, EmptyView, ErrorView, hideError, LoadingView, receiptsVisibility = true, disableSoundForMessages, customSoundForMessages, alignment = "standard", avatarVisibility = true, datePattern, dateSeparatorPattern, templates = [], messageRequestBuilder, scrollToBottomOnNewMessages = false, onThreadRepliesPress, HeaderView, FooterView, onError, onBack, reactionsRequestBuilder, textFormatters, onReactionPress: onReactionPressFromProp, onReactionLongPress: onReactionLongPressFromProp, onReactionListItemPress: onReactionListItemPressProp, style, onAddReactionPress, quickReactionList, addTemplates = [], onLoad, onEmpty, hideReplyInThreadOption = false, hideShareMessageOption = false, hideEditMessageOption = false, hideTranslateMessageOption = false, hideDeleteMessageOption = false, hideReactionOption = false, hideMessagePrivatelyOption = false, hideCopyMessageOption = false, hideMessageInfoOption = false, hideGroupActionMessages = false, hideTimestamp = false, } = props;
37
+ const { parentMessageId, user, group, EmptyView, ErrorView, hideError, LoadingView, receiptsVisibility = true, disableSoundForMessages, customSoundForMessages, alignment = "standard", avatarVisibility = true, datePattern, dateSeparatorPattern, templates = [], messageRequestBuilder, scrollToBottomOnNewMessages = false, onThreadRepliesPress, HeaderView, FooterView, onError, onBack, reactionsRequestBuilder, textFormatters, onReactionPress: onReactionPressFromProp, onReactionLongPress: onReactionLongPressFromProp, onReactionListItemPress: onReactionListItemPressProp, style, onAddReactionPress, quickReactionList, addTemplates = [], onLoad, onEmpty, hideReplyInThreadOption: propHideReplyInThreadOption = false, hideShareMessageOption: propHideShareMessageOption = false, hideEditMessageOption: propHideEditMessageOption = false, hideTranslateMessageOption: propHideTranslateMessageOption = false, hideDeleteMessageOption: propHideDeleteMessageOption = false, hideReactionOption: propHideReactionOption = false, hideMessagePrivatelyOption: propHideMessagePrivatelyOption = false, hideCopyMessageOption: propHideCopyMessageOption = false, hideMessageInfoOption: propHideMessageInfoOption = false, hideGroupActionMessages: propHideGroupActionMessages = false, hideTimestamp = false, suggestedMessages = [], hideSuggestedMessages = false, emptyChatGreetingView, emptyChatIntroMessageView, emptyChatImageView, onSuggestedMessageClick, aiAssistantTools, streamingSpeed = 30 } = props;
38
+ // Helper function to check if user is agentic
39
+ const isAgenticUser = useCallback(() => {
40
+ return user?.getRole?.() === '@agentic';
41
+ }, [user]);
42
+ // hiding props for @agentic users
43
+ const hideReplyInThreadOption = isAgenticUser() ? true : propHideReplyInThreadOption;
44
+ const hideShareMessageOption = isAgenticUser() ? true : propHideShareMessageOption;
45
+ const hideEditMessageOption = isAgenticUser() ? true : propHideEditMessageOption;
46
+ const hideTranslateMessageOption = isAgenticUser() ? true : propHideTranslateMessageOption;
47
+ const hideDeleteMessageOption = isAgenticUser() ? true : propHideDeleteMessageOption;
48
+ const hideReactionOption = isAgenticUser() ? true : propHideReactionOption;
49
+ const hideMessagePrivatelyOption = isAgenticUser() ? true : propHideMessagePrivatelyOption;
50
+ const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
51
+ const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
52
+ const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
35
53
  const callListenerId = "call_" + new Date().getTime();
36
54
  const groupListenerId = "group_" + new Date().getTime();
37
55
  const uiEventListener = "uiEvent_" + new Date().getTime();
@@ -41,9 +59,14 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
41
59
  const connectionListenerId = "connectionListener_" + new Date().getTime();
42
60
  const messageEventListener = "messageEvent_" + new Date().getTime();
43
61
  const groupEventListener = "groupEvent_" + new Date().getTime();
44
- const [showDeleteModal, setShowDeleteModal] = useState(false);
62
+ const streamListenerId = "agent_" + new Date().getTime();
45
63
  const deleteItem = useRef(undefined);
46
64
  useLayoutEffect(() => {
65
+ // For agent chats (non-thread), don't set up message request builder
66
+ if (isAgenticUser() && !parentMessageId) {
67
+ msgRequestBuilder.current = null;
68
+ return;
69
+ }
47
70
  if (user) {
48
71
  _defaultRequestBuilder = new CometChat.MessagesRequestBuilder()
49
72
  .setLimit(30)
@@ -73,8 +96,13 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
73
96
  _updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setUID(user.getUid());
74
97
  if (group)
75
98
  _updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setGUID(group.getGuid());
76
- if (parentMessageId)
99
+ if (parentMessageId) {
77
100
  _updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setParentMessageId(parseInt(parentMessageId));
101
+ if (isAgenticUser()) {
102
+ _updatedCustomRequestBuilder.hideReplies(false);
103
+ _updatedCustomRequestBuilder.withParent(true);
104
+ }
105
+ }
78
106
  let types = [], categories = [];
79
107
  if (templates.length) {
80
108
  types = templates.map((template) => template.type);
@@ -95,7 +123,7 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
95
123
  _updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setCategories(categories);
96
124
  }
97
125
  msgRequestBuilder.current = _updatedCustomRequestBuilder;
98
- }, [hideGroupActionMessages]);
126
+ }, [hideGroupActionMessages, isAgenticUser, parentMessageId]);
99
127
  const theme = useTheme();
100
128
  const { t } = useCometChatTranslation();
101
129
  const mergedTheme = useMemo(() => {
@@ -159,6 +187,18 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
159
187
  incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.linkPreviewBubbleStyles ?? {}),
160
188
  outgoing: deepMerge(outgoingBubbleStyles, outgoingBubbleStyles.linkPreviewBubbleStyles ?? {}),
161
189
  });
190
+ styleCache.set(MessageTypeConstants.assistant, {
191
+ incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
192
+ });
193
+ styleCache.set(CometChatUiKitConstants.streamMessageTypes.run_started, {
194
+ incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
195
+ });
196
+ styleCache.set(CometChatUiKitConstants.streamMessageTypes.run_finished, {
197
+ incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
198
+ });
199
+ styleCache.set(CometChatUiKitConstants.streamMessageTypes.text_message_content, {
200
+ incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
201
+ });
162
202
  return styleCache;
163
203
  }, [mergedTheme]);
164
204
  // refs
@@ -179,7 +219,7 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
179
219
  const lastMessageDate = useRef(new Date().getTime());
180
220
  // states
181
221
  const [messagesList, setMessagesList] = useState([]);
182
- const [listState, setListState] = useState("loading");
222
+ const [listState, setListState] = useState(isAgenticUser() && !parentMessageId ? "loaded" : "loading");
183
223
  const [loadingMessages, setLoadingMessages] = useState(false);
184
224
  /** this is required to prevent duplicate api calls. Cannot use state for this since this is being used in scrollHandler **/
185
225
  const loadingMessagesRef = useRef(false);
@@ -194,11 +234,14 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
194
234
  const [showReactionList, setShowReactionList] = useState(false);
195
235
  const [selectedEmoji, setSelectedEmoji] = useState(undefined);
196
236
  const [hideScrollToBottomButton, setHideScrollToBottomButton] = useState(true);
237
+ const [showDeleteModal, setShowDeleteModal] = useState(false);
197
238
  const infoObject = useRef(undefined);
198
239
  const bottomSheetRef = useRef(null);
199
240
  const conversationId = useRef(null);
241
+ const streamSubscriptionRef = useRef(null);
200
242
  let lastID = useRef(0);
201
243
  let reachedFirstMessage = useRef(false);
244
+ const agenticParentMessageIdRef = useRef(undefined);
202
245
  const markUnreadMessageAsRead = () => {
203
246
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
204
247
  message: messagesContentListRef.current[0],
@@ -218,6 +261,10 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
218
261
  markUnreadMessageAsRead();
219
262
  }, [onLoad]);
220
263
  const getPreviousMessages = async () => {
264
+ // For agent chats (non-thread), don't fetch previous messages
265
+ if (isAgenticUser() && !parentMessageId) {
266
+ return;
267
+ }
221
268
  if (reachedFirstMessage.current) {
222
269
  return;
223
270
  }
@@ -314,6 +361,10 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
314
361
  });
315
362
  };
316
363
  const getUpdatedPreviousMessages = () => {
364
+ // For agent chats (non-thread), don't fetch updated previous messages
365
+ if (isAgenticUser() && !parentMessageId) {
366
+ return;
367
+ }
317
368
  let messagesRequest = new CometChat.MessagesRequestBuilder().setLimit(50);
318
369
  if (user)
319
370
  messagesRequest = messagesRequest.setUID(user.getUid());
@@ -397,25 +448,32 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
397
448
  .catch((e) => console.log("error while fetching updated msgs", e));
398
449
  };
399
450
  const templatesMap = useMemo(() => {
451
+ const isAgenticUserCheck = isAgenticUser();
452
+ const options = {
453
+ textFormatters: textFormatters || [],
454
+ hideReplyInThreadOption: isAgenticUserCheck || hideReplyInThreadOption,
455
+ hideShareMessageOption: isAgenticUserCheck || hideShareMessageOption,
456
+ hideEditMessageOption: isAgenticUserCheck || hideEditMessageOption,
457
+ hideTranslateMessageOption: isAgenticUserCheck || hideTranslateMessageOption,
458
+ hideDeleteMessageOption: isAgenticUserCheck || hideDeleteMessageOption,
459
+ hideReactionOption: isAgenticUserCheck || hideReactionOption,
460
+ hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
461
+ hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
462
+ hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
463
+ hideGroupActionMessages,
464
+ };
400
465
  let _formatters = textFormatters || [];
401
466
  let tempTemplates = templates && templates.length
402
467
  ? templates
403
468
  : [
404
- ...ChatConfigurator.dataSource.getAllMessageTemplates(mergedTheme, {
405
- textFormatters: _formatters,
406
- hideReplyInThreadOption,
407
- hideShareMessageOption,
408
- hideEditMessageOption,
409
- hideTranslateMessageOption,
410
- hideDeleteMessageOption,
411
- hideReactionOption,
412
- hideMessagePrivatelyOption,
413
- hideCopyMessageOption,
414
- hideMessageInfoOption,
415
- hideGroupActionMessages,
416
- }),
469
+ ...ChatConfigurator.dataSource.getAllMessageTemplates(mergedTheme, options),
417
470
  ...addTemplates,
418
471
  ];
472
+ //for internal use only
473
+ const streamTemplate = internalMessageDataSource.getStreamMessageTemplate(mergedTheme, options);
474
+ if (isAgenticUserCheck) {
475
+ tempTemplates.push(streamTemplate);
476
+ }
419
477
  let templatesMapTemp = new Map();
420
478
  tempTemplates.forEach((template) => {
421
479
  if (hideGroupActionMessages && template.type === MessageTypeConstants.groupMember)
@@ -429,6 +487,7 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
429
487
  mergedTheme,
430
488
  templates,
431
489
  addTemplates,
490
+ isAgenticUser,
432
491
  hideReplyInThreadOption,
433
492
  hideShareMessageOption,
434
493
  hideEditMessageOption,
@@ -539,10 +598,30 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
539
598
  group?.getGuid() == message.getReceiverId()) ||
540
599
  false);
541
600
  }
601
+ useEffect(() => {
602
+ if (isAgenticUser() && parentMessageId && !conversationId.current) {
603
+ conversationId.current = parentMessageId;
604
+ }
605
+ }, [parentMessageId, isAgenticUser]);
542
606
  function checkSameConversation(message) {
607
+ if (message.isStreamMessage) {
608
+ if (isAgenticUser()) {
609
+ return message.targetMessageId === agenticParentMessageIdRef.current;
610
+ }
611
+ return true;
612
+ }
613
+ if (isAgenticUser()) {
614
+ if (parentMessageId && agenticParentMessageIdRef.current) {
615
+ return (message.getParentMessageId &&
616
+ String(message.getParentMessageId()) === String(agenticParentMessageIdRef.current));
617
+ }
618
+ return false;
619
+ }
543
620
  return (message.getConversationId() == conversationId.current ||
544
621
  (message.getSender()?.getUid() === user?.getUid() &&
545
- message.getReceiverType() == CometChatUiKitConstants.ReceiverTypeConstants.user));
622
+ message.getReceiverType() == CometChatUiKitConstants.ReceiverTypeConstants.user) ||
623
+ checkMessageInSameConversation(message) ||
624
+ messageToSameConversation(message));
546
625
  }
547
626
  function isNearBottom() {
548
627
  const { layoutHeight, scrollViewHeight, y } = currentScrollPosition.current;
@@ -567,24 +646,37 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
567
646
  if (baseMessage.getCategory() === MessageCategoryConstants.interactive) {
568
647
  //todo show unsupported bubble
569
648
  }
570
- if (checkSameConversation(baseMessage) ||
571
- checkMessageInSameConversation(baseMessage) ||
572
- messageToSameConversation(baseMessage)) {
573
- CometChat.markAsDelivered(newMessage);
574
- //need to add
575
- if (!parentMessageId && newMessage.getParentMessageId()) {
576
- //increase count
577
- let index = messagesList.findIndex((msg) => msg.id === newMessage.parentMessageId);
578
- let oldMsg = CommonUtils.clone(messagesList[index]);
579
- oldMsg.setReplyCount(oldMsg.getReplyCount() ? oldMsg.getReplyCount() + 1 : 1);
580
- let tmpList = [...messagesList];
581
- tmpList[index] = oldMsg;
582
- messagesContentListRef.current = tmpList;
583
- onLoad && onLoad([...messagesContentListRef.current].reverse());
584
- setMessagesList(tmpList);
649
+ if (isAgenticUser()) {
650
+ if (String(baseMessage.getParentMessageId()) === String(parentMessageId) ||
651
+ String(baseMessage.getId()) === String(parentMessageId)) {
652
+ CometChat.markAsDelivered(newMessage);
653
+ bottomHandler(newMessage, isReceived);
654
+ }
655
+ else {
585
656
  return;
586
657
  }
587
- bottomHandler(newMessage, isReceived);
658
+ }
659
+ else {
660
+ if (checkSameConversation(baseMessage) ||
661
+ checkMessageInSameConversation(baseMessage) ||
662
+ messageToSameConversation(baseMessage)) {
663
+ CometChat.markAsDelivered(newMessage);
664
+ if (!parentMessageId && newMessage.getParentMessageId()) {
665
+ const parentId = String(newMessage.getParentMessageId ? newMessage.getParentMessageId() : newMessage.parentMessageId);
666
+ let index = messagesContentListRef.current.findIndex((msg) => String(msg.getId ? msg.getId() : msg.id) === parentId);
667
+ if (index !== -1 && messagesContentListRef.current[index]) {
668
+ let oldMsg = CommonUtils.clone(messagesContentListRef.current[index]);
669
+ oldMsg.setReplyCount(oldMsg.getReplyCount() ? oldMsg.getReplyCount() + 1 : 1);
670
+ let tmpList = [...messagesContentListRef.current];
671
+ tmpList[index] = oldMsg;
672
+ messagesContentListRef.current = tmpList;
673
+ onLoad && onLoad([...messagesContentListRef.current].reverse());
674
+ setMessagesList(tmpList);
675
+ }
676
+ return;
677
+ }
678
+ bottomHandler(newMessage, isReceived);
679
+ }
588
680
  }
589
681
  playNotificationSound(newMessage);
590
682
  };
@@ -596,6 +688,13 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
596
688
  return false;
597
689
  };
598
690
  const bottomHandler = (newMessage, isReceived = false, skipAddToList = false) => {
691
+ if (newMessage?.isStreamMessage) {
692
+ if (!skipAddToList) {
693
+ addToMessageList(newMessage);
694
+ }
695
+ scrollToBottom();
696
+ return;
697
+ }
599
698
  if ((newMessage.getSender()?.getUid() || newMessage?.["sender"]?.["uid"]) ==
600
699
  loggedInUser.current?.["uid"]) {
601
700
  if (!skipAddToList) {
@@ -627,6 +726,35 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
627
726
  }
628
727
  };
629
728
  const addToMessageList = (newMessage) => {
729
+ if (isAgenticUser() && !conversationId.current) {
730
+ if (newMessage.getConversationId()) {
731
+ conversationId.current = newMessage.getConversationId();
732
+ }
733
+ else if (!parentMessageId) {
734
+ const msgId = newMessage.getId();
735
+ if (msgId) {
736
+ conversationId.current = `${loggedInUser.current?.getUid()}_${user?.getUid()}_${msgId}`;
737
+ }
738
+ }
739
+ }
740
+ else if (!conversationId.current && newMessage.getConversationId()) {
741
+ conversationId.current = newMessage.getConversationId();
742
+ }
743
+ const isStreamMessage = newMessage.isStreamMessage;
744
+ const targetMessageId = newMessage.targetMessageId;
745
+ if (isStreamMessage && targetMessageId) {
746
+ const targetId = String(targetMessageId);
747
+ let userMsgIdx = messagesContentListRef.current.findIndex((msg) => String(msg.getId()) === targetId);
748
+ let updatedList;
749
+ if (userMsgIdx !== -1) {
750
+ updatedList = [...messagesContentListRef.current].filter((msg, idx) => !(idx === userMsgIdx - 1 && msg.isStreamMessage && msg.targetMessageId === targetId));
751
+ updatedList.splice(userMsgIdx, 0, newMessage);
752
+ messagesContentListRef.current = updatedList;
753
+ onLoad && onLoad([...messagesContentListRef.current].reverse());
754
+ setMessagesList(updatedList);
755
+ return;
756
+ }
757
+ }
630
758
  messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
631
759
  onLoad && onLoad([...messagesContentListRef.current].reverse());
632
760
  setMessagesList((prev) => [newMessage, ...prev]);
@@ -755,8 +883,15 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
755
883
  CometChat.getLoggedinUser()
756
884
  .then((u) => {
757
885
  loggedInUser.current = u;
758
- messageRequest.current = msgRequestBuilder.current?.build() || null;
759
- getPreviousMessages();
886
+ if (isAgenticUser() && !parentMessageId) {
887
+ messageRequest.current = null;
888
+ }
889
+ else {
890
+ messageRequest.current = msgRequestBuilder.current?.build() || null;
891
+ }
892
+ if (!isAgenticUser() || (isAgenticUser() && parentMessageId)) {
893
+ getPreviousMessages();
894
+ }
760
895
  })
761
896
  .catch((e) => {
762
897
  console.log("Error while getting loggedInUser");
@@ -770,8 +905,78 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
770
905
  onBack && onBack();
771
906
  };
772
907
  }, []);
908
+ // Callback to add stream message and register queue completion callback
909
+ const createStreamMessage = useCallback((userMessage) => {
910
+ const runId = String(userMessage.getId());
911
+ const streamMessage = new StreamMessage(user?.getUid() || group?.getGuid() || '', user ? CometChat.RECEIVER_TYPE.USER : CometChat.RECEIVER_TYPE.GROUP, CometChatUiKitConstants.streamMessageTypes.run_started, CometChatUiKitConstants.MessageCategoryConstants.stream);
912
+ streamMessage.setId(Number(userMessage.getId()));
913
+ if (user) {
914
+ streamMessage.setSender(user);
915
+ }
916
+ streamMessage.setReceiver(loggedInUser.current);
917
+ streamMessage.setReceiverType(CometChat.RECEIVER_TYPE.USER);
918
+ streamMessage.setSentAt(Math.floor(Date.now() / 1000));
919
+ streamMessage.targetMessageId = runId;
920
+ streamMessage.isStreamMessage = true;
921
+ return streamMessage;
922
+ }, [user, group, addToMessageList, setMessagesList, onLoad]);
923
+ const updateStreamMessageWithActualId = useCallback((actualMessageId, runId) => {
924
+ const updatedList = messagesContentListRef.current.map(msg => {
925
+ if (msg.isStreamMessage === true &&
926
+ msg.targetMessageId === runId) {
927
+ const updatedStreamMessage = { ...msg };
928
+ msg.setId(actualMessageId);
929
+ msg.targetMessageId = String(actualMessageId);
930
+ return msg;
931
+ }
932
+ return msg;
933
+ });
934
+ messagesContentListRef.current = updatedList;
935
+ onLoad && onLoad([...messagesContentListRef.current].reverse());
936
+ setMessagesList(updatedList);
937
+ }, [onLoad]);
938
+ useEffect(() => {
939
+ if (isAgenticUser()) {
940
+ agenticParentMessageIdRef.current = undefined;
941
+ }
942
+ }, [user?.getUid(), group?.getGuid(), isAgenticUser]);
773
943
  useEffect(() => {
774
944
  //add listeners
945
+ // AI Assistant listener for agent chats
946
+ if (isAgenticUser() && user && (!parentMessageId || (parentMessageId && isAgenticUser()))) {
947
+ CometChat.addAIAssistantListener(streamListenerId, {
948
+ onAIAssistantEventReceived: (message) => {
949
+ if (message.getConversationId &&
950
+ (!message.getConversationId()?.includes(user.getUid()) ||
951
+ !message.getConversationId()?.includes(loggedInUser.current?.getUid()))) {
952
+ return;
953
+ }
954
+ if (message.getType() === CometChatUiKitConstants.streamMessageTypes.run_started) {
955
+ const lastMessage = messagesContentListRef.current[0];
956
+ updateStreamMessageWithActualId(message.getMessageId(), message.getRunId());
957
+ }
958
+ if (message.getType() === CometChatUiKitConstants.streamMessageTypes.run_finished) {
959
+ const runId = String(message.getRunId?.() || message.getMessageId?.());
960
+ setQueueCompletionCallback(runId, (aiAssistantMessage, aiToolResultMessage, aiToolArgumentMessage) => {
961
+ let replacement = aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
962
+ if (!replacement)
963
+ return;
964
+ const updatedList = messagesContentListRef.current.map(msg => {
965
+ if (msg.isStreamMessage === true && msg.targetMessageId === runId) {
966
+ return replacement;
967
+ }
968
+ return msg;
969
+ });
970
+ messagesContentListRef.current = updatedList;
971
+ setMessagesList(updatedList);
972
+ onLoad && onLoad([...updatedList].reverse());
973
+ });
974
+ checkAndTriggerQueueCompletion(runId);
975
+ }
976
+ handleWebsocketMessage(message);
977
+ },
978
+ });
979
+ }
775
980
  let reactionListeners = {
776
981
  onMessageReactionAdded: (reaction) => {
777
982
  updateMessageReaction(reaction, true);
@@ -810,6 +1015,15 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
810
1015
  }
811
1016
  if (status == MessageStatusConstants.success) {
812
1017
  messageEdited(message, true);
1018
+ if (isAgenticUser() &&
1019
+ agenticParentMessageIdRef.current === undefined &&
1020
+ messagesList.length !== 0 && message.getType() === MessageTypeConstants.text && message.getCategory() === MessageCategoryConstants.message) {
1021
+ agenticParentMessageIdRef.current = String(message.getId());
1022
+ }
1023
+ if (isAgenticUser() && agenticParentMessageIdRef.current !== undefined) {
1024
+ const streamMessage = createStreamMessage(message);
1025
+ addToMessageList(streamMessage);
1026
+ }
813
1027
  }
814
1028
  if (status == MessageStatusConstants.error) {
815
1029
  messageEdited(message, true);
@@ -829,13 +1043,40 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
829
1043
  }
830
1044
  },
831
1045
  onTextMessageReceived: (textMessage) => {
832
- newMessage(textMessage);
1046
+ if (isAgenticUser()) {
1047
+ if (textMessage.getSender?.()?.getRole?.() === '@agentic' ||
1048
+ textMessage.getCategory?.() === MessageCategoryConstants.agentic ||
1049
+ textMessage.getCategory?.() === CometChatUiKitConstants.MessageCategoryConstants.stream) {
1050
+ newMessage(textMessage);
1051
+ }
1052
+ }
1053
+ else {
1054
+ newMessage(textMessage);
1055
+ }
833
1056
  },
834
1057
  onMediaMessageReceived: (mediaMessage) => {
835
- newMessage(mediaMessage);
1058
+ if (isAgenticUser()) {
1059
+ if (mediaMessage.getSender?.()?.getRole?.() === '@agentic' ||
1060
+ mediaMessage.getCategory?.() === MessageCategoryConstants.agentic ||
1061
+ mediaMessage.getCategory?.() === CometChatUiKitConstants.MessageCategoryConstants.stream) {
1062
+ newMessage(mediaMessage);
1063
+ }
1064
+ }
1065
+ else {
1066
+ newMessage(mediaMessage);
1067
+ }
836
1068
  },
837
1069
  onCustomMessageReceived: (customMessage) => {
838
- newMessage(customMessage);
1070
+ if (isAgenticUser()) {
1071
+ if (customMessage.getSender?.()?.getRole?.() === '@agentic' ||
1072
+ customMessage.getCategory?.() === MessageCategoryConstants.agentic ||
1073
+ customMessage.getCategory?.() === CometChatUiKitConstants.MessageCategoryConstants.stream) {
1074
+ newMessage(customMessage);
1075
+ }
1076
+ }
1077
+ else {
1078
+ newMessage(customMessage);
1079
+ }
839
1080
  },
840
1081
  onMessagesDelivered: (messageReceipt) => {
841
1082
  updateMessageReceipt(messageReceipt);
@@ -864,6 +1105,15 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
864
1105
  onInteractionGoalCompleted: (interactionReceipt) => {
865
1106
  //todo show unsupported bubble
866
1107
  },
1108
+ onAIAssistantMessageReceived: (aiAssistantMessage) => {
1109
+ const runId = aiAssistantMessage.getAssistantMessageData?.()?.getRunId?.() || aiAssistantMessage.getId?.();
1110
+ if (parentMessageId && String(parentMessageId) !== String(aiAssistantMessage.getParentMessageId?.())) {
1111
+ return;
1112
+ }
1113
+ if (runId) {
1114
+ storeAIAssistantMessage(String(runId), aiAssistantMessage);
1115
+ }
1116
+ },
867
1117
  ...reactionListeners,
868
1118
  onMessagesDeliveredToAll: (messageReceipt) => {
869
1119
  updateMessageReceipt(messageReceipt);
@@ -959,6 +1209,7 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
959
1209
  CometChat.addConnectionListener(connectionListenerId, new CometChat.ConnectionListener({
960
1210
  onConnected: () => {
961
1211
  console.log("CONNECTED...");
1212
+ streamOnConnected();
962
1213
  if (lastID.current) {
963
1214
  getUpdatedPreviousMessages();
964
1215
  }
@@ -966,6 +1217,7 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
966
1217
  inConnecting: () => { },
967
1218
  onDisconnected: () => {
968
1219
  console.log("DISCONNECTED...");
1220
+ streamOnDisconnected();
969
1221
  if (!messagesList[0].id) {
970
1222
  for (let i = 0; i < messagesList.length; i++) {
971
1223
  if (messagesList[i].id) {
@@ -987,8 +1239,24 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
987
1239
  CometChat.removeGroupListener(groupListenerId);
988
1240
  CometChat.removeCallListener(callListenerId);
989
1241
  CometChat.removeConnectionListener(connectionListenerId);
1242
+ if (isAgenticUser()) {
1243
+ CometChat.removeAIAssistantListener(streamListenerId);
1244
+ if (streamSubscriptionRef.current) {
1245
+ streamSubscriptionRef.current.unsubscribe();
1246
+ }
1247
+ }
990
1248
  };
991
- }, [messagesList, unreadCount, user, group]);
1249
+ }, [unreadCount, user, group, isAgenticUser, messagesList]);
1250
+ useEffect(() => {
1251
+ if (aiAssistantTools) {
1252
+ setAIAssistantTools(aiAssistantTools);
1253
+ }
1254
+ }, [aiAssistantTools]);
1255
+ // Initialize streaming configuration and subscribe to streaming state
1256
+ useEffect(() => {
1257
+ setStreamSpeed(streamingSpeed);
1258
+ return () => streamSubscriptionRef.current?.unsubscribe();
1259
+ }, [streamingSpeed]);
992
1260
  useEffect(() => {
993
1261
  prevMessagesLength.current =
994
1262
  messagesLength.current || messagesContentListRef.current.length;
@@ -1092,10 +1360,14 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1092
1360
  // functions returning view
1093
1361
  const getLeadingView = useCallback((item) => {
1094
1362
  let _style = getCurrentBubbleStyle(item);
1095
- if (avatarVisibility &&
1096
- (alignment === "leftAligned" ||
1097
- (item.getSender()?.getUid() !== loggedInUser.current?.getUid() && !user)) &&
1098
- ![MessageCategoryConstants.action, MessageCategoryConstants.call].includes(item.getCategory())) {
1363
+ if ([MessageCategoryConstants.action, MessageCategoryConstants.call].includes(item.getCategory())) {
1364
+ return undefined;
1365
+ }
1366
+ const isIncomingMessage = item.getSender()?.getUid() !== loggedInUser.current?.getUid();
1367
+ const shouldShowAvatar = avatarVisibility && (alignment === "leftAligned" ||
1368
+ (isIncomingMessage && !user) ||
1369
+ (isAgenticUser() && isIncomingMessage));
1370
+ if (shouldShowAvatar) {
1099
1371
  return (<CometChatAvatar image={item?.getSender()?.getAvatar && item?.getSender()?.getAvatar()
1100
1372
  ? { uri: item.getSender().getAvatar() }
1101
1373
  : undefined} name={item?.getSender()?.getName && item?.getSender()?.getName()
@@ -1145,6 +1417,9 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1145
1417
  // This example assumes you have a method (or property) like getEditedAt() that returns a timestamp when edited.
1146
1418
  const isEdited = item.getEditedAt?.() &&
1147
1419
  item.getType() === MessageTypeConstants.text;
1420
+ const shouldShowTimestamp = isAgenticUser()
1421
+ ? isOutgoingMessage
1422
+ : !hideTimestamp;
1148
1423
  return (<View>
1149
1424
  <View style={[
1150
1425
  {
@@ -1163,10 +1438,10 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1163
1438
  ]}>
1164
1439
  {t("EDITED")}
1165
1440
  </Text>)}
1166
- {<CometChatDate timeStamp={!hideTimestamp
1441
+ {shouldShowTimestamp && (<CometChatDate timeStamp={!hideTimestamp
1167
1442
  ? (item.getDeletedAt() || item.getSentAt()) * 1000 ||
1168
1443
  getSentAtTimestamp(item)
1169
- : undefined} pattern={"timeFormat"} customDateString={datePattern && datePattern(item)} style={_style.dateStyles}/>}
1444
+ : undefined} pattern={"timeFormat"} customDateString={datePattern && datePattern(item)} style={_style.dateStyles}/>)}
1170
1445
  {receiptsVisibility && alignment !== "leftAligned" && isOutgoingMessage ? (<View style={{ marginLeft: 2, alignItems: "center", justifyContent: "center" }}>
1171
1446
  <CometChatReceipt receipt={messageState} style={{
1172
1447
  deliveredIcon: _style.receiptStyles.deliveredIcon,
@@ -1183,7 +1458,7 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1183
1458
  </View>) : null}
1184
1459
  </View>
1185
1460
  </View>);
1186
- }, [mergedTheme]);
1461
+ }, [mergedTheme, isAgenticUser, hideTimestamp]);
1187
1462
  const onReactionPress = useCallback((reaction, messageObject) => {
1188
1463
  if (reaction.getReaction() == "All") {
1189
1464
  setSelectedMessage(messageObject);
@@ -1382,6 +1657,8 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1382
1657
  : getFooterView(message, bubbleAlignment);
1383
1658
  }, [hasTemplate, isThreaded, getFooterView, message, bubbleAlignment]);
1384
1659
  const ThreadedView = useMemo(() => {
1660
+ if (isAgenticUser())
1661
+ return undefined;
1385
1662
  return !isThreaded
1386
1663
  ? !message.getDeletedBy()
1387
1664
  ? getThreadView(message, bubbleAlignment)
@@ -1515,42 +1792,212 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1515
1792
  }
1516
1793
  setShowMessageOptions([]);
1517
1794
  };
1518
- const RenderMessageItem = useCallback(({ item, theme }) => {
1519
- const index = useMemo(() => {
1520
- return messagesContentListRef.current.findIndex((msg) => msg.getId() === item.getId() || msg.getMuid() === item.getMuid());
1521
- }, [item]);
1522
- const separatorView = useMemo(() => {
1523
- const previousMessageDate = messagesContentListRef.current[index + 1]
1524
- ? new Date(getSentAtTimestamp(messagesContentListRef.current[index + 1]))
1525
- : null;
1526
- const currentMessageDate = new Date(getSentAtTimestamp(item));
1527
- const currentDate = isNaN(currentMessageDate.getDate())
1528
- ? undefined
1529
- : `${currentMessageDate.getDate()}-${currentMessageDate.getMonth()}-${currentMessageDate.getFullYear()}`;
1530
- const previousDate = `${previousMessageDate?.getDate()}-${previousMessageDate?.getMonth()}-${previousMessageDate?.getFullYear()}`;
1531
- if (currentDate !== undefined && previousDate !== currentDate) {
1532
- return (<View style={{ marginBottom: 10 }}>
1533
- <CometChatDateSeparator timeStamp={getSentAtTimestamp(item)} pattern={"dayDateFormat"} customDateString={dateSeparatorPattern ? dateSeparatorPattern(item.getSentAt()) : undefined} style={theme.messageListStyles.dateSeparatorStyle}/>
1534
- </View>);
1795
+ const sentAtToMs = (msg) => {
1796
+ if (!msg)
1797
+ return undefined;
1798
+ // try CometChat getter first
1799
+ const raw = typeof msg.getSentAt === "function"
1800
+ ? msg.getSentAt()
1801
+ : (msg?.sentAt ?? msg?.sent_at ?? msg?.sentOn ?? msg?.senton);
1802
+ if (raw === undefined || raw === null)
1803
+ return undefined;
1804
+ // if raw looks like seconds (10 digits) convert to ms
1805
+ return raw < 1e12 ? raw * 1000 : raw;
1806
+ };
1807
+ const makeDayKey = (ms) => {
1808
+ if (!ms)
1809
+ return null;
1810
+ const d = new Date(ms);
1811
+ // use local date parts so "Today" follows user's timezone
1812
+ return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
1813
+ };
1814
+ const messageDayKeys = useMemo(() => {
1815
+ return messagesList.map((m) => {
1816
+ const ms = sentAtToMs(m);
1817
+ return makeDayKey(ms); // null if no timestamp
1818
+ });
1819
+ }, [messagesList]);
1820
+ const showDateSeparatorAtIndex = useMemo(() => {
1821
+ const n = messagesList.length;
1822
+ const flags = new Array(n).fill(false);
1823
+ // helper to find next non-null key to the right
1824
+ const nextNonNullKey = (startIdx) => {
1825
+ for (let j = startIdx; j < n; j++) {
1826
+ if (messageDayKeys[j] != null)
1827
+ return messageDayKeys[j];
1535
1828
  }
1536
1829
  return null;
1537
- }, [item, dateSeparatorPattern, theme]);
1830
+ };
1831
+ for (let i = 0; i < n; i++) {
1832
+ const currKey = messageDayKeys[i] ?? nextNonNullKey(i);
1833
+ const nextKey = i + 1 < n ? (messageDayKeys[i + 1] ?? nextNonNullKey(i + 1)) : null;
1834
+ if (currKey != null && currKey !== nextKey) {
1835
+ flags[i] = true;
1836
+ }
1837
+ else if (i === n - 1 && currKey != null) {
1838
+ // last message in list show header
1839
+ flags[i] = true;
1840
+ }
1841
+ }
1842
+ return flags;
1843
+ }, [messageDayKeys, messagesList.length]);
1844
+ const isSameLocalDay = (ms) => {
1845
+ if (!ms)
1846
+ return false;
1847
+ const a = new Date(ms);
1848
+ const b = new Date();
1849
+ return (a.getFullYear() === b.getFullYear() &&
1850
+ a.getMonth() === b.getMonth() &&
1851
+ a.getDate() === b.getDate());
1852
+ };
1853
+ const getDayHeaderString = (ms) => {
1854
+ if (!ms)
1855
+ return undefined;
1856
+ if (isSameLocalDay(ms))
1857
+ return t("TODAY") || "Today";
1858
+ return dateSeparatorPattern ? dateSeparatorPattern(ms) : undefined;
1859
+ };
1860
+ const RenderMessageItem = useCallback(({ item, theme, idx, }) => {
1861
+ const index = idx;
1538
1862
  lastMessageDate.current = getSentAtTimestamp(item);
1539
- return (<React.Fragment key={index}>
1540
- {separatorView}
1863
+ return (<React.Fragment key={`${item.getId()}_${item.getMuid()}`}>
1541
1864
  <MessageView message={item} currentIndex={index}/>
1542
1865
  </React.Fragment>);
1543
- }, [mergedTheme]);
1866
+ }, [mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]);
1544
1867
  const keyExtractor = useCallback((item) => `${item?.getId()}_${item.getMuid()}`, []);
1545
1868
  const itemSeparator = useCallback(() => <View style={{ height: 8 }}/>, []);
1869
+ const getAgentEmptyView = useCallback(() => {
1870
+ if (!user)
1871
+ return <></>;
1872
+ const userMetadata = user.getMetadata();
1873
+ const displaySuggestions = suggestedMessages.length > 0
1874
+ ? suggestedMessages
1875
+ : userMetadata?.suggestedMessages || [];
1876
+ const isDark = mergedTheme.mode === "dark";
1877
+ const { background2, textPrimary, textSecondary, borderLight, primary, textTertiary, } = mergedTheme.color;
1878
+ const avatarURL = user.getAvatar();
1879
+ const isSVG = avatarURL && (avatarURL.includes(".svg") || avatarURL.includes("svg"));
1880
+ const imageSource = !isSVG && avatarURL ? { uri: avatarURL } : undefined;
1881
+ return (<ScrollView contentContainerStyle={{
1882
+ flex: 1,
1883
+ justifyContent: "center",
1884
+ alignItems: "center",
1885
+ }} showsVerticalScrollIndicator={false}>
1886
+ <View style={{
1887
+ alignItems: "center",
1888
+ justifyContent: "center",
1889
+ padding: 24,
1890
+ }}>
1891
+ {emptyChatImageView || (<CometChatAvatar image={imageSource} name={user.getName()} style={{
1892
+ containerStyle: {
1893
+ width: 60,
1894
+ height: 60,
1895
+ borderRadius: 40,
1896
+ marginBottom: 20,
1897
+ alignItems: "center",
1898
+ justifyContent: "center",
1899
+ backgroundColor: mergedTheme.avatarStyle.containerStyle?.backgroundColor,
1900
+ },
1901
+ imageStyle: {
1902
+ width: 60,
1903
+ height: 60,
1904
+ borderRadius: 40,
1905
+ },
1906
+ textStyle: {
1907
+ fontSize: 32,
1908
+ fontWeight: "bold",
1909
+ color: mergedTheme.avatarStyle.textStyle?.color,
1910
+ textAlign: "center",
1911
+ textAlignVertical: "center",
1912
+ },
1913
+ }}/>)}
1914
+
1915
+ {emptyChatGreetingView || (<Text style={{
1916
+ fontSize: theme.typography.heading4.medium.fontSize,
1917
+ fontWeight: theme.typography.heading4.medium.fontWeight,
1918
+ textAlign: "center",
1919
+ color: textPrimary,
1920
+ }}>
1921
+ {userMetadata?.greetingMessage ?? `Hi, I'm ${user.getName()}`}
1922
+ </Text>)}
1923
+
1924
+ {emptyChatIntroMessageView || (<Text style={{
1925
+ fontSize: theme.typography.body.regular.fontSize,
1926
+ fontWeight: theme.typography.body.regular.fontWeight,
1927
+ marginBottom: theme.spacing.spacing.s5,
1928
+ textAlign: "center",
1929
+ lineHeight: 22,
1930
+ paddingHorizontal: 20,
1931
+ color: textTertiary,
1932
+ }}>
1933
+ {userMetadata?.introductoryMessage ??
1934
+ "I'm here to help! Ask me anything or choose from the suggestions below."}
1935
+ </Text>)}
1936
+
1937
+ {!hideSuggestedMessages && displaySuggestions?.length > 0 && (<View style={{
1938
+ flexDirection: "row",
1939
+ flexWrap: "wrap",
1940
+ justifyContent: "center",
1941
+ paddingHorizontal: 0,
1942
+ maxWidth: "100%",
1943
+ }}>
1944
+ {displaySuggestions.map((suggestion, idx) => (<TouchableOpacity key={idx} style={{
1945
+ borderRadius: 20,
1946
+ paddingHorizontal: theme.spacing.spacing.s4,
1947
+ paddingVertical: theme.spacing.spacing.s2,
1948
+ margin: theme.spacing.margin.m1,
1949
+ borderWidth: 1,
1950
+ backgroundColor: isDark ? theme.color.background1 : theme.color.background1,
1951
+ borderColor: isDark ? mergedTheme.color.borderDefault : mergedTheme.color.borderDefault,
1952
+ flexDirection: "row",
1953
+ alignItems: "center",
1954
+ maxWidth: "100%",
1955
+ }} onPress={() => {
1956
+ if (onSuggestedMessageClick) {
1957
+ onSuggestedMessageClick(suggestion);
1958
+ }
1959
+ else {
1960
+ CometChatUIEventHandler.emitUIEvent("ccComposeMessage", {
1961
+ text: suggestion,
1962
+ });
1963
+ }
1964
+ }}>
1965
+ <Text style={{
1966
+ fontWeight: theme.typography.body.regular.fontWeight,
1967
+ fontSize: theme.typography.body.regular.fontSize,
1968
+ color: textSecondary,
1969
+ paddingRight: mergedTheme.spacing.padding.p2,
1970
+ flexShrink: 1,
1971
+ }}>
1972
+ {suggestion}
1973
+ </Text>
1974
+ <Icon size={14} name='right-arrow' color={theme.color.iconSecondary}/>
1975
+ </TouchableOpacity>))}
1976
+ </View>)}
1977
+ </View>
1978
+ </ScrollView>);
1979
+ }, [
1980
+ user,
1981
+ suggestedMessages,
1982
+ hideSuggestedMessages,
1983
+ emptyChatGreetingView,
1984
+ emptyChatIntroMessageView,
1985
+ emptyChatImageView,
1986
+ onSuggestedMessageClick,
1987
+ mergedTheme,
1988
+ ]);
1546
1989
  const getEmptyStateView = useCallback(() => {
1990
+ const isAgenticUserCheck = user?.getRole?.() === '@agentic';
1991
+ if (isAgenticUserCheck) {
1992
+ return getAgentEmptyView();
1993
+ }
1547
1994
  if (EmptyView)
1548
1995
  return (<>
1549
1996
  <ScrollView contentContainerStyle={{}}>{EmptyView()}</ScrollView>
1550
1997
  </>);
1551
1998
  return (<ErrorEmptyView containerStyle={(mergedTheme.messageListStyles.emptyStateStyle?.containerStyle ??
1552
1999
  mergedTheme?.messageListStyles.containerStyle)} titleStyle={mergedTheme.messageListStyles.emptyStateStyle?.textStyle}/>);
1553
- }, [mergedTheme]);
2000
+ }, [mergedTheme, EmptyView, getAgentEmptyView, user]);
1554
2001
  const getErrorStateView = useCallback(() => {
1555
2002
  if (hideError)
1556
2003
  return null;
@@ -1569,6 +2016,11 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1569
2016
  if (loadingMessagesRef.current) {
1570
2017
  return;
1571
2018
  }
2019
+ // For agent chats (non-thread), don't fetch previous messages when scrolling to top
2020
+ if (isAgenticUser() && !parentMessageId) {
2021
+ scrollHandler(event);
2022
+ return;
2023
+ }
1572
2024
  const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
1573
2025
  if (Math.floor(contentOffset.y) >= Math.floor(contentSize.height - layoutMeasurement.height)) {
1574
2026
  getPreviousMessages();
@@ -1587,7 +2039,6 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1587
2039
  * layoutMeasurement.height: The height of the visible area within the ScrollView.
1588
2040
  * contentOffset.y: The current vertical scroll position (distance from the top of the content).
1589
2041
  The y value in contentOffset indicates how far the top edge of the visible area is from the top of the scrollable content.
1590
- The x value (if applicable) indicates how far the left edge of the visible area is from the left of the scrollable content.
1591
2042
  For example:
1592
2043
  If contentOffset.y is 0, the top of the visible area is aligned with the top of the content.
1593
2044
  If contentOffset.y is 50, the top of the visible area is 50 units (pixels) below the top of the content.
@@ -1616,12 +2067,20 @@ export const CometChatMessageList = memo(forwardRef((props, ref) => {
1616
2067
  // const windowSize = useMemo(() => {
1617
2068
  // return messagesList.length > 50 ? messagesList.length / 2 : 21;
1618
2069
  // }, [messagesList]);
1619
- const memoizedRenderItem = useCallback(({ item, index, separators }) => (<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8 }}>
1620
- <RenderMessageItem item={item} theme={mergedTheme}/>
1621
- {itemSeparator()}
1622
- </View>), [mergedTheme]);
2070
+ const memoizedRenderItem = useCallback(({ item, index, separators }) => {
2071
+ // index here is FlatList's index in messagesList (newest-first)
2072
+ const showSeparator = showDateSeparatorAtIndex[index];
2073
+ const ms = sentAtToMs(item) ?? Date.now();
2074
+ return (<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8 }}>
2075
+ {showSeparator && (<View style={{ alignItems: "center", marginBottom: 8 }}>
2076
+ <CometChatDateSeparator timeStamp={ms} pattern={"dayDateFormat"} customDateString={getDayHeaderString(ms)} style={mergedTheme.messageListStyles.dateSeparatorStyle}/>
2077
+ </View>)}
2078
+ <RenderMessageItem item={item} theme={mergedTheme} idx={index}/>
2079
+ {itemSeparator()}
2080
+ </View>);
2081
+ }, [mergedTheme, showDateSeparatorAtIndex, dateSeparatorPattern, messageDayKeys]);
1623
2082
  return (<View style={mergedTheme.messageListStyles.containerStyle}>
1624
- {listState == "loading" && messagesList.length == 0 ? (getLoadingStateView()) : listState == "error" ? (getErrorStateView()) : listState == "" ? (messagesList.length == 0 ? (getEmptyStateView()) : (<View style={{ height: "100%", width: "100%" }}>
2083
+ {listState == "loading" && messagesList.length == 0 ? (getLoadingStateView()) : listState == "error" ? (getErrorStateView()) : (listState == "" || listState == "loaded") ? (messagesList.length == 0 ? (getEmptyStateView()) : (<View style={{ height: "100%", width: "100%" }}>
1625
2084
  {HeaderView && (<View style={[{ top: 0 }]}>
1626
2085
  <HeaderView group={group} user={user} id={{
1627
2086
  guid: group && group["guid"],