forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssistantMessage.tsx
More file actions
73 lines (69 loc) · 2.08 KB
/
Copy pathAssistantMessage.tsx
File metadata and controls
73 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from "react";
import { View, Text, StyleSheet, type ViewStyle } from "react-native";
import { CopilotMarkdown } from "../Markdown";
import { TypingIndicator } from "./TypingIndicator";
import { formatTimestamp } from "./utils";
// ─── Colors ──────────────────────────────────────────────────────────────────
const ASSISTANT_BUBBLE_BG = "#F0F0F0";
const ASSISTANT_TEXT_COLOR = "#1A1A1A";
const TIMESTAMP_COLOR = "#999999";
/**
* Props for the AssistantMessage component.
*/
export interface AssistantMessageProps {
/** Markdown content to render inside the bubble */
content: string;
/** When true, shows a typing indicator instead of content */
isLoading?: boolean;
/** Optional timestamp displayed below the bubble */
timestamp?: Date;
/** Optional style override for the outer container */
style?: ViewStyle;
}
/**
* Left-aligned chat bubble for AI assistant responses.
*
* Renders markdown content via `CopilotMarkdown` and shows an animated
* typing indicator when `isLoading` is true.
*/
export function AssistantMessage({
content,
isLoading = false,
timestamp,
style,
}: AssistantMessageProps) {
return (
<View style={[styles.container, style]}>
<View style={styles.bubble}>
{content ? <CopilotMarkdown content={content} /> : null}
{isLoading ? <TypingIndicator /> : null}
</View>
{timestamp && (
<Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
alignItems: "flex-start",
marginVertical: 4,
paddingHorizontal: 12,
},
bubble: {
backgroundColor: ASSISTANT_BUBBLE_BG,
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
borderBottomRightRadius: 16,
borderBottomLeftRadius: 4,
paddingHorizontal: 12,
paddingVertical: 8,
maxWidth: "80%",
},
timestamp: {
color: TIMESTAMP_COLOR,
fontSize: 11,
marginTop: 2,
marginLeft: 4,
},
});