@cometchat/chat-uikit-react-native 5.1.2 → 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 (200) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/7.4/gc.properties +0 -0
  5. package/android/.gradle/vcs-1/gc.properties +0 -0
  6. package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.d.ts +40 -0
  7. package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.js +467 -0
  8. package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.js.map +1 -0
  9. package/lib/CometChatAIAssistantChatHistory/Skeleton.d.ts +24 -0
  10. package/lib/CometChatAIAssistantChatHistory/Skeleton.js +130 -0
  11. package/lib/CometChatAIAssistantChatHistory/Skeleton.js.map +1 -0
  12. package/lib/CometChatAIAssistantChatHistory/index.d.ts +1 -0
  13. package/lib/CometChatAIAssistantChatHistory/index.js +2 -0
  14. package/lib/CometChatAIAssistantChatHistory/index.js.map +1 -0
  15. package/lib/CometChatAIAssistantChatHistory/style.d.ts +30 -0
  16. package/lib/CometChatAIAssistantChatHistory/style.js +122 -0
  17. package/lib/CometChatAIAssistantChatHistory/style.js.map +1 -0
  18. package/lib/CometChatConversations/CometChatConversations.js +26 -5
  19. package/lib/CometChatConversations/CometChatConversations.js.map +1 -1
  20. package/lib/CometChatMessageComposer/CometChatMessageComposer.d.ts +7 -0
  21. package/lib/CometChatMessageComposer/CometChatMessageComposer.js +101 -13
  22. package/lib/CometChatMessageComposer/CometChatMessageComposer.js.map +1 -1
  23. package/lib/CometChatMessageHeader/CometChatMessageHeader.d.ts +16 -0
  24. package/lib/CometChatMessageHeader/CometChatMessageHeader.js +63 -13
  25. package/lib/CometChatMessageHeader/CometChatMessageHeader.js.map +1 -1
  26. package/lib/CometChatMessageList/CometChatMessageList.d.ts +33 -0
  27. package/lib/CometChatMessageList/CometChatMessageList.js +535 -76
  28. package/lib/CometChatMessageList/CometChatMessageList.js.map +1 -1
  29. package/lib/CometChatMessageList/style.js +74 -2
  30. package/lib/CometChatMessageList/style.js.map +1 -1
  31. package/lib/calls/CometChatIncomingCall/CometChatIncomingCall.js +6 -12
  32. package/lib/calls/CometChatIncomingCall/CometChatIncomingCall.js.map +1 -1
  33. package/lib/calls/CometChatOutgoingCall/CometChatOutgoingCall.js +4 -3
  34. package/lib/calls/CometChatOutgoingCall/CometChatOutgoingCall.js.map +1 -1
  35. package/lib/extensions/Polls/Polls.js +38 -17
  36. package/lib/extensions/Polls/Polls.js.map +1 -1
  37. package/lib/index.d.ts +5 -1
  38. package/lib/index.js +6 -2
  39. package/lib/index.js.map +1 -1
  40. package/lib/shared/constants/UIKitConstants.d.ts +16 -0
  41. package/lib/shared/constants/UIKitConstants.js +16 -0
  42. package/lib/shared/constants/UIKitConstants.js.map +1 -1
  43. package/lib/shared/events/CometChatMessageEvents/index.d.ts +3 -0
  44. package/lib/shared/events/CometChatMessageEvents/index.js +3 -0
  45. package/lib/shared/events/CometChatMessageEvents/index.js.map +1 -1
  46. package/lib/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.js +3 -0
  47. package/lib/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.js.map +1 -1
  48. package/lib/shared/events/CometChatUIEventHandler/Listener.d.ts +3 -1
  49. package/lib/shared/events/CometChatUIEventHandler/Listener.js +4 -1
  50. package/lib/shared/events/CometChatUIEventHandler/Listener.js.map +1 -1
  51. package/lib/shared/events/ListenerInitializer.d.ts +3 -1
  52. package/lib/shared/events/ListenerInitializer.js +5 -1
  53. package/lib/shared/events/ListenerInitializer.js.map +1 -1
  54. package/lib/shared/events/messages.d.ts +2 -1
  55. package/lib/shared/events/messages.js +1 -0
  56. package/lib/shared/events/messages.js.map +1 -1
  57. package/lib/shared/framework/DataSource.d.ts +3 -1
  58. package/lib/shared/framework/DataSourceDecorator.d.ts +3 -1
  59. package/lib/shared/framework/DataSourceDecorator.js +8 -2
  60. package/lib/shared/framework/DataSourceDecorator.js.map +1 -1
  61. package/lib/shared/framework/MessageDataSource.d.ts +6 -0
  62. package/lib/shared/framework/MessageDataSource.js +64 -1
  63. package/lib/shared/framework/MessageDataSource.js.map +1 -1
  64. package/lib/shared/icons/components/ai-chat-history.d.ts +8 -0
  65. package/lib/shared/icons/components/ai-chat-history.js +9 -0
  66. package/lib/shared/icons/components/ai-chat-history.js.map +1 -0
  67. package/lib/shared/icons/components/ai-copy-option.d.ts +8 -0
  68. package/lib/shared/icons/components/ai-copy-option.js +9 -0
  69. package/lib/shared/icons/components/ai-copy-option.js.map +1 -0
  70. package/lib/shared/icons/components/ai-new-chat.d.ts +8 -0
  71. package/lib/shared/icons/components/ai-new-chat.js +9 -0
  72. package/lib/shared/icons/components/ai-new-chat.js.map +1 -0
  73. package/lib/shared/icons/components/ai-send-button.d.ts +8 -0
  74. package/lib/shared/icons/components/ai-send-button.js +9 -0
  75. package/lib/shared/icons/components/ai-send-button.js.map +1 -0
  76. package/lib/shared/icons/components/right-arrow.d.ts +3 -0
  77. package/lib/shared/icons/components/right-arrow.js +6 -0
  78. package/lib/shared/icons/components/right-arrow.js.map +1 -0
  79. package/lib/shared/icons/components/stop-fill.js +8 -7
  80. package/lib/shared/icons/components/stop-fill.js.map +1 -1
  81. package/lib/shared/icons/icon-mapping.d.ts +11 -0
  82. package/lib/shared/icons/icon-mapping.js +11 -0
  83. package/lib/shared/icons/icon-mapping.js.map +1 -1
  84. package/lib/shared/modals/CometChatAIAssistantTools.d.ts +47 -0
  85. package/lib/shared/modals/CometChatAIAssistantTools.js +44 -0
  86. package/lib/shared/modals/CometChatAIAssistantTools.js.map +1 -0
  87. package/lib/shared/modals/StreamMessage.d.ts +4 -0
  88. package/lib/shared/modals/StreamMessage.js +11 -0
  89. package/lib/shared/modals/StreamMessage.js.map +1 -0
  90. package/lib/shared/modals/index.d.ts +3 -1
  91. package/lib/shared/modals/index.js +3 -1
  92. package/lib/shared/modals/index.js.map +1 -1
  93. package/lib/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.d.ts +126 -0
  94. package/lib/shared/resources/CometChatLocalizeNew/resources/de/translation.json +7 -1
  95. package/lib/shared/resources/CometChatLocalizeNew/resources/en/translation.json +7 -1
  96. package/lib/shared/resources/CometChatLocalizeNew/resources/es/translation.json +7 -1
  97. package/lib/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +7 -1
  98. package/lib/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +7 -1
  99. package/lib/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +7 -1
  100. package/lib/shared/resources/CometChatLocalizeNew/resources/it/translation.json +7 -1
  101. package/lib/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +7 -1
  102. package/lib/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +7 -1
  103. package/lib/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +7 -1
  104. package/lib/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +7 -1
  105. package/lib/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +7 -1
  106. package/lib/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +7 -1
  107. package/lib/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +7 -1
  108. package/lib/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +7 -1
  109. package/lib/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +7 -1
  110. package/lib/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +7 -1
  111. package/lib/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +7 -1
  112. package/lib/shared/services/stream-message.service.d.ts +84 -0
  113. package/lib/shared/services/stream-message.service.js +406 -0
  114. package/lib/shared/services/stream-message.service.js.map +1 -0
  115. package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.d.ts +9 -0
  116. package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.js +248 -0
  117. package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.js.map +1 -0
  118. package/lib/shared/views/CometChatAIAssistantMessageBubble/index.d.ts +3 -0
  119. package/lib/shared/views/CometChatAIAssistantMessageBubble/index.js +4 -0
  120. package/lib/shared/views/CometChatAIAssistantMessageBubble/index.js.map +1 -0
  121. package/lib/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.js +5 -2
  122. package/lib/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.js.map +1 -1
  123. package/lib/shared/views/CometChatImageBubble/CometChatImageLoader.js +1 -1
  124. package/lib/shared/views/CometChatImageBubble/CometChatImageLoader.js.map +1 -1
  125. package/lib/shared/views/CometChatImageViewerModal/ImageViewerModal.js +52 -32
  126. package/lib/shared/views/CometChatImageViewerModal/ImageViewerModal.js.map +1 -1
  127. package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.d.ts +10 -0
  128. package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.js +54 -0
  129. package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.js.map +1 -0
  130. package/lib/shared/views/CometChatSendButtonView/index.d.ts +1 -0
  131. package/lib/shared/views/CometChatSendButtonView/index.js +2 -0
  132. package/lib/shared/views/CometChatSendButtonView/index.js.map +1 -0
  133. package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.d.ts +8 -0
  134. package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.js +436 -0
  135. package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.js.map +1 -0
  136. package/lib/shared/views/CometChatStreamMessageBubble/index.d.ts +3 -0
  137. package/lib/shared/views/CometChatStreamMessageBubble/index.js +3 -0
  138. package/lib/shared/views/CometChatStreamMessageBubble/index.js.map +1 -0
  139. package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.d.ts +14 -6
  140. package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.js +82 -57
  141. package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.js.map +1 -1
  142. package/lib/theme/context.d.ts +96 -15
  143. package/lib/theme/type.d.ts +14 -1
  144. package/package.json +5 -2
  145. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +627 -0
  146. package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +228 -0
  147. package/src/CometChatAIAssistantChatHistory/index.ts +2 -0
  148. package/src/CometChatAIAssistantChatHistory/style.ts +160 -0
  149. package/src/CometChatConversations/CometChatConversations.tsx +36 -10
  150. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +137 -19
  151. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +106 -18
  152. package/src/CometChatMessageList/CometChatMessageList.tsx +619 -72
  153. package/src/CometChatMessageList/style.ts +74 -2
  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/CometChatSendButtonView/CometChatSendButtonView.tsx +86 -0
  197. package/src/shared/views/CometChatSendButtonView/index.ts +1 -0
  198. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +493 -0
  199. package/src/shared/views/CometChatStreamMessageBubble/index.ts +9 -0
  200. package/src/theme/type.ts +14 -1
