-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
/
Copy pathRender.tsx
35 lines (28 loc) · 1021 Bytes
/
Render.tsx
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
import { memo } from 'react';
import Thinking from '@/components/Thinking';
import { ARTIFACT_THINKING_TAG } from '@/const/plugin';
import { useChatStore } from '@/store/chat';
import { chatSelectors } from '@/store/chat/selectors';
import { MarkdownElementProps } from '../type';
/**
* Replace all line breaks in the matched `lobeArtifact` tag with an empty string
*/
export const isLobeThinkingClosed = (input: string = '') => {
const openTag = `<${ARTIFACT_THINKING_TAG}>`;
const closeTag = `</${ARTIFACT_THINKING_TAG}>`;
return input.includes(openTag) && input.includes(closeTag);
};
const Render = memo<MarkdownElementProps>(({ children, id }) => {
const [isGenerating] = useChatStore((s) => {
const message = chatSelectors.getMessageById(id)(s);
return [!isLobeThinkingClosed(message?.content)];
});
return (
<Thinking
content={children as string}
style={{ width: isGenerating ? '100%' : undefined }}
thinking={isGenerating}
/>
);
});
export default Render;