-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathAIChatErrorUnderMessageList.tsx
More file actions
45 lines (38 loc) · 1.79 KB
/
AIChatErrorUnderMessageList.tsx
File metadata and controls
45 lines (38 loc) · 1.79 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
import { AIChatErrorRenderer } from '@/ai/components/AIChatErrorRenderer';
import { AgentMessageRole } from '@/ai/constants/AgentMessageRole';
import { agentChatErrorState } from '@/ai/states/agentChatErrorState';
import { agentChatIsStreamingState } from '@/ai/states/agentChatIsStreamingState';
import { agentChatMessageComponentFamilySelector } from '@/ai/states/agentChatMessageComponentFamilySelector';
import { agentChatMessageIdsComponentSelector } from '@/ai/states/agentChatMessageIdsComponentSelector';
import { useAtomComponentFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentFamilySelectorValue';
import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { styled } from '@linaria/react';
import { themeCssVariables } from 'twenty-ui/theme-constants';
const StyledErrorWrapper = styled.div`
padding-top: ${themeCssVariables.spacing[3]};
`;
export const AIChatErrorUnderMessageList = () => {
const agentChatError = useAtomStateValue(agentChatErrorState);
const agentChatIsStreaming = useAtomStateValue(agentChatIsStreamingState);
const agentChatMessageIds = useAtomComponentSelectorValue(
agentChatMessageIdsComponentSelector,
);
const lastMessageId = agentChatMessageIds.at(-1);
const agentChatMessage = useAtomComponentFamilySelectorValue(
agentChatMessageComponentFamilySelector,
{ messageId: lastMessageId },
);
const showError =
agentChatError &&
!agentChatIsStreaming &&
agentChatMessage?.role === AgentMessageRole.USER;
if (!showError) {
return null;
}
return (
<StyledErrorWrapper>
<AIChatErrorRenderer error={agentChatError} />
</StyledErrorWrapper>
);
};