The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { AiChatErrorRenderer } from '@/ai/components/AiChatErrorRenderer';
import { AGENT_MESSAGE_ROLE } from '@/ai/constants/AgentMessageRole';
import { agentChatDisplayedThreadState } from '@/ai/states/agentChatDisplayedThreadState';
import { agentChatErrorFamilyState } from '@/ai/states/agentChatErrorFamilyState';
import { agentChatIsStreamingFamilyState } from '@/ai/states/agentChatIsStreamingFamilyState';
import { agentChatMessageFamilySelector } from '@/ai/states/selectors/agentChatMessageFamilySelector';
import { agentChatMessageIdsSelector } from '@/ai/states/selectors/agentChatMessageIdsSelector';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { styled } from '@linaria/react';
import { themeCssVariables } from 'twenty-ui/theme';
import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
const StyledErrorWrapper = styled.div`
padding-top: ${themeCssVariables.spacing[3]};
`;
export const AiChatErrorUnderMessageList = () => {
const agentChatDisplayedThread = useAtomStateValue(
agentChatDisplayedThreadState,
);
const agentChatError = useAtomFamilyStateValue(agentChatErrorFamilyState, {
threadId: agentChatDisplayedThread,
});
const agentChatIsStreaming = useAtomFamilyStateValue(
agentChatIsStreamingFamilyState,
{ threadId: agentChatDisplayedThread },
);
const agentChatMessageIds = useAtomStateValue(agentChatMessageIdsSelector);
const lastMessageId = agentChatMessageIds.at(-1);
const agentChatMessage = useAtomFamilySelectorValue(
agentChatMessageFamilySelector,
{ messageId: lastMessageId },
);
const showError =
agentChatError &&
!agentChatIsStreaming &&
agentChatMessage?.role === AGENT_MESSAGE_ROLE.USER;
if (!showError) {
return null;
}
return (
<StyledErrorWrapper>
<AiChatErrorRenderer error={agentChatError} />
</StyledErrorWrapper>
);
};