Add mdast-related dependencies and update code to use mdast
- Update package.json to include mdast dependencies - Import necessary functions and types from mdast-util - Update logic to use mdast functions and types - Update rendering logic to work with new mdast structure
This commit is contained in:
parent
b214ddfc71
commit
46e3e1edfc
1138
package-lock.json
generated
1138
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -796,6 +796,9 @@
|
|||||||
"axios": "^1.3.6",
|
"axios": "^1.3.6",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
"mdast": "^3.0.0",
|
||||||
|
"mdast-util-from-markdown": "^2.0.0",
|
||||||
|
"mdast-util-to-markdown": "^2.1.0",
|
||||||
"mobx": "^6.10.0",
|
"mobx": "^6.10.0",
|
||||||
"mobx-react": "^9.0.0",
|
"mobx-react": "^9.0.0",
|
||||||
"mobx-state-tree": "^5.1.8",
|
"mobx-state-tree": "^5.1.8",
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
|
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { keyframes } from "@emotion/react";
|
import { keyframes } from "@emotion/react";
|
||||||
import { Box, Container, Text } from "@mantine/core";
|
import { Box, Container, Text } from "@mantine/core";
|
||||||
import MessageBody from "@/views/components/MessageBody";
|
import MessageBody from "@/views/components/MessageBody";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { useMst } from "@/views/stores/RootStore";
|
import { useMst } from "@/views/stores/RootStore";
|
||||||
import { Message } from "@/views/stores/ChatStore";
|
import { Message } from "@/views/stores/ChatStore";
|
||||||
|
import {fromMarkdown} from 'mdast-util-from-markdown';
|
||||||
|
import {toMarkdown} from 'mdast-util-to-markdown';
|
||||||
|
import {Root} from 'mdast';
|
||||||
|
|
||||||
const MessageBlink = observer(() => {
|
const MessageBlink = observer(() => {
|
||||||
const { chat } = useMst();
|
const { chat } = useMst();
|
||||||
@ -49,13 +51,12 @@ const CurrentMessage = observer((props: any) => {
|
|||||||
const { width } = props;
|
const { width } = props;
|
||||||
const { chat } = useMst();
|
const { chat } = useMst();
|
||||||
const { messages, currentMessage, generating, responsed, hasDone } = chat;
|
const { messages, currentMessage, generating, responsed, hasDone } = chat;
|
||||||
|
|
||||||
// split blocks
|
// split blocks
|
||||||
const messageBlocks = getBlocks(currentMessage);
|
const messageBlocks = fromMarkdown(currentMessage);
|
||||||
const lastMessageBlocks = getBlocks(messages[messages.length - 1]?.message);
|
const lastMessageBlocks = fromMarkdown(messages[messages.length - 1]?.message);
|
||||||
const fixedCount = lastMessageBlocks.length;
|
const fixedCount = lastMessageBlocks.children.length;
|
||||||
const receivedCount = messageBlocks.length;
|
const receivedCount = messageBlocks.children.length;
|
||||||
const renderBlocks = messageBlocks.splice(-1);
|
const renderBlocks = messageBlocks.children.splice(-1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (generating) {
|
if (generating) {
|
||||||
@ -67,7 +68,10 @@ const CurrentMessage = observer((props: any) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (generating && (receivedCount - fixedCount >= 1 || !responsed)) {
|
if (generating && (receivedCount - fixedCount >= 1 || !responsed)) {
|
||||||
chat.updateLastMessage(currentMessage);
|
chat.updateLastMessage(toMarkdown({
|
||||||
|
type: 'root',
|
||||||
|
children: messageBlocks.children
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}, [currentMessage, responsed, generating]);
|
}, [currentMessage, responsed, generating]);
|
||||||
|
|
||||||
@ -86,7 +90,7 @@ const CurrentMessage = observer((props: any) => {
|
|||||||
whiteSpace: 'break-spaces'
|
whiteSpace: 'break-spaces'
|
||||||
},
|
},
|
||||||
}}>
|
}}>
|
||||||
<MessageBody messageText={renderBlocks.join('\n\n')} messageType="bot" />
|
<MessageBody messageText={renderBlocks.length>0?toMarkdown(renderBlocks[0]):''} messageType="bot" />
|
||||||
<MessageBlink />
|
<MessageBlink />
|
||||||
</Box>
|
</Box>
|
||||||
: <></>;
|
: <></>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user