@cometchat/chat-uikit-react-native 5.3.8 → 5.3.9

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 (42) hide show
  1. package/package.json +1 -1
  2. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +6 -3
  3. package/src/CometChatMessageList/CometChatMessageList.tsx +17 -1
  4. package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
  5. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
  6. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +12 -4
  7. package/src/CometChatSearch/CometChatSearch.tsx +16 -0
  8. package/src/shared/constants/UIKitConstants.ts +5 -1
  9. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +5 -0
  10. package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -0
  11. package/src/shared/events/CometChatUIEvents.ts +1 -0
  12. package/src/shared/events/ListenerInitializer.ts +3 -0
  13. package/src/shared/framework/DataSource.ts +10 -0
  14. package/src/shared/framework/DataSourceDecorator.tsx +13 -0
  15. package/src/shared/framework/MessageDataSource.tsx +56 -1
  16. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +501 -500
  17. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +1 -0
  18. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +521 -520
  19. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +521 -520
  20. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +521 -520
  21. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +521 -520
  22. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +521 -520
  23. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +521 -520
  24. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +521 -520
  25. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +521 -520
  26. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +521 -520
  27. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +521 -520
  28. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +521 -520
  29. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +521 -520
  30. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +521 -520
  31. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +521 -520
  32. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +521 -520
  33. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +521 -520
  34. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +7 -0
  35. package/src/shared/utils/conversationUtils.ts +8 -0
  36. package/src/shared/utils/stripRichText.ts +41 -0
  37. package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +107 -48
  38. package/src/shared/views/CometChatCardBubble/CometChatCardBubble.tsx +118 -0
  39. package/src/shared/views/CometChatCardBubble/index.ts +2 -0
  40. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +63 -0
  41. package/src/shared/views/index.ts +2 -0
  42. package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
@@ -221,6 +221,13 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
221
221
  }
222
222
  } else if (messageCategory === CometChat.CATEGORY_ACTION) {
223
223
  return t("ACTION_MESSAGE") || "Action";
224
+ } else if (messageCategory === CometChat.CATEGORY_CARD) {
225
+ // Developer card preview: getText() if present, else localized "Card Message".
226
+ const cardMessage = message as any;
227
+ const cardText =
228
+ (typeof cardMessage.getText === "function" && cardMessage.getText()) ||
229
+ "";
230
+ return cardText || t("CARD_MESSAGE") || "Card Message";
224
231
  }
225
232
 
226
233
  return t("MESSAGE") || "Message";
@@ -49,6 +49,14 @@ export class CometChatConversationUtils {
49
49
  );
50
50
  }
51
51
 
