Skip to content

Commit

Permalink
[Security Solution] Fix skip intro for elastic assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
lgestc committed Jul 12, 2023
1 parent 665b887 commit c1ab91d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ const AssistantComponent: React.FC<Props> = ({
return doesConversationHaveMessages
? {
...conversation,
messages: [
...conversation.messages,
...BASE_CONVERSATIONS[WELCOME_CONVERSATION_TITLE].messages,
],
messages: [...conversation.messages],
}
: {
...conversation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface StreamingTextProps {
children?: (text: string, isStreamingComplete: boolean) => React.ReactNode;
chunkSize?: number;
delay?: number;
onStreamingComplete?: () => void;
onStreamingComplete: () => void;
}

export const StreamingText: React.FC<StreamingTextProps> = React.memo<StreamingTextProps>(
Expand All @@ -22,7 +22,7 @@ export const StreamingText: React.FC<StreamingTextProps> = React.memo<StreamingT

useEffect(() => {
if (delay === 0) {
onStreamingComplete?.();
onStreamingComplete();
}
// Only run on initial render so onStreamingComplete is only called once if delay is 0
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -37,7 +37,7 @@ export const StreamingText: React.FC<StreamingTextProps> = React.memo<StreamingT
setIsStreamingComplete(false);
const interval = setInterval(() => {
if (currentPos >= text.length) {
onStreamingComplete?.();
onStreamingComplete();
setIsStreamingComplete(true);
clearInterval(interval);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ export const useConnectorSetup = ({

// Once streaming of previous message is complete, proceed to next message
const onHandleMessageStreamingComplete = useCallback(() => {
const timeoutId = setTimeout(() => {
setTimeout(() => {
bottomRef.current?.scrollIntoView({ block: 'end' });
if (currentMessageIndex >= MESSAGE_INDEX_BEFORE_CONNECTOR) {
return;
}
return setCurrentMessageIndex(currentMessageIndex + 1);
}, conversation.messages[currentMessageIndex]?.presentation?.delay ?? 0);
return () => clearTimeout(timeoutId);
}, [conversation.messages, currentMessageIndex]);

// Show button to add connector after last message has finished streaming
Expand All @@ -121,7 +123,8 @@ export const useConnectorSetup = ({
// Show button to add connector after last message has finished streaming
const handleSkipSetup = useCallback(() => {
setCurrentMessageIndex(MESSAGE_INDEX_BEFORE_CONNECTOR);
}, [setCurrentMessageIndex]);
onHandleLastMessageStreamingComplete();
}, [onHandleLastMessageStreamingComplete]);

// Create EuiCommentProps[] from conversation messages
const commentBody = useCallback(
Expand All @@ -135,7 +138,10 @@ export const useConnectorSetup = ({
}
const isLastMessage = index === length - 1;
const enableStreaming =
(message?.presentation?.stream ?? false) && currentMessageIndex !== length - 1;
(message?.presentation?.stream ?? false) &&
currentMessageIndex !== length - 1 &&
index < MESSAGE_INDEX_BEFORE_CONNECTOR;

return (
<StreamingText
text={message.content}
Expand All @@ -144,7 +150,7 @@ export const useConnectorSetup = ({
isLastMessage ? onHandleLastMessageStreamingComplete : onHandleMessageStreamingComplete
}
>
{(streamedText, isStreamingComplete) => (
{(streamedText) => (
<EuiText>
<EuiMarkdownFormat className={`message-${index}`}>{streamedText}</EuiMarkdownFormat>
<span ref={bottomRef} />
Expand Down

0 comments on commit c1ab91d

Please sign in to comment.