2023-07-05 15:00:20 +08:00
|
|
|
|
2023-10-11 23:51:57 +08:00
|
|
|
import { Stack, Container, Divider, Box, Group,Text, Button, createStyles } from "@mantine/core";
|
2023-08-22 14:34:43 +08:00
|
|
|
import React, { useEffect } from "react";
|
2023-08-21 14:07:11 +08:00
|
|
|
import MessageBody from "@/views/components/MessageBody";
|
2023-08-21 13:56:42 +08:00
|
|
|
import MessageAvatar from "@/views/components/MessageAvatar";
|
2023-08-18 00:24:10 +08:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import { useMst } from "@/views/stores/RootStore";
|
2023-08-22 14:34:43 +08:00
|
|
|
import { Message } from "@/views/stores/ChatStore";
|
2023-08-21 14:00:34 +08:00
|
|
|
import MessageContext from "@/views/components/MessageContext";
|
2023-09-13 20:47:22 +08:00
|
|
|
import CurrentMessage from "@/views/components/CurrentMessage";
|
2023-10-11 23:51:57 +08:00
|
|
|
import { Card } from '@mantine/core';
|
|
|
|
import { IconInfoSquareRounded } from "@tabler/icons-react";
|
2023-06-08 19:28:15 +08:00
|
|
|
|
2023-10-11 23:51:57 +08:00
|
|
|
const useStyles = createStyles((theme) => ({
|
|
|
|
card:{
|
|
|
|
backgroundColor: 'var(--vscode-menu-background)',
|
|
|
|
fontFamily: 'var(--vscode-editor-font-familyy)',
|
|
|
|
fontSize: 'var(--vscode-editor-font-size)',
|
|
|
|
color: 'var(--vscode-menu-foreground)',
|
|
|
|
borderColor: 'var(--vscode-menu-border)',
|
|
|
|
},
|
|
|
|
cardDescription:{
|
|
|
|
marginTop: 10,
|
|
|
|
marginBottom: 10,
|
|
|
|
},
|
|
|
|
button:{
|
|
|
|
backgroundColor:"#ED6A45",
|
2023-10-11 23:51:57 +08:00
|
|
|
fontFamily: 'var(--vscode-editor-font-familyy)',
|
|
|
|
fontSize: 'var(--vscode-editor-font-size)',
|
2023-10-11 23:51:57 +08:00
|
|
|
color:"#fff",
|
|
|
|
"&:hover":{
|
|
|
|
backgroundColor:"#ED6A45",
|
|
|
|
opacity: 0.8,
|
|
|
|
},
|
|
|
|
"&:focus":{
|
|
|
|
backgroundColor:"#ED6A45",
|
|
|
|
opacity: 0.8,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2023-06-08 19:28:15 +08:00
|
|
|
|
2023-08-23 21:30:23 +08:00
|
|
|
const MessageList = observer((props: any) => {
|
2023-08-18 00:24:10 +08:00
|
|
|
const { chat } = useMst();
|
2023-10-11 23:51:57 +08:00
|
|
|
const {classes} = useStyles();
|
2023-06-08 19:28:15 +08:00
|
|
|
|
2023-09-13 20:47:22 +08:00
|
|
|
return (<Stack spacing={0} sx={{margin:'0 10px 10px 10px'}}>
|
2023-08-18 11:25:28 +08:00
|
|
|
{chat.messages.map((item, index: number) => {
|
2023-10-11 23:51:57 +08:00
|
|
|
const { message: messageText, type: messageType, hash: messageHash, contexts, confirm } = item;
|
2023-08-18 00:24:10 +08:00
|
|
|
// setMessage(messageText);
|
|
|
|
return <Stack
|
|
|
|
spacing={0}
|
|
|
|
key={`message-${index}`}
|
2023-06-05 19:27:25 +08:00
|
|
|
sx={{
|
2023-08-18 00:24:10 +08:00
|
|
|
padding: 0,
|
2023-09-13 20:47:22 +08:00
|
|
|
margin: 0
|
2023-06-05 19:27:25 +08:00
|
|
|
}}>
|
2023-08-21 13:56:42 +08:00
|
|
|
<MessageAvatar
|
2023-08-18 00:24:10 +08:00
|
|
|
key={`message-header-${index}`}
|
|
|
|
showDelete={index === chat.messages.length - 2}
|
2023-08-21 15:28:19 +08:00
|
|
|
deleteHash={messageHash}
|
|
|
|
avatarType={messageType}
|
|
|
|
copyMessage={messageText}
|
|
|
|
messageContexts={contexts} />
|
2023-08-23 20:26:05 +08:00
|
|
|
<Box
|
2023-08-18 00:24:10 +08:00
|
|
|
key={`message-container-${index}`}
|
|
|
|
sx={{
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
pre: {
|
|
|
|
whiteSpace: 'break-spaces'
|
|
|
|
},
|
|
|
|
}}>
|
2023-10-11 23:51:57 +08:00
|
|
|
{ messageType === 'bot' && confirm && <Card shadow="sm" padding="xs" radius="md" withBorder className={classes.card}>
|
2023-10-11 23:51:57 +08:00
|
|
|
<Card.Section withBorder inheritPadding py="xs">
|
|
|
|
<Group position="left">
|
|
|
|
<IconInfoSquareRounded size={20} />
|
|
|
|
<Text fw={500}>Additional Cost Required</Text>
|
|
|
|
</Group>
|
|
|
|
</Card.Section>
|
2023-10-11 23:51:57 +08:00
|
|
|
<Text className={classes.cardDescription}>Will you pay approximately $0.1 - $0.5 for this task?</Text>
|
2023-10-11 23:51:57 +08:00
|
|
|
<Group position="right" >
|
2023-10-11 23:51:57 +08:00
|
|
|
<Button size="compact-xs" className={classes.button} onClick={()=> chat.sendLastUserMessage() }>Yes</Button>
|
|
|
|
<Button size="compact-xs" className={classes.button} onClick={()=> chat.cancelDevchatAsk()}>No</Button>
|
2023-10-11 23:51:57 +08:00
|
|
|
</Group>
|
|
|
|
</Card>}
|
2023-08-18 00:24:10 +08:00
|
|
|
<MessageContext key={`message-context-${index}`} contexts={contexts} />
|
2023-10-11 23:51:57 +08:00
|
|
|
<MessageBody key={`message-codeblock-${index}`} messageType={messageType} >
|
|
|
|
{messageText}
|
|
|
|
</MessageBody>
|
2023-08-23 20:26:05 +08:00
|
|
|
</Box >
|
2023-08-18 00:24:10 +08:00
|
|
|
{index !== chat.messages.length - 1 && <Divider my={3} key={`message-divider-${index}`} />}
|
|
|
|
</Stack >;
|
|
|
|
})}
|
2023-09-13 20:47:22 +08:00
|
|
|
<CurrentMessage />
|
|
|
|
</Stack>);
|
2023-08-18 00:24:10 +08:00
|
|
|
});
|
2023-06-05 19:27:25 +08:00
|
|
|
|
2023-08-21 13:53:32 +08:00
|
|
|
export default MessageList;
|