-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchat-single-message.tsx
More file actions
109 lines (100 loc) · 3.27 KB
/
chat-single-message.tsx
File metadata and controls
109 lines (100 loc) · 3.27 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { useChatStore } from '@/components/providers/chat-store-provider';
import type { PartyDetails } from '@/lib/party-details';
import type {
MessageItem,
VoiceTranscriptionStatus,
} from '@/lib/stores/chat-store.types';
import { cn } from '@/lib/utils';
import ChatMarkdown from './chat-markdown';
import { ChatMessageIcon } from './chat-message-icon';
import ChatProConExpandable from './chat-pro-con-expandable';
import ChatSingleMessageActions from './chat-single-message-actions';
import ChatSingleUserMessage from './chat-single-user-message';
import ChatVotingBehaviorExpandable from './chat-voting-behavior-expandable';
import MessageLoadingBorderTrail from './message-loading-border-trail';
import SurveyBanner from './survey-banner';
type Props = {
message: MessageItem;
partyId?: string;
party?: PartyDetails;
isLastMessage?: boolean;
showAssistantIcon?: boolean;
showMessageActions?: boolean;
isGroupChat?: boolean;
voiceTranscriptionStatus?: VoiceTranscriptionStatus;
};
function ChatSingleMessage({
message,
partyId,
party,
isLastMessage,
showAssistantIcon = true,
showMessageActions = true,
isGroupChat = false,
voiceTranscriptionStatus,
}: Props) {
const isLoadingAnyAction = useChatStore(
(state) =>
state.loading.proConPerspective === message.id ||
state.loading.votingBehaviorSummary === message.id,
);
const shouldHaveBackground =
message.pro_con_perspective ||
message.voting_behavior ||
isLoadingAnyAction;
const content = (
<div className="flex flex-col gap-4">
<ChatMarkdown message={message} />
</div>
);
if (message.role === 'user') {
return (
<ChatSingleUserMessage
message={message}
isLastMessage={isLastMessage ?? false}
voiceTranscriptionStatus={voiceTranscriptionStatus}
/>
);
}
if (message.role === 'assistant') {
return (
<article
id={message.id}
className={cn(
'flex flex-col gap-4 relative transition-all duration-200 ease-out',
shouldHaveBackground && 'bg-zinc-100 dark:bg-zinc-900 group',
!isGroupChat &&
shouldHaveBackground &&
'border border-muted p-3 md:p-4 rounded-lg',
)}
data-has-message-background={Boolean(shouldHaveBackground)}
>
<div className={cn('flex items-start justify-start gap-3 md:gap-4')}>
{showAssistantIcon && (
<ChatMessageIcon partyId={partyId} party={party} />
)}
<div className="flex flex-col gap-2">
{content}
{isLastMessage && <SurveyBanner />}
<ChatSingleMessageActions
isLastMessage={isLastMessage}
message={message}
partyId={partyId}
showMessageActions={showMessageActions}
isGroupChat={isGroupChat}
/>
</div>
</div>
<ChatProConExpandable message={message} isGroupChat={isGroupChat} />
<ChatVotingBehaviorExpandable
message={message}
isGroupChat={isGroupChat}
/>
{isLoadingAnyAction && !isGroupChat && <MessageLoadingBorderTrail />}
</article>
);
}
return <ChatMarkdown message={message} />;
}
ChatSingleMessage.displayName = 'ChatSingleMessage';
export default ChatSingleMessage;