@@ -0,0 +1,493 @@
1
+ import React, { useState, useEffect, useRef, useCallback, memo, useMemo } from 'react';
2
+ import { View, Text, StyleSheet, Animated, TouchableOpacity } from 'react-native';
3
+ import Markdown from 'react-native-markdown-display';
4
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
5
+ import { useTheme } from '../../../theme';
6
+ import { messageStream, streamingState$, IStreamData, getAIAssistantTools, stopStreamingForRunId, handleWebsocketMessage, startStreamingForRunId, streamConnection$, notifyStreamRenderComplete } from '../../services/stream-message.service';
7
+ import { CometChatUiKitConstants } from '../../index';
8
+
9
+ export interface CometChatStreamMessageBubbleProps {
10
+ message: any;
11
+ theme?: any;
12
+ style?: any;
13
+ }
14
+
15
+ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps> = memo(({
16
+ message,
17
+ style: bubbleStyle
18
+ }) => {
19
+ const initialMessageRef = useRef<any>(message);
20
+ const [data, setData] = useState<any>(initialMessageRef.current || null);
21
+ const [fullMessage, setFullMessage] = useState<string>('');
22
+ const [executionText, setExecutionText] = useState<string>('');
23
+ const [isStreaming, setIsStreaming] = useState(false);
24
+ const [hasError, setHasError] = useState(false);
25
+ const [finished, setFinished] = useState(false);
26
+ const [contentStreamStarted, setContentStreamStarted] = useState(false);
27
+ const [runStarted, setRunStarted] = useState(false);
28
+ const [showingExecutionText, setShowingExecutionText] = useState(false);
29
+ const shimmerAnimation = useRef(new Animated.Value(-1)).current;
30
+ const theme = useTheme();
31
+ const [connectionStatus, setConnectionStatus] = useState<'connected' | 'disconnected' | 'error'>('connected');
32
+ const streamListenerId = useRef(`stream_bubble_${Date.now()}`);
33
+ const hasInitializedStreaming = useRef(false);
34
+ const [renderComplete, setRenderComplete] = useState(false);
35
+
36
+ const toolCallNameRef = useRef<string>('');
37
+ const toolCallDataRef = useRef<object>({});
38
+
39
+ // Tool events mapping
40
+ const toolEventsMap = [
41
+ CometChatUiKitConstants.streamMessageTypes.tool_call_args,
42
+ CometChatUiKitConstants.streamMessageTypes.tool_call_end,
43
+ CometChatUiKitConstants.streamMessageTypes.tool_call_result,
44
+ CometChatUiKitConstants.streamMessageTypes.tool_call_start
45
+ ];
46
+ useEffect(() => {
47
+ if (finished && fullMessage && contentStreamStarted) {
48
+ setRenderComplete(true);
49
+ const runId = (initialMessageRef.current as any)?.getId?.();
50
+ if (runId) {
51
+ notifyStreamRenderComplete(runId);
52
+ }
53
+ }
54
+ }, [finished, fullMessage, contentStreamStarted]);
55
+
56
+ useEffect(() => {
57
+ const isStreamMessage = (initialMessageRef.current as any)?.isStreamMessage;
58
+ const runId = (initialMessageRef.current as any)?.getId?.();
59
+ const metadata = (initialMessageRef.current as any)?.getMetadata?.();
60
+ const startRunning = metadata?.start_running;
61
+
62
+ if (isStreamMessage && runId && startRunning && !hasInitializedStreaming.current) {
63
+ hasInitializedStreaming.current = true;
64
+ startStreamingForRunId(runId, (aiEvent: CometChat.AIAssistantBaseEvent) => {
65
+ if (aiEvent.getMessageId && aiEvent.getMessageId() === runId) {
66
+ if (aiEvent.getType() === CometChatUiKitConstants.streamMessageTypes.run_started) {
67
+ setRunStarted(true);
68
+ }
69
+ }
70
+ });
71
+ }
72
+
73
+ return () => {
74
+ if (hasInitializedStreaming.current) {
75
+ stopStreamingForRunId();
76
+ }
77
+ };
78
+ }, []);
79
+
80
+
81
+ useEffect(() => {
82
+ const streamState = streamingState$.subscribe({
83
+ next: setIsStreaming,
84
+ error: () => {
85
+ stopStreamingForRunId();
86
+ setHasError(true);
87
+ },
88
+ });
89
+
90
+ const subscription = messageStream.subscribe({
91
+ next: (streamData: IStreamData) => {
92
+ const targetMessageId = (initialMessageRef.current as any)?.getId?.();
93
+ const currentId = String(streamData.message?.getMessageId?.());
94
+
95
+ if (targetMessageId && String(currentId) !== String(targetMessageId)) {
96
+ return;
97
+ }
98
+
99
+ // Handle tool call events
100
+ const eventType = streamData.message.getType();
101
+
102
+ // Handle tool call events
103
+ if (toolEventsMap.includes(eventType)) {
104
+ if (eventType === CometChatUiKitConstants.streamMessageTypes.tool_call_start) {
105
+ toolCallNameRef.current = (streamData.message as any).getToolCallName();
106
+ const execText = streamData.message.getData()?.executionText;
107
+
108
+ if (execText) {
109
+ setExecutionText(execText);
110
+ setShowingExecutionText(true);
111
+ setContentStreamStarted(false);
112
+ }
113
+ }
114
+ if (eventType === CometChatUiKitConstants.streamMessageTypes.tool_call_args) {
115
+ toolCallDataRef.current = JSON.parse((streamData.message as any).getDelta());
116
+ }
117
+ if (eventType === CometChatUiKitConstants.streamMessageTypes.tool_call_end) {
118
+ const assistantTools = getAIAssistantTools();
119
+ const toolCallName = toolCallNameRef.current;
120
+
121
+ if (toolCallName && assistantTools) {
122
+ const handler = assistantTools.getAction(toolCallName);
123
+ handler?.(toolCallDataRef.current);
124
+ }
125
+ setShowingExecutionText(false);
126
+ setExecutionText('');
127
+ }
128
+ }
129
+
130
+ setData(streamData.message);
131
+
132
+ if (streamData.streamedMessages !== undefined) {
133
+ const newMessage = streamData.streamedMessages ?? '';
134
+ if (!contentStreamStarted && streamData.message?.getType() === CometChatUiKitConstants.streamMessageTypes.text_message_content) {
135
+ setContentStreamStarted(true);
136
+ setShowingExecutionText(false);
137
+ }
138
+ setFullMessage(() => newMessage);
139
+ }
140
+
141
+ if (streamData.message?.getType() === CometChatUiKitConstants.streamMessageTypes.run_finished) {
142
+ setFinished(true);
143
+ setContentStreamStarted(true);
144
+ setShowingExecutionText(false);
145
+ subscription.unsubscribe();
146
+ streamState.unsubscribe();
147
+ if (hasInitializedStreaming.current) {
148
+ CometChat.removeAIAssistantListener(streamListenerId.current);
149
+ hasInitializedStreaming.current = false;
150
+ }
151
+ }
152
+ },
153
+ error: () => {
154
+ stopStreamingForRunId();
155
+ setHasError(true);
156
+ },
157
+ });
158
+
159
+ return () => {
160
+ subscription.unsubscribe();
161
+ streamState.unsubscribe();
162
+ shimmerAnimation.stopAnimation();
163
+ };
164
+ }, []);
165
+
166
+ useEffect(() => {
167
+ const sub = streamConnection$.subscribe(({ status, error }) => {
168
+ setConnectionStatus(status);
169
+ if (status === 'disconnected' || status === 'error') {
170
+ setHasError(true);
171
+ stopStreamingForRunId();
172
+ }
173
+ });
174
+ return () => sub.unsubscribe();
175
+ }, []);
176
+
177
+ // Create markdown styles based on theme
178
+ const markdownStyles = useMemo(() => ({
179
+ body: {
180
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
181
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
182
+ fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
183
+ ...bubbleStyle?.textStyle,
184
+ margin: 0,
185
+ padding: 0,
186
+ textAlignVertical: 'top',
187
+ },
188
+ text: {
189
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
190
+ fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
191
+ ...(bubbleStyle?.textStyle && Object.fromEntries(
192
+ Object.entries(bubbleStyle.textStyle).filter(([key]) => key !== 'color')
193
+ )),
194
+ },
195
+ paragraph: {
196
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
197
+ margin: 0,
198
+ padding: 0,
199
+ },
200
+ code_inline: {
201
+ backgroundColor: theme.color.background3,
202
+ color: theme.color.textHighlight,
203
+ borderRadius: theme.spacing.radius.r1,
204
+ padding: theme.spacing.padding.p0_5,
205
+ },
206
+ code_block: {
207
+ backgroundColor: theme.color.background3,
208
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
209
+ borderRadius: theme.spacing.radius.r2,
210
+ padding: theme.spacing.padding.p2,
211
+ fontFamily: 'monospace',
212
+ },
213
+ fence: {
214
+ backgroundColor: theme.color.background3,
215
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
216
+ borderRadius: theme.spacing.radius.r2,
217
+ borderWidth: 1,
218
+ borderColor: theme.color.borderDefault,
219
+ padding: theme.spacing.padding.p2,
220
+ marginVertical: theme.spacing.margin.m4,
221
+ fontFamily: 'monospace',
222
+ },
223
+ table: {
224
+ borderWidth: 1,
225
+ borderColor: theme.color.borderDefault,
226
+ borderRadius: theme.spacing.radius.r2,
227
+ backgroundColor: theme.color.background2,
228
+ marginVertical: theme.spacing.margin.m2,
229
+ overflow: 'hidden' as 'hidden',
230
+ borderCollapse: 'separate' as 'separate',
231
+ borderSpacing: 0,
232
+ },
233
+ thead: {
234
+ backgroundColor: theme.color.background3,
235
+ margin: 0,
236
+ padding: 0,
237
+ },
238
+ tbody: {
239
+ backgroundColor: theme.color.background1,
240
+ margin: 0,
241
+ padding: 0,
242
+ },
243
+ th: {
244
+ borderRightWidth: 1,
245
+ borderBottomWidth: 1,
246
+ borderColor: theme.color.borderDefault,
247
+ backgroundColor: theme.color.background3,
248
+ padding: theme.spacing.padding.p2,
249
+ fontWeight: 'bold',
250
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
251
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
252
+ fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
253
+ margin: 0,
254
+ borderTopWidth: 0,
255
+ borderLeftWidth: 0,
256
+ },
257
+ td: {
258
+ borderRightWidth: 1,
259
+ borderBottomWidth: 1,
260
+ borderColor: theme.color.borderDefault,
261
+ backgroundColor: theme.color.background1,
262
+ padding: theme.spacing.padding.p2,
263
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
264
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
265
+ fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
266
+ margin: 0,
267
+ borderTopWidth: 0,
268
+ borderLeftWidth: 0,
269
+ },
270
+ tr: {
271
+ borderBottomWidth: 0,
272
+ margin: 0,
273
+ padding: 0,
274
+ },
275
+ heading1: {
276
+ fontWeight: '700' as '700',
277
+ fontSize: (bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize) * 1.6,
278
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
279
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
280
+ marginVertical: theme.spacing.margin.m2,
281
+ },
282
+ heading2: {
283
+ fontWeight: '700' as '700',
284
+ fontSize: (bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize) * 1.4,
285
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
286
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
287
+ marginVertical: theme.spacing.margin.m2,
288
+ },
289
+ heading3: {
290
+ fontWeight: '700' as '700',
291
+ fontSize: (bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize) * 1.2,
292
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
293
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
294
+ marginVertical: theme.spacing.margin.m1,
295
+ },
296
+ heading4: {
297
+ fontWeight: '700' as '700',
298
+ fontSize: (bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize) * 1.1,
299
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
300
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
301
+ marginVertical: theme.spacing.margin.m1,
302
+ },
303
+ heading5: {
304
+ fontWeight: '700' as '700',
305
+ fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
306
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
307
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
308
+ marginVertical: theme.spacing.margin.m1,
309
+ },
310
+ heading6: {
311
+ fontWeight: '700' as '700',
312
+ fontSize: (bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize) * 0.9,
313
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
314
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
315
+ marginVertical: theme.spacing.margin.m1,
316
+ },
317
+ strong: {
318
+ fontWeight: '700' as '700',
319
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
320
+ },
321
+ em: {
322
+ fontStyle: 'italic' as 'italic',
323
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
324
+ },
325
+ blockquote: {
326
+ borderLeftWidth: 3,
327
+ borderLeftColor: theme.color.borderDefault,
328
+ paddingLeft: theme.spacing.padding.p2,
329
+ color: theme.color.textSecondary,
330
+ },
331
+ link: {
332
+ underlineColor: theme.color.textHighlight,
333
+ color: theme.color.textHighlight,
334
+ borderRadius: theme.spacing.radius.r1,
335
+ paddingHorizontal: theme.spacing.padding.p0_5,
336
+ paddingVertical: theme.spacing.padding.p0_5,
337
+ textDecorationLine: 'underline' as 'underline',
338
+ },
339
+ }), [bubbleStyle?.textStyle, theme]);
340
+
341
+ const MemoMarkdown = useMemo(() => {
342
+ return fullMessage ? (
343
+ <Markdown style={markdownStyles} mergeStyle={true}>
344
+ {fullMessage.trim()}
345
+ </Markdown>
346
+ ) : null;
347
+ }, [fullMessage, markdownStyles]);
348
+
349
+ const shouldShowThinking = !contentStreamStarted && !runStarted && !showingExecutionText;
350
+ const shouldShowExecutionText = showingExecutionText && executionText && !contentStreamStarted;
351
+
352
+ // Simple shimmer component - single text with opacity and color animation
353
+ const ShimmerText = useCallback(({ children, style }: { children: string, style: any }) => {
354
+ return (
355
+ <Animated.Text
356
+ style={[
357
+ style,
358
+ {
359
+ opacity: shimmerAnimation.interpolate({
360
+ inputRange: [-1, -0.5, 0, 0.5, 1],
361
+ outputRange: [0.4, 0.7, 1, 0.7, 0.4],
362
+ }),
363
+ color: shimmerAnimation.interpolate({
364
+ inputRange: [-1, -0.5, 0, 0.5, 1],
365
+ outputRange: [
366
+ style.color || theme.color.textTertiary,
367
+ style.color || theme.color.textTertiary,
368
+ style.color || theme.color.textSecondary,
369
+ style.color || theme.color.textPrimary,
370
+ style.color || theme.color.receiveBubbleText,
371
+ ],
372
+ }),
373
+ },
374
+ ]}
375
+ >
376
+ {children}
377
+ </Animated.Text>
378
+ );
379
+ }, [shimmerAnimation, theme]);
380
+
381
+ // Use the bubbleStyle passed from parent, with theme fallbacks
382
+ const styles = StyleSheet.create({
383
+ container: {
384
+ display: 'flex',
385
+ paddingVertical: bubbleStyle?.containerStyle?.paddingVertical || 0,
386
+ paddingHorizontal: bubbleStyle?.containerStyle?.paddingHorizontal || 0,
387
+ alignItems: 'flex-start',
388
+ justifyContent: 'flex-start',
389
+ alignSelf: 'flex-start',
390
+ backgroundColor: bubbleStyle?.containerStyle?.backgroundColor || 'transparent',
391
+ borderRadius: bubbleStyle?.containerStyle?.borderRadius || theme.spacing.radius.r3,
392
+ maxWidth: '100%',
393
+ ...bubbleStyle?.containerStyle,
394
+ },
395
+ textContainer: {
396
+ ...bubbleStyle?.textContainerStyle,
397
+ },
398
+ text: {
399
+ color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
400
+ fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
401
+ fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
402
+ ...bubbleStyle?.textStyle,
403
+ },
404
+ placeholderText: {
405
+ color: bubbleStyle?.placeholderTextStyle?.color || theme.color.receiveBubbleText,
406
+ fontFamily: bubbleStyle?.placeholderTextStyle?.fontFamily || theme.typography.body.regular.fontFamily,
407
+ fontSize: bubbleStyle?.placeholderTextStyle?.fontSize || theme.typography.body.regular.fontSize,
408
+ opacity: bubbleStyle?.placeholderTextStyle?.opacity || 0.6,
409
+ ...bubbleStyle?.placeholderTextStyle,
410
+ marginTop: 10
411
+ },
412
+ executionText: {
413
+ color: bubbleStyle?.placeholderTextStyle?.color || theme.color.receiveBubbleText,
414
+ fontFamily: bubbleStyle?.placeholderTextStyle?.fontFamily || theme.typography.body.regular.fontFamily,
415
+ fontSize: bubbleStyle?.placeholderTextStyle?.fontSize || theme.typography.body.regular.fontSize,
416
+ opacity: bubbleStyle?.placeholderTextStyle?.opacity || 0.8,
417
+ ...bubbleStyle?.placeholderTextStyle,
418
+ marginTop: 10,
419
+ fontStyle: 'italic',
420
+ },
421
+ errorContainer: {
422
+ borderLeftWidth: 3,
423
+ borderLeftColor: theme.color.error,
424
+ backgroundColor: bubbleStyle?.errorContainerStyle?.backgroundColor || theme.color.error,
425
+ padding: bubbleStyle?.errorContainerStyle?.padding || theme.spacing.padding.p2,
426
+ borderRadius: bubbleStyle?.errorContainerStyle?.borderRadius || theme.spacing.radius.r2,
427
+ marginTop: bubbleStyle?.errorContainerStyle?.marginTop || theme.spacing.margin.m1,
428
+ ...bubbleStyle?.errorContainerStyle,
429
+ },
430
+ errorText: {
431
+ color: bubbleStyle?.errorTextStyle?.color || theme.color.background1,
432
+ fontFamily: bubbleStyle?.errorTextStyle?.fontFamily || theme.typography.caption1.regular.fontFamily,
433
+ fontSize: bubbleStyle?.errorTextStyle?.fontSize || theme.typography.caption1.regular.fontSize,
434
+ ...bubbleStyle?.errorTextStyle,
435
+ },
436
+ });
437
+
438
+ useEffect(() => {
439
+ if ((shouldShowThinking || shouldShowExecutionText) && !fullMessage.trim() && !hasError) {
440
+ Animated.loop(
441
+ Animated.timing(shimmerAnimation, {
442
+ toValue: 1,
443
+ duration: 1200,
444
+ useNativeDriver: false,
445
+ })
446
+ ).start();
447
+ } else {
448
+ shimmerAnimation.stopAnimation();
449
+ shimmerAnimation.setValue(-1);
450
+ }
451
+ }, [shouldShowThinking, shouldShowExecutionText, fullMessage, hasError]);
452
+
453
+
454
+ return (
455
+ <View style={styles.container}>
456
+ {shouldShowThinking && (
457
+ <ShimmerText
458
+ style={[
459
+ styles.placeholderText,
460
+ {
461
+ fontStyle: theme.assistantBubbleStyles?.placeholderTextStyle?.fontStyle || theme.typography.body.regular.fontStyle,
462
+ },
463
+ ]}
464
+ >
465
+ Thinking...
466
+ </ShimmerText>
467
+ )}
468
+
469
+ {shouldShowExecutionText && (
470
+ <ShimmerText
471
+ style={[
472
+ styles.executionText,
473
+ {
474
+ fontStyle: theme.assistantBubbleStyles?.placeholderTextStyle?.fontStyle || theme.typography.body.regular.fontStyle,
475
+ },
476
+ ]}
477
+ >
478
+ {executionText}
479
+ </ShimmerText>
480
+ )}
481
+
482
+ {fullMessage && contentStreamStarted && MemoMarkdown}
483
+
484
+ {hasError && (
485
+ <View style={styles.errorContainer}>
486
+ <Text style={styles.errorText}>No internet connection. Please check your connection and try again.</Text>
487
+ </View>
488
+ )}
489
+ </View>
490
+ );
491
+ });
492
+
493
+ export default CometChatStreamMessageBubble;
@@ -0,0 +1,9 @@
1
+ import CometChatStreamMessageBubble, { CometChatStreamMessageBubbleProps } from "./CometChatStreamMessageBubble";
2
+
3
+ export {
4
+ CometChatStreamMessageBubble,
5
+ };
6
+
7
+ export type {
8
+ CometChatStreamMessageBubbleProps,
9
+ };
package/src/theme/type.ts CHANGED
@@ -22,6 +22,7 @@ import { CallLogsItemStyle, CallLogsStyle } from "../calls/CometChatCallLogs/sty
22
22
  import { DeepPartial } from "../shared/helper/types";