52
+ if (lastMessage.getCategory() === MessageCategoryConstants.card) {
53
+ const cardText =
54
+ (typeof (lastMessage as any).getText === "function" && (lastMessage as any).getText()) ||
55
+ t("CARD_MESSAGE") ||
56
+ "Card Message";
57
+ return cardText;
58
+ }
59
+
52
60
  if (lastMessage.getCategory() == "call") {
53
61
  let color: ColorValue | undefined = theme?.color?.textSecondary;
54
62
  let text = "Video call";
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Strip rich-text formatting (HTML formatting tags + markdown markers) from a
3
+ * string and return plain text. For compact single-line previews such as the AI
4
+ * chat-history list, where formatting must NOT render.
5
+ *
6
+ * Only a whitelist of known formatting tags is removed, so legitimate text such
7
+ * as "make a <product>" or "5 < 10" is preserved.
8
+ */
9
+ export const stripRichText = (input?: string | null): string => {
10
+ if (!input) return "";
11
+ let text = input;
12
+
13
+ // 1. Remove the HTML formatting tags the compact composer can emit — bold, italic,
14
+ // underline, strikethrough, link, ordered/unordered lists, blockquote, inline code
15
+ // and code-block, plus the structural wrappers these produce. Whitelisted (not a
16
+ // blanket strip) so genuine angle-bracket text like "make a <product>" survives.
17
+ // Replaced with a space so adjacent list items / blocks don't get word-joined; the
18
+ // whitespace is collapsed in step 3.
19
+ text = text.replace(
20
+ /<\/?(?:b|strong|i|em|u|ins|s|strike|del|a|ol|ul|li|blockquote|code|pre|p|br|div|span|font|h[1-6])\b[^>]*>/gi,
21
+ " "
22
+ );
23
+
24
+ // 2. Strip markdown markers (keep inner text), covering the same set of formats in
25
+ // case the text carries markdown instead of / alongside HTML.
26
+ text = text
27
+ .replace(/```[a-z]*\s*([\s\S]*?)```/gi, "$1") // ```code block```
28
+ .replace(/(\*\*\*|___)(.+?)\1/g, "$2") // ***bold italic***
29
+ .replace(/(\*\*|__)(.+?)\1/g, "$2") // **bold** / __bold/underline__
30
+ // *italic* / _italic_ — boundary-aware (capture the leading boundary instead of a
31
+ // lookbehind, which Hermes/RN doesn't reliably support) so snake_case identifiers
32
+ // like "my_var_name" and "a * b" arithmetic are left untouched.
33
+ .replace(/(^|[^A-Za-z0-9*])\*\s*(.+?)\s*\*(?![A-Za-z0-9*])/g, "$1$2") // *italic*
34
+ .replace(/(^|[^A-Za-z0-9_])_\s*(.+?)\s*_(?![A-Za-z0-9_])/g, "$1$2") // _italic_
35
+ .replace(/~~(.+?)~~/g, "$1") // ~~strikethrough~~
36
+ .replace(/`([^`]+)`/g, "$1") // `inline code`
37
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1"); // [label](url) -> label
38
+
39
+ // 3. Collapse leftover whitespace into a single clean line.
40
+ return text.replace(/\s+/g, " ").trim();
41
+ };
@@ -1,9 +1,11 @@
1
- import React, { useRef, useEffect, useMemo } from 'react';
2
- import { View, Text, StyleSheet, Animated } from 'react-native';
1
+ import React, { useMemo } from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
3
  import Markdown from 'react-native-markdown-display';
4
4
  import { CometChat } from '@cometchat/chat-sdk-react-native';
5
+ import { CometChatCardView } from '@cometchat/cards-react-native';
5
6
  import { useTheme } from '../../../theme';
6
7
  import { CometChatTheme } from '../../../theme/type';
8
+ import { CometChatUIEventHandler, CometChatUIEvents } from '../../events';
7
9
 
8
10
  export interface CometChatAIAssistantMessageBubbleProps {
9
11
  message: any;
@@ -34,53 +36,39 @@ const CometChatAIAssistantMessageBubble: React.FC<CometChatAIAssistantMessageBub
34
36
  const theme = useTheme();
35
37
  const text = getMessageText(message);
36
38
 
39
+ // Check if message has elements (agent card blocks)
40
+ const elements: any[] | undefined = useMemo(() => {
41
+ try {
42
+ if (typeof message?.getElements === 'function') {
43
+ const els = message.getElements();
44
+ if (Array.isArray(els) && els.length > 0) return els;
45
+ }
46
+ } catch {}
47
+ return undefined;
48
+ }, [message]);
49
+
50
+ const resolvedThemeMode: "light" | "dark" =
51
+ theme?.mode === "dark" ? "dark" : "light";
52
+
37
53
  // Use the bubbleStyle passed from parent, with theme fallbacks
38
- const styles = StyleSheet.create({
54
+ const styles = useMemo(() => StyleSheet.create({
39
55
  container: {
40
56
  backgroundColor: bubbleStyle?.containerStyle?.backgroundColor || 'transparent',
41
57
  borderRadius: bubbleStyle?.containerStyle?.borderRadius || theme.spacing.radius.r3,
42
58
  minWidth: bubbleStyle?.containerStyle?.minWidth || 90,
43
59
  alignSelf: bubbleStyle?.containerStyle?.alignSelf || 'flex-start',
44
60
  maxWidth: '100%',
61
+ overflow: 'hidden',
45
62
  ...bubbleStyle?.containerStyle,
46
63
  },
47
- textContainer: {
48
- ...bubbleStyle?.textContainerStyle,
49
- },
50
- text: {
51
- color: bubbleStyle?.textStyle?.color || theme.color.receiveBubbleText,
52
- fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
53
- fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
54
- ...bubbleStyle?.textStyle,
55
- },
56
- placeholderText: {
57
- color: bubbleStyle?.placeholderTextStyle?.color || theme.color.receiveBubbleText,
58
- fontFamily: bubbleStyle?.placeholderTextStyle?.fontFamily || theme.typography.body.regular.fontFamily,
59
- fontSize: bubbleStyle?.placeholderTextStyle?.fontSize || theme.typography.body.regular.fontSize,
60
- opacity: bubbleStyle?.placeholderTextStyle?.opacity || 0.6,
61
- fontStyle: 'italic',
62
- ...bubbleStyle?.placeholderTextStyle,
64
+ cardBlock: {
65
+ alignSelf: 'stretch',
66
+ overflow: 'visible',
67
+ borderRadius: theme.spacing.radius.r3,
68
+ marginVertical: 8,
69
+ marginHorizontal: -4,
63
70
  },
64
- copyButton: {
65
- backgroundColor: bubbleStyle?.copyButtonStyle?.backgroundColor || theme.color.primary,
66
- padding: bubbleStyle?.copyButtonStyle?.padding || theme.spacing.padding.p1,
67
- borderRadius: bubbleStyle?.copyButtonStyle?.borderRadius || theme.spacing.radius.r1,
68
- ...bubbleStyle?.copyButtonStyle,
69
- },
70
- errorContainer: {
71
- backgroundColor: bubbleStyle?.errorContainerStyle?.backgroundColor || theme.color.error,
72
- padding: bubbleStyle?.errorContainerStyle?.padding || theme.spacing.padding.p2,
73
- borderRadius: bubbleStyle?.errorContainerStyle?.borderRadius || theme.spacing.radius.r2,
74
- marginTop: bubbleStyle?.errorContainerStyle?.marginTop || theme.spacing.margin.m1,
75
- ...bubbleStyle?.errorContainerStyle,
76
- },
77
- errorText: {
78
- color: bubbleStyle?.errorTextStyle?.color || theme.color.background1,
79
- fontFamily: bubbleStyle?.errorTextStyle?.fontFamily || theme.typography.caption1.regular.fontFamily,
80
- fontSize: bubbleStyle?.errorTextStyle?.fontSize || theme.typography.caption1.regular.fontSize,
81
- ...bubbleStyle?.errorTextStyle,
82
- },
83
- });
71
+ }), [bubbleStyle, theme]);
84
72
 
85
73
  // Create markdown styles based on theme
86
74
  const markdownStyles = useMemo(() => ({
@@ -97,7 +85,7 @@ const CometChatAIAssistantMessageBubble: React.FC<CometChatAIAssistantMessageBub
97
85
  fontFamily: bubbleStyle?.textStyle?.fontFamily || theme.typography.body.regular.fontFamily,
98
86
  fontSize: bubbleStyle?.textStyle?.fontSize || theme.typography.body.regular.fontSize,
99
87
  ...(bubbleStyle?.textStyle && Object.fromEntries(
100
- Object.entries(bubbleStyle.textStyle).filter(([key]) => key !== 'color')
88
+ Object.entries(bubbleStyle.textStyle).filter(([key]: [string, any]) => key !== 'color')
101
89
  )),
102
90
  },
103
91
  paragraph: {
@@ -246,17 +234,88 @@ const CometChatAIAssistantMessageBubble: React.FC<CometChatAIAssistantMessageBub
246
234
  },
247
235
  }), [bubbleStyle?.textStyle, theme]);
248
236
 
249
- const MemoMarkdown = useMemo(() => {
237
+ // Handle card action from a nested agent-card block (event-only, no prop).
238
+ const handleCardAction = (actionEvent: any) => {
239
+ // Renderer emits { action, elementId, cardJson }. Forward the raw action.
240
+ const action = actionEvent?.action ?? actionEvent;
241
+ if (!action) return;
242
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccCardActionClicked, {
243
+ message,
244
+ action,
245
+ });
246
+ };
247
+
248
+ // Render elements walk (§2.7(b)): when getElements() is non-empty, walk
249
+ // blocks in array order, switch on element.getType().
250
+ const renderElements = useMemo(() => {
251
+ if (!elements) return null;
252
+ return elements.map((element: any, index: number) => {
253
+ const type = typeof element.getType === 'function' ? element.getType() : element.type;
254
+ const data = typeof element.getData === 'function' ? element.getData() : element.value;
255
+
256
+ if (type === 'card') {
257
+ // data is { card: {...}, cardId: "..." }
258
+ const cardPayload = data?.card;
259
+ if (!cardPayload) {
260
+ // Empty/invalid block payload (§2.8): skip the renderer and fall back to
261
+ // the block's fallbackText, else the block's text. Other blocks render normally.
262
+ const blockFallback = data?.fallbackText ?? data?.text ?? '';
263
+ if (!blockFallback || !String(blockFallback).trim()) return null;
264
+ return (
265
+ <View key={`card-fb-${index}`} style={{ marginTop: index > 0 ? 8 : 0 }}>
266
+ <Markdown style={markdownStyles} mergeStyle={true}>
267
+ {String(blockFallback).trim()}
268
+ </Markdown>
269
+ </View>
270
+ );
271
+ }
272
+ const cardJson = JSON.stringify(cardPayload);
273
+ return (
274
+ <View key={`card-${index}`} style={styles.cardBlock}>
275
+ <CometChatCardView
276
+ cardJson={cardJson}
277
+ themeMode={resolvedThemeMode}
278
+ onAction={handleCardAction}
279
+ />
280
+ </View>
281
+ );
282
+ }
283
+
284
+ if (type === 'text') {
285
+ // data is the text string
286
+ const textContent = typeof data === 'string' ? data : (data?.text ?? '');
287
+ if (!textContent.trim()) return null;
288
+ return (
289
+ <View key={`text-${index}`} style={{ marginTop: index > 0 ? 8 : 0 }}>
290
+ <Markdown style={markdownStyles} mergeStyle={true}>
291
+ {textContent.trim()}
292
+ </Markdown>
293
+ </View>
294
+ );
295
+ }
296
+
297
+ // Other element types — skip for now (renderer owns unknown handling)
298
+ return null;
299
+ });
300
+ }, [elements, styles, markdownStyles, resolvedThemeMode, message]);
301
+
302
+ // If elements are present, render them in order. Otherwise fall back to getText().
303
+ if (elements) {
250
304
  return (
251
305
  <View style={styles.container}>
252
- <Markdown style={markdownStyles} mergeStyle={true}>
253
- {text.trim()}
254
- </Markdown>
306
+ {renderElements}
255
307
  </View>
256
- )
257
- }, [text, markdownStyles, styles]);
308
+ );
309
+ }
258
310
 
259
- return MemoMarkdown;
311
+ // Fallback: existing getText() rendering (older messages without elements)
312
+ return (
313
+ <View style={styles.container}>
314
+ <Markdown style={markdownStyles} mergeStyle={true}>
315
+ {text.trim()}
316
+ </Markdown>
317
+ </View>
318
+ );
260
319
  };
261
320
 
262
- export default CometChatAIAssistantMessageBubble;
321
+ export default CometChatAIAssistantMessageBubble;
@@ -0,0 +1,118 @@
1
+ import React, { useMemo } from "react";
2
+ import { StyleSheet, Text, View } from "react-native";
3
+ import { CometChatCardView } from "@cometchat/cards-react-native";
4
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
5
+ import { useTheme } from "../../../theme";
6
+ import { CometChatUIEventHandler, CometChatUIEvents } from "../../events";
7
+ import { useCometChatTranslation } from "../../resources/CometChatLocalizeNew";
8
+
9
+ export interface CometChatCardBubbleProps {
10
+ /** The card message to render (CometChat.CardMessage). */
11
+ message: any;
12
+ /** Theme override; falls back to the current UIKit theme. */
13
+ theme?: any;
14
+ /** Renderer theme mode. Defaults to the active UIKit theme mode. */
15
+ themeMode?: "auto" | "light" | "dark";
16
+ /**
17
+ * Fired when an action inside the card is tapped. Receives the owning
18
+ * message and the raw renderer action. The kit performs no behavior itself.
19
+ */
20
+ onCardAction?: (message: any, action: any) => void;
21
+ }
22
+
23
+ /**
24
+ * CometChatCardBubble
25
+ *
26
+ * First-party, render-only bubble for developer cards (`category: "card"`).
27
+ * Sits inside the SAME standard message-bubble container as TextBubble
28
+ * (receipts, reactions, long-press, reply, thread all work unchanged).
29
+ *
30
+ * Feeds the raw `getCard()` payload to the prebuilt `CometChatCardView`
31
+ * renderer and forwards any tapped action via both the `onCardAction` prop
32
+ * and the `ccCardActionClicked` UI event. Zero transformation in the kit.
33
+ */
34
+ const CometChatCardBubble: React.FC<CometChatCardBubbleProps> = ({
35
+ message,
36
+ themeMode,
37
+ onCardAction,
38
+ }) => {
39
+ const theme = useTheme();
40
+ const { t } = useCometChatTranslation();
41
+
42
+ const resolvedThemeMode: "auto" | "light" | "dark" =
43
+ themeMode ?? (theme?.mode === "dark" ? "dark" : "light");
44
+
45
+ // Raw card payload from the SDK. Pass untouched (stringified) to the renderer.
46
+ const rawCard = useMemo(() => {
47
+ try {
48
+ return typeof message?.getCard === "function" ? message.getCard() : undefined;
49
+ } catch {
50
+ return undefined;
51
+ }
52
+ }, [message]);
53
+
54
+ const isEmptyCard =
55
+ rawCard == null || (typeof rawCard === "object" && Object.keys(rawCard).length === 0);
56
+
57
+ // Empty/invalid card → fallbackText → text → "Card Message" (don't render an empty schema).
58
+ if (isEmptyCard) {
59
+ const fallback =
60
+ (typeof message?.getFallbackText === "function" && message.getFallbackText()) ||
61
+ (typeof message?.getText === "function" && message.getText()) ||
62
+ t("CARD_MESSAGE") ||
63
+ "Card Message";
64
+ return (
65
+ <View style={styles.fallbackContainer}>
66
+ <Text
67
+ style={{
68
+ color: theme.color.receiveBubbleText,
69
+ fontFamily: theme.typography.body.regular.fontFamily,
70
+ fontSize: theme.typography.body.regular.fontSize,
71
+ }}
72
+ >
73
+ {fallback}
74
+ </Text>
75
+ </View>
76
+ );
77
+ }
78
+
79
+ const cardJson = JSON.stringify(rawCard);
80
+
81
+ const handleAction = (actionEvent: any) => {
82
+ // Renderer emits { action, elementId, cardJson }. Forward the raw inner action
83
+ // (spec §2.6 — forward raw, no reshaping). Fall back to actionEvent itself for
84
+ // older renderer versions that emit a flat shape.
85
+ const action = actionEvent?.action ?? actionEvent;
86
+ if (!action) return;
87
+ // (1) prop — for apps that render the card bubble directly.
88
+ onCardAction?.(message, action);
89
+ // (2) event bus — the channel that also reaches nested (agent) cards.
90
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccCardActionClicked, {
91
+ message,
92
+ action,
93
+ });
94
+ };
95
+
96
+ return (
97
+ <View style={styles.cardContainer}>
98
+ <CometChatCardView
99
+ cardJson={cardJson}
100
+ themeMode={resolvedThemeMode}
101
+ onAction={handleAction}
102
+ />
103
+ </View>
104
+ );
105
+ };
106
+
107
+ const styles = StyleSheet.create({
108
+ cardContainer: {
109
+ // Fill the standard bubble container width (bubble already caps at ~80% of screen).
110
+ alignSelf: "stretch",
111
+ overflow: "hidden",
112
+ },
113
+ fallbackContainer: {
114
+ paddingVertical: 4,
115
+ },
116
+ });
117
+
118
+ export default CometChatCardBubble;
@@ -0,0 +1,2 @@
1
+ export { default as CometChatCardBubble } from "./CometChatCardBubble";
2
+ export type { CometChatCardBubbleProps } from "./CometChatCardBubble";
@@ -2,9 +2,11 @@ import React, { useState, useEffect, useRef, useCallback, memo, useMemo } from '
2
2
  import { View, Text, StyleSheet, Animated, TouchableOpacity } from 'react-native';
3
3
  import Markdown from 'react-native-markdown-display';
4
4
  import { CometChat } from '@cometchat/chat-sdk-react-native';
5
+ import { CometChatCardView } from '@cometchat/cards-react-native';
5
6
  import { useTheme } from '../../../theme';
6
7
  import { messageStream, streamingState$, IStreamData, getAIAssistantTools, stopStreamingForRunId, handleWebsocketMessage, startStreamingForRunId, streamConnection$, notifyStreamRenderComplete } from '../../services/stream-message.service';
7
8
  import { CometChatUiKitConstants } from '../../index';
9
+ import { CometChatUIEventHandler, CometChatUIEvents } from '../../events';
8
10
 
9
11
  export interface CometChatStreamMessageBubbleProps {
10
12
  message: any;
@@ -26,6 +28,7 @@ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps>
26
28
  const [contentStreamStarted, setContentStreamStarted] = useState(false);
27
29
  const [runStarted, setRunStarted] = useState(false);
28
30
  const [showingExecutionText, setShowingExecutionText] = useState(false);
31
+ const [streamCards, setStreamCards] = useState<{ cardId: string; cardJson: string }[]>([]);
29
32
  const shimmerAnimation = useRef(new Animated.Value(-1)).current;
30
33
  const theme = useTheme();
31
34
  const [connectionStatus, setConnectionStatus] = useState<'connected' | 'disconnected' | 'error'>('connected');
@@ -43,6 +46,13 @@ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps>
43
46
  CometChatUiKitConstants.streamMessageTypes.tool_call_result,
44
47
  CometChatUiKitConstants.streamMessageTypes.tool_call_start
45
48
  ];
49
+
50
+ // Card stream events mapping
51
+ const cardEventsMap = [
52
+ CometChatUiKitConstants.streamMessageTypes.card_start,
53
+ CometChatUiKitConstants.streamMessageTypes.card,
54
+ CometChatUiKitConstants.streamMessageTypes.card_end,
55
+ ];
46
56
  useEffect(() => {
47
57
  if (finished && fullMessage && contentStreamStarted) {
48
58
  setRenderComplete(true);
@@ -127,6 +137,40 @@ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps>
127
137
  }
128
138
  }
129
139
 
140
+ // Handle card stream events (§2.6.2)
141
+ if (cardEventsMap.includes(eventType)) {
142
+ if (eventType === CometChatUiKitConstants.streamMessageTypes.card_start) {
143
+ // Show skeleton loader with executionText label
144
+ const execText = streamData.message.getData()?.executionText;
145
+ if (execText) {
146
+ setExecutionText(execText);
147
+ } else {
148
+ setExecutionText('Building card...');
149
+ }
150
+ setShowingExecutionText(true);
151
+ setContentStreamStarted(false);
152
+ }
153
+ if (eventType === CometChatUiKitConstants.streamMessageTypes.card_end) {
154
+ // No-op: the persisted message swap handles the rest
155
+ setShowingExecutionText(false);
156
+ setExecutionText('');
157
+ }
158
+ if (eventType === CometChatUiKitConstants.streamMessageTypes.card) {
159
+ const ev: any = streamData.message;
160
+ const cardObj = ev.getCard?.() ?? ev.getData?.()?.card;
161
+ const cardId: string = ev.getData?.()?.cardId ?? `${streamData.message.getMessageId?.()}`;
162
+ if (cardObj) {
163
+ const cardJson = typeof cardObj === 'string' ? cardObj : JSON.stringify(cardObj);
164
+ setStreamCards((prev) => [
165
+ ...prev.filter((c) => c.cardId !== cardId),
166
+ { cardId, cardJson },
167
+ ]);
168
+ }
169
+ setShowingExecutionText(false);
170
+ setExecutionText('');
171
+ }
172
+ }
173
+
130
174
  setData(streamData.message);
131
175
 
132
176
  if (streamData.streamedMessages !== undefined) {
@@ -492,6 +536,25 @@ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps>
492
536
 
493
537
  {fullMessage && contentStreamStarted && MemoMarkdown}
494
538
 
539
+ {streamCards.length > 0 && streamCards.map((card) => (
540
+ <View key={card.cardId} style={{ alignSelf: 'stretch', marginTop: 8, overflow: 'hidden', borderRadius: theme.spacing.radius.r3 }}>
541
+ <CometChatCardView
542
+ cardJson={card.cardJson}
543
+ themeMode={theme?.mode === 'dark' ? 'dark' : 'light'}
544
+ onAction={(actionEvent: any) => {
545
+ // Renderer emits { action, elementId, cardJson }. Forward the raw action.
546
+ const action = actionEvent?.action ?? actionEvent;
547
+ if (action) {
548
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccCardActionClicked, {
549
+ message: data,
550
+ action,
551
+ });
552
+ }
553
+ }}
554
+ />
555
+ </View>
556
+ ))}
557
+
495
558
  {hasError && (
496
559
  <View style={styles.errorContainer}>
497
560
  <Text style={styles.errorText}>No internet connection. Please check your connection and try again.</Text>
@@ -12,6 +12,7 @@ import {
12
12
  CometChatTextBubble,
13
13
  CometChatTextBubbleInterface,
14
14
  } from "./CometChatTextBubble";
15
+ import { CometChatCardBubble } from "./CometChatCardBubble";
15
16
  import {
16
17
  CometChatVideoBubble,
17
18
  CometChatVideoBubbleInterface
@@ -177,6 +178,7 @@ export {
177
178
  CometChatTextBubble,
178
179
  CometChatVideoBubble,
179
180
  SuggestionItem,
181
+ CometChatCardBubble,
180
182
  CometChatNewMessageIndicator,
181
183
  CometChatInlineAudioRecorder,
182
184
  formatDuration,
@@ -1,154 +0,0 @@
1
- # Manual Test Cases — `loadLastAgentConversation`
2
-
3
- ## Prerequisites
4
- - An `@agentic` user configured in your CometChat dashboard
5
- - The example app running with `loadLastAgentConversation={true}` on `CometChatMessageList`
6
- - At least one previous conversation with the agent (send a message, get a response)
7
-
8
- ---
9
-
10
- ## TC-1: Auto-loads last conversation on open
11
-
12
- **Steps:**
13
- 1. Have at least one previous conversation with the agent (send "Hello", wait for reply)
14
- 2. Navigate away from the agent chat (go back to conversation list)
15
- 3. Open the agent chat again
16
-
17
- **Expected:**
18
- - A loading indicator appears briefly
19
- - The previous conversation messages load automatically
20
- - You see your last messages and the agent's responses
21
-
22
- ---
23
-
24
- ## TC-2: Shows greeting/empty state when no previous conversation exists
25
-
26
- **Steps:**
27
- 1. Use a fresh `@agentic` user with no message history (or use a new logged-in user who hasn't chatted with the agent)
28
- 2. Open the agent chat
29
-
30
- **Expected:**
31
- - The agent greeting view appears (avatar, greeting message, suggested messages)
32
- - No loading spinner hangs indefinitely
33
-
34
- ---
35
-
36
- ## TC-3: "New Chat" button from header shows empty state
37
-
38
- **Steps:**
39
- 1. Open the agent chat (previous conversation auto-loads)
40
- 2. Tap the "New Chat" button (pencil/compose icon) in the header
41
-
42
- **Expected:**
43
- - The screen resets to the greeting/empty state
44
- - The previous conversation is NOT re-loaded
45
- - You can type a fresh message to start a new conversation
46
-
47
- ---
48
-
49
- ## TC-4: "New Chat" button from Chat History drawer works
50
-
51
- **Steps:**
52
- 1. Open the agent chat
53
- 2. Tap the "Chat History" button in the header to open the history drawer
54
- 3. Tap the "New Chat" button inside the history drawer
55
-
56
- **Expected:**
57
- - The history drawer closes
58
- - The message list resets to greeting/empty state
59
- - The previous conversation is NOT re-loaded
60
-
61
- ---
62
-
63
- ## TC-5: Loading a specific conversation from Chat History still works
64
-
65
- **Steps:**
66
- 1. Open the agent chat (previous conversation auto-loads)
67
- 2. Tap the "Chat History" button in the header
68
- 3. Tap on a specific past conversation from the list
69
-
70
- **Expected:**
71
- - The selected conversation loads with all its messages
72
- - Streaming/responses still work if you send a new message in that thread
73
-
74
- ---
75
-
76
- ## TC-6: Sending a new message after "New Chat" starts a new thread
77
-
78
- **Steps:**
79
- 1. Open the agent chat (previous conversation auto-loads)
80
- 2. Tap "New Chat" (message list resets to empty)
81
- 3. Type and send a message (e.g., "What's the weather?")
82
-
83
- **Expected:**
84
- - Your message appears in the list
85
- - A streaming indicator shows while the agent responds
86
- - The agent's reply appears correctly
87
- - This is now a NEW conversation thread (not appended to the old one)
88
-
89
- ---
90
-
91
- ## TC-7: Re-opening after new chat shows the NEW conversation
92
-
93
- **Steps:**
94
- 1. Complete TC-6 (start a new chat, send message, get reply)
95
- 2. Navigate away from the agent chat
96
- 3. Open the agent chat again
97
-
98
- **Expected:**
99
- - The most recent conversation (from step 1-2) auto-loads
100
- - You see the "What's the weather?" message and the agent's response
101
- - NOT the older conversation from before
102
-
103
- ---
104
-
105
- ## TC-8: `loadLastAgentConversation={false}` preserves existing behavior
106
-
107
- **Steps:**
108
- 1. Change the prop to `loadLastAgentConversation={false}` (or remove it) in Messages.tsx
109
- 2. Open the agent chat (even with previous conversations)
110
-
111
- **Expected:**
112
- - The greeting/empty state shows immediately
113
- - No automatic loading of previous conversation
114
- - Behaves exactly as before this feature was added
115
-
116
- ---
117
-
118
- ## TC-9: Non-agentic users are unaffected
119
-
120
- **Steps:**
121
- 1. With `loadLastAgentConversation={true}` still set
122
- 2. Open a regular (non-agentic) user chat that has message history
123
-
124
- **Expected:**
125
- - Messages load normally (standard behavior)
126
- - No change in behavior — the prop only applies to `@agentic` users
127
-
128
- ---
129
-
130
- ## TC-10: Scroll up to load older messages in auto-loaded conversation
131
-
132
- **Steps:**
133
- 1. Have a long conversation history with the agent (30+ messages)
134
- 2. Open the agent chat (auto-loads last conversation)
135
- 3. Scroll up to the top of the loaded messages
136
-
137
- **Expected:**
138
- - Older messages load (pagination works)
139
- - No crash or infinite spinner
140
- - The loading indicator appears at the top while fetching
141
-
142
- ---
143
-
144
- ## TC-11: Delete all history from Chat History panel
145
-
146
- **Steps:**
147
- 1. Open the agent chat
148
- 2. Open Chat History drawer
149
- 3. Long-press and delete all conversations one by one until none remain
150
-
151
- **Expected:**
152
- - When the last conversation is deleted, the list shows empty state
153
- - The message list resets to greeting/empty view
154
- - Re-opening the chat shows greeting (no conversation to auto-load)