23
23
  import { DateSeparatorStyle } from "../shared/views/CometChatDateSeperator/styles";
24
24
  import { JSX } from "react";
25
+ import { ChatHistoryStyle } from "../CometChatAIAssistantChatHistory/style";
25
26
 
26
27
  export type BubbleStyles = {
27
28
  containerStyle: ViewStyle;
@@ -33,6 +34,7 @@ export type BubbleStyles = {
33
34
  dateReceiptContainerStyle: ViewStyle;
34
35
  senderNameTextStyles: TextStyle;
35
36
  textBubbleStyles?: DeepPartial<CometChatTheme["textBubbleStyles"]>;
37
+ assistantBubbleStyles?: DeepPartial<CometChatTheme["assistantBubbleStyles"]>;
36
38
  imageBubbleStyles?: DeepPartial<CometChatTheme["imageBubbleStyles"]>;
37
39
  videoBubbleStyles?: DeepPartial<CometChatTheme["videoBubbleStyles"]>;
38
40
  audioBubbleStyles?: DeepPartial<CometChatTheme["audioBubbleStyles"]>;
@@ -93,6 +95,7 @@ export interface CometChatTheme {
93
95
  deletedBubbleStyles?: DeletedBubbleStyle;
94
96
  messageComposerStyles: DeepPartial<MessageComposerStyle>;
95
97
  userStyles: UserStyle;
98
+ chatHistoryStyles: ChatHistoryStyle;
96
99
  groupStyles: GroupStyle;
97
100
  groupMemberStyle: GroupMemberStyle;
98
101
  //messageOptionsStyles: ActionSheetStyle;
@@ -347,6 +350,16 @@ export interface CometChatTheme {
347
350
  translatedTextContainerStyle: ViewStyle;
348
351
  translatedTextDividerStyle: ViewStyle;
349
352
  };
353
+ assistantBubbleStyles?: {
354
+ containerStyle: ViewStyle;
355
+ avatarStyle: CometChatTheme["avatarStyle"];
356
+ textStyle: TextStyle;
357
+ textContainerStyle?: ViewStyle;
358
+ placeholderTextStyle: TextStyle;
359
+ copyButtonStyle: ViewStyle;
360
+ errorContainerStyle: ViewStyle;
361
+ errorTextStyle: TextStyle;
362
+ };
350
363
  stickerBubbleStyles?: {
351
364
  containerStyle?: ViewStyle;
352
365
  threadedMessageStyle?: CometChatTheme["threadedMessageStyles"];
@@ -425,7 +438,7 @@ export interface CometChatTheme {
425
438
  };
426
439
  dateSeparatorStyle?: DateSeparatorStyle;
427
440
  incomingMessageBubbleStyles: DeepPartial<BubbleStyles>;
428
- outgoingMessageBubbleStyles: DeepPartial<BubbleStyles>;
441
+ outgoingMessageBubbleStyles: DeepPartial<Omit<BubbleStyles, 'assistantBubbleStyles'>>;
429
442
  groupActionBubbleStyles: DeepPartial<CometChatTheme["groupActionBubbleStyles"]>;
430
443
  callActionBubbleStyles: DeepPartial<CallActionBubbleStyles>;
431
444
  messageInformationStyles: DeepPartial<CometChatTheme["messageInformationStyles"]>;