balibabu
commited on
Commit
·
18da36c
1
Parent(s):
1fa0527
fix: remove duplicate MessageItem #1289 (#1566)
Browse files### What problem does this PR solve?
fix: remove duplicate MessageItem #1289
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- web/src/components/message-item/index.less +20 -0
- web/src/components/message-item/index.tsx +21 -14
- web/src/hooks/flow-hooks.ts +1 -1
- web/src/hooks/logicHooks.ts +4 -1
- web/src/interfaces/database/chat.ts +1 -0
- web/src/pages/chat/chat-container/index.less +0 -79
- web/src/pages/chat/chat-container/index.tsx +10 -125
- web/src/pages/chat/hooks.ts +4 -15
- web/src/pages/chat/markdown-content/index.tsx +2 -2
- web/src/pages/chat/share/index.less +0 -54
- web/src/pages/chat/share/large.tsx +6 -117
- web/src/pages/flow/chat/box.tsx +4 -0
web/src/components/message-item/index.less
CHANGED
|
@@ -22,6 +22,26 @@
|
|
| 22 |
background-color: rgba(249, 250, 251, 1);
|
| 23 |
word-break: break-all;
|
| 24 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
.messageEmpty {
|
| 26 |
width: 300px;
|
| 27 |
}
|
|
|
|
| 22 |
background-color: rgba(249, 250, 251, 1);
|
| 23 |
word-break: break-all;
|
| 24 |
}
|
| 25 |
+
.messageTextBase() {
|
| 26 |
+
padding: 6px 10px;
|
| 27 |
+
border-radius: 8px;
|
| 28 |
+
& > p {
|
| 29 |
+
margin: 0;
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
.messageText {
|
| 33 |
+
.chunkText();
|
| 34 |
+
.messageTextBase();
|
| 35 |
+
background-color: #e6f4ff;
|
| 36 |
+
word-break: break-all;
|
| 37 |
+
}
|
| 38 |
+
.messageUserText {
|
| 39 |
+
.chunkText();
|
| 40 |
+
.messageTextBase();
|
| 41 |
+
background-color: rgb(248, 247, 247);
|
| 42 |
+
word-break: break-all;
|
| 43 |
+
text-align: justify;
|
| 44 |
+
}
|
| 45 |
.messageEmpty {
|
| 46 |
width: 300px;
|
| 47 |
}
|
web/src/components/message-item/index.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import { MessageType } from '@/constants/chat';
|
|
| 3 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 4 |
import { useGetDocumentUrl } from '@/hooks/documentHooks';
|
| 5 |
import { useSelectFileThumbnails } from '@/hooks/knowledgeHook';
|
| 6 |
-
import { useSelectUserInfo } from '@/hooks/userSettingHook';
|
| 7 |
import { IReference, Message } from '@/interfaces/database/chat';
|
| 8 |
import { IChunk } from '@/interfaces/database/knowledge';
|
| 9 |
import classNames from 'classnames';
|
|
@@ -16,23 +15,27 @@ import NewDocumentLink from '../new-document-link';
|
|
| 16 |
import SvgIcon from '../svg-icon';
|
| 17 |
import styles from './index.less';
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
const MessageItem = ({
|
| 20 |
item,
|
| 21 |
reference,
|
| 22 |
loading = false,
|
|
|
|
|
|
|
| 23 |
clickDocumentButton,
|
| 24 |
-
}: {
|
| 25 |
-
item
|
| 26 |
-
|
| 27 |
-
loading?: boolean;
|
| 28 |
-
clickDocumentButton: (documentId: string, chunk: IChunk) => void;
|
| 29 |
-
}) => {
|
| 30 |
-
const userInfo = useSelectUserInfo();
|
| 31 |
const fileThumbnails = useSelectFileThumbnails();
|
| 32 |
const getDocumentUrl = useGetDocumentUrl();
|
| 33 |
-
const { t } = useTranslate('chat');
|
| 34 |
-
|
| 35 |
-
const isAssistant = item.role === MessageType.Assistant;
|
| 36 |
|
| 37 |
const referenceDocumentList = useMemo(() => {
|
| 38 |
return reference?.doc_aggs ?? [];
|
|
@@ -68,7 +71,7 @@ const MessageItem = ({
|
|
| 68 |
<Avatar
|
| 69 |
size={40}
|
| 70 |
src={
|
| 71 |
-
|
| 72 |
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
|
| 73 |
}
|
| 74 |
/>
|
|
@@ -76,8 +79,12 @@ const MessageItem = ({
|
|
| 76 |
<AssistantIcon></AssistantIcon>
|
| 77 |
)}
|
| 78 |
<Flex vertical gap={8} flex={1}>
|
| 79 |
-
<b>{isAssistant ? '' :
|
| 80 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
<MarkdownContent
|
| 82 |
content={content}
|
| 83 |
reference={reference}
|
|
|
|
| 3 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 4 |
import { useGetDocumentUrl } from '@/hooks/documentHooks';
|
| 5 |
import { useSelectFileThumbnails } from '@/hooks/knowledgeHook';
|
|
|
|
| 6 |
import { IReference, Message } from '@/interfaces/database/chat';
|
| 7 |
import { IChunk } from '@/interfaces/database/knowledge';
|
| 8 |
import classNames from 'classnames';
|
|
|
|
| 15 |
import SvgIcon from '../svg-icon';
|
| 16 |
import styles from './index.less';
|
| 17 |
|
| 18 |
+
interface IProps {
|
| 19 |
+
item: Message;
|
| 20 |
+
reference: IReference;
|
| 21 |
+
loading?: boolean;
|
| 22 |
+
nickname?: string;
|
| 23 |
+
avatar?: string;
|
| 24 |
+
clickDocumentButton?: (documentId: string, chunk: IChunk) => void;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
const MessageItem = ({
|
| 28 |
item,
|
| 29 |
reference,
|
| 30 |
loading = false,
|
| 31 |
+
avatar = '',
|
| 32 |
+
nickname = '',
|
| 33 |
clickDocumentButton,
|
| 34 |
+
}: IProps) => {
|
| 35 |
+
const isAssistant = item.role === MessageType.Assistant;
|
| 36 |
+
const { t } = useTranslate('chat');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
const fileThumbnails = useSelectFileThumbnails();
|
| 38 |
const getDocumentUrl = useGetDocumentUrl();
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
const referenceDocumentList = useMemo(() => {
|
| 41 |
return reference?.doc_aggs ?? [];
|
|
|
|
| 71 |
<Avatar
|
| 72 |
size={40}
|
| 73 |
src={
|
| 74 |
+
avatar ??
|
| 75 |
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
|
| 76 |
}
|
| 77 |
/>
|
|
|
|
| 79 |
<AssistantIcon></AssistantIcon>
|
| 80 |
)}
|
| 81 |
<Flex vertical gap={8} flex={1}>
|
| 82 |
+
<b>{isAssistant ? '' : nickname}</b>
|
| 83 |
+
<div
|
| 84 |
+
className={
|
| 85 |
+
isAssistant ? styles.messageText : styles.messageUserText
|
| 86 |
+
}
|
| 87 |
+
>
|
| 88 |
<MarkdownContent
|
| 89 |
content={content}
|
| 90 |
reference={reference}
|
web/src/hooks/flow-hooks.ts
CHANGED
|
@@ -120,7 +120,7 @@ export const useSetFlow = () => {
|
|
| 120 |
dsl?: DSL;
|
| 121 |
avatar?: string;
|
| 122 |
}) => {
|
| 123 |
-
const { data } = await flowService.setCanvas(params);
|
| 124 |
if (data.retcode === 0) {
|
| 125 |
message.success(
|
| 126 |
i18n.t(`message.${params?.id ? 'modified' : 'created'}`),
|
|
|
|
| 120 |
dsl?: DSL;
|
| 121 |
avatar?: string;
|
| 122 |
}) => {
|
| 123 |
+
const { data = {} } = await flowService.setCanvas(params);
|
| 124 |
if (data.retcode === 0) {
|
| 125 |
message.success(
|
| 126 |
i18n.t(`message.${params?.id ? 'modified' : 'created'}`),
|
web/src/hooks/logicHooks.ts
CHANGED
|
@@ -189,7 +189,10 @@ export const useSendMessageWithSse = (
|
|
| 189 |
const d = val?.data;
|
| 190 |
if (typeof d !== 'boolean') {
|
| 191 |
console.info('data:', d);
|
| 192 |
-
setAnswer(
|
|
|
|
|
|
|
|
|
|
| 193 |
}
|
| 194 |
} catch (e) {
|
| 195 |
console.warn(e);
|
|
|
|
| 189 |
const d = val?.data;
|
| 190 |
if (typeof d !== 'boolean') {
|
| 191 |
console.info('data:', d);
|
| 192 |
+
setAnswer({
|
| 193 |
+
...d,
|
| 194 |
+
conversationId: body?.conversation_id,
|
| 195 |
+
});
|
| 196 |
}
|
| 197 |
} catch (e) {
|
| 198 |
console.warn(e);
|
web/src/interfaces/database/chat.ts
CHANGED
|
@@ -77,6 +77,7 @@ export interface IReference {
|
|
| 77 |
export interface IAnswer {
|
| 78 |
answer: string;
|
| 79 |
reference: IReference;
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
export interface Docagg {
|
|
|
|
| 77 |
export interface IAnswer {
|
| 78 |
answer: string;
|
| 79 |
reference: IReference;
|
| 80 |
+
conversationId?: string;
|
| 81 |
}
|
| 82 |
|
| 83 |
export interface Docagg {
|
web/src/pages/chat/chat-container/index.less
CHANGED
|
@@ -5,82 +5,3 @@
|
|
| 5 |
padding-right: 24px;
|
| 6 |
}
|
| 7 |
}
|
| 8 |
-
|
| 9 |
-
.messageItem {
|
| 10 |
-
padding: 24px 0;
|
| 11 |
-
.messageItemSection {
|
| 12 |
-
display: inline-block;
|
| 13 |
-
}
|
| 14 |
-
.messageItemSectionLeft {
|
| 15 |
-
width: 70%;
|
| 16 |
-
}
|
| 17 |
-
.messageItemSectionRight {
|
| 18 |
-
width: 40%;
|
| 19 |
-
}
|
| 20 |
-
.messageItemContent {
|
| 21 |
-
display: inline-flex;
|
| 22 |
-
gap: 20px;
|
| 23 |
-
}
|
| 24 |
-
.messageItemContentReverse {
|
| 25 |
-
flex-direction: row-reverse;
|
| 26 |
-
}
|
| 27 |
-
.messageTextBase() {
|
| 28 |
-
padding: 6px 10px;
|
| 29 |
-
border-radius: 8px;
|
| 30 |
-
& > p {
|
| 31 |
-
margin: 0;
|
| 32 |
-
}
|
| 33 |
-
}
|
| 34 |
-
.messageText {
|
| 35 |
-
.chunkText();
|
| 36 |
-
.messageTextBase();
|
| 37 |
-
background-color: #e6f4ff;
|
| 38 |
-
word-break: break-all;
|
| 39 |
-
}
|
| 40 |
-
.messageUserText {
|
| 41 |
-
.chunkText();
|
| 42 |
-
.messageTextBase();
|
| 43 |
-
background-color: rgb(248, 247, 247);
|
| 44 |
-
word-break: break-all;
|
| 45 |
-
text-align: justify;
|
| 46 |
-
}
|
| 47 |
-
.messageEmpty {
|
| 48 |
-
width: 300px;
|
| 49 |
-
}
|
| 50 |
-
// .referenceIcon {
|
| 51 |
-
// padding: 0 6px;
|
| 52 |
-
// }
|
| 53 |
-
.thumbnailImg {
|
| 54 |
-
max-width: 20px;
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
.messageItemLeft {
|
| 59 |
-
text-align: left;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
.messageItemRight {
|
| 63 |
-
text-align: right;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
// .referencePopoverWrapper {
|
| 67 |
-
// max-width: 50vw;
|
| 68 |
-
// }
|
| 69 |
-
|
| 70 |
-
// .referenceChunkImage {
|
| 71 |
-
// width: 10vw;
|
| 72 |
-
// object-fit: contain;
|
| 73 |
-
// }
|
| 74 |
-
|
| 75 |
-
// .referenceImagePreview {
|
| 76 |
-
// max-width: 45vw;
|
| 77 |
-
// max-height: 45vh;
|
| 78 |
-
// }
|
| 79 |
-
// .chunkContentText {
|
| 80 |
-
// .chunkText;
|
| 81 |
-
// max-height: 45vh;
|
| 82 |
-
// overflow-y: auto;
|
| 83 |
-
// }
|
| 84 |
-
// .documentLink {
|
| 85 |
-
// padding: 0;
|
| 86 |
-
// }
|
|
|
|
| 5 |
padding-right: 24px;
|
| 6 |
}
|
| 7 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/chat/chat-container/index.tsx
CHANGED
|
@@ -1,139 +1,21 @@
|
|
| 1 |
-
import
|
| 2 |
-
import NewDocumentLink from '@/components/new-document-link';
|
| 3 |
import DocumentPreviewer from '@/components/pdf-previewer';
|
| 4 |
import { MessageType } from '@/constants/chat';
|
| 5 |
-
import {
|
| 6 |
-
import {
|
| 7 |
-
import { IReference, Message } from '@/interfaces/database/chat';
|
| 8 |
-
import { IChunk } from '@/interfaces/database/knowledge';
|
| 9 |
-
import { Avatar, Button, Drawer, Flex, Input, List, Spin } from 'antd';
|
| 10 |
-
import classNames from 'classnames';
|
| 11 |
-
import { useMemo } from 'react';
|
| 12 |
import {
|
| 13 |
useClickDrawer,
|
| 14 |
useFetchConversationOnMount,
|
| 15 |
useGetFileIcon,
|
| 16 |
useGetSendButtonDisabled,
|
| 17 |
-
useSelectConversationLoading,
|
|
|
|
| 18 |
useSendMessage,
|
| 19 |
} from '../hooks';
|
| 20 |
-
import MarkdownContent from '../markdown-content';
|
| 21 |
-
|
| 22 |
-
import SvgIcon from '@/components/svg-icon';
|
| 23 |
-
import { useTranslate } from '@/hooks/commonHooks';
|
| 24 |
-
import { useGetDocumentUrl } from '@/hooks/documentHooks';
|
| 25 |
-
import { getExtension, isPdf } from '@/utils/documentUtils';
|
| 26 |
import { buildMessageItemReference } from '../utils';
|
| 27 |
-
import styles from './index.less';
|
| 28 |
-
|
| 29 |
-
const MessageItem = ({
|
| 30 |
-
item,
|
| 31 |
-
reference,
|
| 32 |
-
loading = false,
|
| 33 |
-
clickDocumentButton,
|
| 34 |
-
}: {
|
| 35 |
-
item: Message;
|
| 36 |
-
reference: IReference;
|
| 37 |
-
loading?: boolean;
|
| 38 |
-
clickDocumentButton: (documentId: string, chunk: IChunk) => void;
|
| 39 |
-
}) => {
|
| 40 |
-
const userInfo = useSelectUserInfo();
|
| 41 |
-
const fileThumbnails = useSelectFileThumbnails();
|
| 42 |
-
const getDocumentUrl = useGetDocumentUrl();
|
| 43 |
-
const { t } = useTranslate('chat');
|
| 44 |
-
|
| 45 |
-
const isAssistant = item.role === MessageType.Assistant;
|
| 46 |
-
|
| 47 |
-
const referenceDocumentList = useMemo(() => {
|
| 48 |
-
return reference?.doc_aggs ?? [];
|
| 49 |
-
}, [reference?.doc_aggs]);
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
if (text === '') {
|
| 54 |
-
text = t('searching');
|
| 55 |
-
}
|
| 56 |
-
return loading ? text?.concat('~~2$$') : text;
|
| 57 |
-
}, [item.content, loading, t]);
|
| 58 |
-
|
| 59 |
-
return (
|
| 60 |
-
<div
|
| 61 |
-
className={classNames(styles.messageItem, {
|
| 62 |
-
[styles.messageItemLeft]: item.role === MessageType.Assistant,
|
| 63 |
-
[styles.messageItemRight]: item.role === MessageType.User,
|
| 64 |
-
})}
|
| 65 |
-
>
|
| 66 |
-
<section
|
| 67 |
-
className={classNames(styles.messageItemSection, {
|
| 68 |
-
[styles.messageItemSectionLeft]: item.role === MessageType.Assistant,
|
| 69 |
-
[styles.messageItemSectionRight]: item.role === MessageType.User,
|
| 70 |
-
})}
|
| 71 |
-
>
|
| 72 |
-
<div
|
| 73 |
-
className={classNames(styles.messageItemContent, {
|
| 74 |
-
[styles.messageItemContentReverse]: item.role === MessageType.User,
|
| 75 |
-
})}
|
| 76 |
-
>
|
| 77 |
-
{item.role === MessageType.User ? (
|
| 78 |
-
<Avatar
|
| 79 |
-
size={40}
|
| 80 |
-
src={
|
| 81 |
-
userInfo.avatar ??
|
| 82 |
-
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
|
| 83 |
-
}
|
| 84 |
-
/>
|
| 85 |
-
) : (
|
| 86 |
-
<AssistantIcon></AssistantIcon>
|
| 87 |
-
)}
|
| 88 |
-
<Flex vertical gap={8} flex={1}>
|
| 89 |
-
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
| 90 |
-
<div className={isAssistant ? styles.messageText : styles.messageUserText}>
|
| 91 |
-
<MarkdownContent
|
| 92 |
-
content={content}
|
| 93 |
-
reference={reference}
|
| 94 |
-
clickDocumentButton={clickDocumentButton}
|
| 95 |
-
></MarkdownContent>
|
| 96 |
-
</div>
|
| 97 |
-
{isAssistant && referenceDocumentList.length > 0 && (
|
| 98 |
-
<List
|
| 99 |
-
bordered
|
| 100 |
-
dataSource={referenceDocumentList}
|
| 101 |
-
renderItem={(item) => {
|
| 102 |
-
const fileThumbnail = fileThumbnails[item.doc_id];
|
| 103 |
-
const fileExtension = getExtension(item.doc_name);
|
| 104 |
-
return (
|
| 105 |
-
<List.Item>
|
| 106 |
-
<Flex gap={'small'} align="center">
|
| 107 |
-
{fileThumbnail ? (
|
| 108 |
-
<img
|
| 109 |
-
src={fileThumbnail}
|
| 110 |
-
className={styles.thumbnailImg}
|
| 111 |
-
></img>
|
| 112 |
-
) : (
|
| 113 |
-
<SvgIcon
|
| 114 |
-
name={`file-icon/${fileExtension}`}
|
| 115 |
-
width={24}
|
| 116 |
-
></SvgIcon>
|
| 117 |
-
)}
|
| 118 |
-
|
| 119 |
-
<NewDocumentLink
|
| 120 |
-
link={getDocumentUrl(item.doc_id)}
|
| 121 |
-
preventDefault={!isPdf(item.doc_name)}
|
| 122 |
-
>
|
| 123 |
-
{item.doc_name}
|
| 124 |
-
</NewDocumentLink>
|
| 125 |
-
</Flex>
|
| 126 |
-
</List.Item>
|
| 127 |
-
);
|
| 128 |
-
}}
|
| 129 |
-
/>
|
| 130 |
-
)}
|
| 131 |
-
</Flex>
|
| 132 |
-
</div>
|
| 133 |
-
</section>
|
| 134 |
-
</div>
|
| 135 |
-
);
|
| 136 |
-
};
|
| 137 |
|
| 138 |
const ChatContainer = () => {
|
| 139 |
const {
|
|
@@ -161,6 +43,7 @@ const ChatContainer = () => {
|
|
| 161 |
useGetFileIcon();
|
| 162 |
const loading = useSelectConversationLoading();
|
| 163 |
const { t } = useTranslate('chat');
|
|
|
|
| 164 |
|
| 165 |
return (
|
| 166 |
<>
|
|
@@ -178,6 +61,8 @@ const ChatContainer = () => {
|
|
| 178 |
}
|
| 179 |
key={message.id}
|
| 180 |
item={message}
|
|
|
|
|
|
|
| 181 |
reference={buildMessageItemReference(conversation, message)}
|
| 182 |
clickDocumentButton={clickDocumentButton}
|
| 183 |
></MessageItem>
|
|
|
|
| 1 |
+
import MessageItem from '@/components/message-item';
|
|
|
|
| 2 |
import DocumentPreviewer from '@/components/pdf-previewer';
|
| 3 |
import { MessageType } from '@/constants/chat';
|
| 4 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
| 5 |
+
import { Button, Drawer, Flex, Input, Spin } from 'antd';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import {
|
| 7 |
useClickDrawer,
|
| 8 |
useFetchConversationOnMount,
|
| 9 |
useGetFileIcon,
|
| 10 |
useGetSendButtonDisabled,
|
| 11 |
+
useSelectConversationLoading,
|
| 12 |
+
useSendButtonDisabled,
|
| 13 |
useSendMessage,
|
| 14 |
} from '../hooks';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import { buildMessageItemReference } from '../utils';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
import { useSelectUserInfo } from '@/hooks/userSettingHook';
|
| 18 |
+
import styles from './index.less';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
const ChatContainer = () => {
|
| 21 |
const {
|
|
|
|
| 43 |
useGetFileIcon();
|
| 44 |
const loading = useSelectConversationLoading();
|
| 45 |
const { t } = useTranslate('chat');
|
| 46 |
+
const userInfo = useSelectUserInfo();
|
| 47 |
|
| 48 |
return (
|
| 49 |
<>
|
|
|
|
| 61 |
}
|
| 62 |
key={message.id}
|
| 63 |
item={message}
|
| 64 |
+
nickname={userInfo.nickname}
|
| 65 |
+
avatar={userInfo.avatar}
|
| 66 |
reference={buildMessageItemReference(conversation, message)}
|
| 67 |
clickDocumentButton={clickDocumentButton}
|
| 68 |
></MessageItem>
|
web/src/pages/chat/hooks.ts
CHANGED
|
@@ -326,7 +326,7 @@ export const useSelectDerivedConversationList = () => {
|
|
| 326 |
|
| 327 |
return pre;
|
| 328 |
});
|
| 329 |
-
}, [conversationList, dialogId, prologue]);
|
| 330 |
|
| 331 |
useEffect(() => {
|
| 332 |
addTemporaryConversation();
|
|
@@ -402,7 +402,7 @@ export const useSelectCurrentConversation = () => {
|
|
| 402 |
role: MessageType.Assistant,
|
| 403 |
content: answer,
|
| 404 |
id: uuid(),
|
| 405 |
-
reference:
|
| 406 |
} as IMessage,
|
| 407 |
],
|
| 408 |
};
|
|
@@ -433,7 +433,6 @@ export const useSelectCurrentConversation = () => {
|
|
| 433 |
}, []);
|
| 434 |
|
| 435 |
const removeLatestMessage = useCallback(() => {
|
| 436 |
-
console.info('removeLatestMessage');
|
| 437 |
setCurrentConversation((pre) => {
|
| 438 |
const nextMessages = pre.message?.slice(0, -2) ?? [];
|
| 439 |
return {
|
|
@@ -484,7 +483,6 @@ export const useScrollToBottom = (currentConversation: IClientConversation) => {
|
|
| 484 |
const ref = useRef<HTMLDivElement>(null);
|
| 485 |
|
| 486 |
const scrollToBottom = useCallback(() => {
|
| 487 |
-
console.info('useScrollToBottom');
|
| 488 |
if (currentConversation.id) {
|
| 489 |
ref.current?.scrollIntoView({ behavior: 'instant' });
|
| 490 |
}
|
|
@@ -588,7 +586,6 @@ export const useSendMessage = (
|
|
| 588 |
[
|
| 589 |
conversation?.message,
|
| 590 |
conversationId,
|
| 591 |
-
// fetchConversation,
|
| 592 |
handleClickConversation,
|
| 593 |
removeLatestMessage,
|
| 594 |
setValue,
|
|
@@ -612,12 +609,10 @@ export const useSendMessage = (
|
|
| 612 |
);
|
| 613 |
|
| 614 |
useEffect(() => {
|
| 615 |
-
if (answer.answer) {
|
| 616 |
addNewestAnswer(answer);
|
| 617 |
-
console.info('true?');
|
| 618 |
-
console.info('send msg:', answer.answer);
|
| 619 |
}
|
| 620 |
-
}, [answer, addNewestAnswer]);
|
| 621 |
|
| 622 |
const handlePressEnter = useCallback(() => {
|
| 623 |
if (trim(value) === '') return;
|
|
@@ -639,15 +634,9 @@ export const useSendMessage = (
|
|
| 639 |
};
|
| 640 |
|
| 641 |
export const useGetFileIcon = () => {
|
| 642 |
-
// const req = require.context('@/assets/svg/file-icon');
|
| 643 |
-
// const ret = req.keys().map(req);
|
| 644 |
-
// console.info(ret);
|
| 645 |
-
// useEffect(() => {}, []);
|
| 646 |
-
|
| 647 |
const getFileIcon = (filename: string) => {
|
| 648 |
const ext: string = getFileExtension(filename);
|
| 649 |
const iconPath = fileIconMap[ext as keyof typeof fileIconMap];
|
| 650 |
-
// const x = require(`@/assets/svg/file-icon/${iconPath}`);
|
| 651 |
return `@/assets/svg/file-icon/${iconPath}`;
|
| 652 |
};
|
| 653 |
|
|
|
|
| 326 |
|
| 327 |
return pre;
|
| 328 |
});
|
| 329 |
+
}, [conversationList, dialogId, prologue, t]);
|
| 330 |
|
| 331 |
useEffect(() => {
|
| 332 |
addTemporaryConversation();
|
|
|
|
| 402 |
role: MessageType.Assistant,
|
| 403 |
content: answer,
|
| 404 |
id: uuid(),
|
| 405 |
+
reference: {},
|
| 406 |
} as IMessage,
|
| 407 |
],
|
| 408 |
};
|
|
|
|
| 433 |
}, []);
|
| 434 |
|
| 435 |
const removeLatestMessage = useCallback(() => {
|
|
|
|
| 436 |
setCurrentConversation((pre) => {
|
| 437 |
const nextMessages = pre.message?.slice(0, -2) ?? [];
|
| 438 |
return {
|
|
|
|
| 483 |
const ref = useRef<HTMLDivElement>(null);
|
| 484 |
|
| 485 |
const scrollToBottom = useCallback(() => {
|
|
|
|
| 486 |
if (currentConversation.id) {
|
| 487 |
ref.current?.scrollIntoView({ behavior: 'instant' });
|
| 488 |
}
|
|
|
|
| 586 |
[
|
| 587 |
conversation?.message,
|
| 588 |
conversationId,
|
|
|
|
| 589 |
handleClickConversation,
|
| 590 |
removeLatestMessage,
|
| 591 |
setValue,
|
|
|
|
| 609 |
);
|
| 610 |
|
| 611 |
useEffect(() => {
|
| 612 |
+
if (answer.answer && answer?.conversationId === conversationId) {
|
| 613 |
addNewestAnswer(answer);
|
|
|
|
|
|
|
| 614 |
}
|
| 615 |
+
}, [answer, addNewestAnswer, conversationId]);
|
| 616 |
|
| 617 |
const handlePressEnter = useCallback(() => {
|
| 618 |
if (trim(value) === '') return;
|
|
|
|
| 634 |
};
|
| 635 |
|
| 636 |
export const useGetFileIcon = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 637 |
const getFileIcon = (filename: string) => {
|
| 638 |
const ext: string = getFileExtension(filename);
|
| 639 |
const iconPath = fileIconMap[ext as keyof typeof fileIconMap];
|
|
|
|
| 640 |
return `@/assets/svg/file-icon/${iconPath}`;
|
| 641 |
};
|
| 642 |
|
web/src/pages/chat/markdown-content/index.tsx
CHANGED
|
@@ -28,7 +28,7 @@ const MarkdownContent = ({
|
|
| 28 |
}: {
|
| 29 |
content: string;
|
| 30 |
reference: IReference;
|
| 31 |
-
clickDocumentButton
|
| 32 |
}) => {
|
| 33 |
const fileThumbnails = useSelectFileThumbnails();
|
| 34 |
|
|
@@ -37,7 +37,7 @@ const MarkdownContent = ({
|
|
| 37 |
if (!isPdf) {
|
| 38 |
return;
|
| 39 |
}
|
| 40 |
-
clickDocumentButton(documentId, chunk);
|
| 41 |
},
|
| 42 |
[clickDocumentButton],
|
| 43 |
);
|
|
|
|
| 28 |
}: {
|
| 29 |
content: string;
|
| 30 |
reference: IReference;
|
| 31 |
+
clickDocumentButton?: (documentId: string, chunk: IChunk) => void;
|
| 32 |
}) => {
|
| 33 |
const fileThumbnails = useSelectFileThumbnails();
|
| 34 |
|
|
|
|
| 37 |
if (!isPdf) {
|
| 38 |
return;
|
| 39 |
}
|
| 40 |
+
clickDocumentButton?.(documentId, chunk);
|
| 41 |
},
|
| 42 |
[clickDocumentButton],
|
| 43 |
);
|
web/src/pages/chat/share/index.less
CHANGED
|
@@ -11,57 +11,3 @@
|
|
| 11 |
padding-right: 6px;
|
| 12 |
}
|
| 13 |
}
|
| 14 |
-
|
| 15 |
-
.messageItem {
|
| 16 |
-
padding: 24px 0;
|
| 17 |
-
.messageItemSection {
|
| 18 |
-
display: inline-block;
|
| 19 |
-
}
|
| 20 |
-
.messageItemSectionLeft {
|
| 21 |
-
width: 70%;
|
| 22 |
-
}
|
| 23 |
-
.messageItemSectionRight {
|
| 24 |
-
width: 40%;
|
| 25 |
-
}
|
| 26 |
-
.messageItemContent {
|
| 27 |
-
display: inline-flex;
|
| 28 |
-
gap: 20px;
|
| 29 |
-
}
|
| 30 |
-
.messageItemContentReverse {
|
| 31 |
-
flex-direction: row-reverse;
|
| 32 |
-
}
|
| 33 |
-
.messageTextBase() {
|
| 34 |
-
padding: 6px 10px;
|
| 35 |
-
border-radius: 8px;
|
| 36 |
-
& > p {
|
| 37 |
-
margin: 0;
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
.messageText {
|
| 41 |
-
.chunkText();
|
| 42 |
-
.messageTextBase();
|
| 43 |
-
background-color: #e6f4ff;
|
| 44 |
-
word-break: break-all;
|
| 45 |
-
}
|
| 46 |
-
.messageUserText {
|
| 47 |
-
.chunkText();
|
| 48 |
-
.messageTextBase();
|
| 49 |
-
background-color: rgb(248, 247, 247);
|
| 50 |
-
word-break: break-all;
|
| 51 |
-
text-align: justify;
|
| 52 |
-
}
|
| 53 |
-
.messageEmpty {
|
| 54 |
-
width: 300px;
|
| 55 |
-
}
|
| 56 |
-
.thumbnailImg {
|
| 57 |
-
max-width: 20px;
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
.messageItemLeft {
|
| 62 |
-
text-align: left;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
.messageItemRight {
|
| 66 |
-
text-align: right;
|
| 67 |
-
}
|
|
|
|
| 11 |
padding-right: 6px;
|
| 12 |
}
|
| 13 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/chat/share/large.tsx
CHANGED
|
@@ -1,129 +1,17 @@
|
|
| 1 |
-
import
|
| 2 |
import { MessageType } from '@/constants/chat';
|
| 3 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 4 |
-
import {
|
| 5 |
-
import {
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
import NewDocumentLink from '@/components/new-document-link';
|
| 9 |
-
import SvgIcon from '@/components/svg-icon';
|
| 10 |
-
import { useGetDocumentUrl } from '@/hooks/documentHooks';
|
| 11 |
-
import { useSelectFileThumbnails } from '@/hooks/knowledgeHook';
|
| 12 |
-
import { getExtension, isPdf } from '@/utils/documentUtils';
|
| 13 |
-
import { forwardRef, useMemo } from 'react';
|
| 14 |
-
import MarkdownContent from '../markdown-content';
|
| 15 |
import {
|
| 16 |
useCreateSharedConversationOnMount,
|
| 17 |
useSelectCurrentSharedConversation,
|
| 18 |
useSendSharedMessage,
|
| 19 |
} from '../shared-hooks';
|
| 20 |
import { buildMessageItemReference } from '../utils';
|
| 21 |
-
import styles from './index.less';
|
| 22 |
-
import {useSendButtonDisabled} from "@/pages/chat/hooks";
|
| 23 |
-
|
| 24 |
-
const MessageItem = ({
|
| 25 |
-
item,
|
| 26 |
-
reference,
|
| 27 |
-
loading = false,
|
| 28 |
-
}: {
|
| 29 |
-
item: Message;
|
| 30 |
-
reference: IReference;
|
| 31 |
-
loading?: boolean;
|
| 32 |
-
}) => {
|
| 33 |
-
const isAssistant = item.role === MessageType.Assistant;
|
| 34 |
-
const { t } = useTranslate('chat');
|
| 35 |
-
const fileThumbnails = useSelectFileThumbnails();
|
| 36 |
-
const getDocumentUrl = useGetDocumentUrl();
|
| 37 |
-
|
| 38 |
-
const referenceDocumentList = useMemo(() => {
|
| 39 |
-
return reference?.doc_aggs ?? [];
|
| 40 |
-
}, [reference?.doc_aggs]);
|
| 41 |
-
|
| 42 |
-
const content = useMemo(() => {
|
| 43 |
-
let text = item.content;
|
| 44 |
-
if (text === '') {
|
| 45 |
-
text = t('searching');
|
| 46 |
-
}
|
| 47 |
-
return loading ? text?.concat('~~2$$') : text;
|
| 48 |
-
}, [item.content, loading, t]);
|
| 49 |
|
| 50 |
-
|
| 51 |
-
<div
|
| 52 |
-
className={classNames(styles.messageItem, {
|
| 53 |
-
[styles.messageItemLeft]: item.role === MessageType.Assistant,
|
| 54 |
-
[styles.messageItemRight]: item.role === MessageType.User,
|
| 55 |
-
})}
|
| 56 |
-
>
|
| 57 |
-
<section
|
| 58 |
-
className={classNames(styles.messageItemSection, {
|
| 59 |
-
[styles.messageItemSectionLeft]: item.role === MessageType.Assistant,
|
| 60 |
-
[styles.messageItemSectionRight]: item.role === MessageType.User,
|
| 61 |
-
})}
|
| 62 |
-
>
|
| 63 |
-
<div
|
| 64 |
-
className={classNames(styles.messageItemContent, {
|
| 65 |
-
[styles.messageItemContentReverse]: item.role === MessageType.User,
|
| 66 |
-
})}
|
| 67 |
-
>
|
| 68 |
-
{item.role === MessageType.User ? (
|
| 69 |
-
<Avatar
|
| 70 |
-
size={40}
|
| 71 |
-
src={
|
| 72 |
-
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
|
| 73 |
-
}
|
| 74 |
-
/>
|
| 75 |
-
) : (
|
| 76 |
-
<AssistantIcon></AssistantIcon>
|
| 77 |
-
)}
|
| 78 |
-
<Flex vertical gap={8} flex={1}>
|
| 79 |
-
<b>{isAssistant ? '' : 'You'}</b>
|
| 80 |
-
<div className={isAssistant ? styles.messageText : styles.messageUserText}>
|
| 81 |
-
<MarkdownContent
|
| 82 |
-
reference={reference}
|
| 83 |
-
clickDocumentButton={() => {}}
|
| 84 |
-
content={content}
|
| 85 |
-
></MarkdownContent>
|
| 86 |
-
</div>
|
| 87 |
-
{isAssistant && referenceDocumentList.length > 0 && (
|
| 88 |
-
<List
|
| 89 |
-
bordered
|
| 90 |
-
dataSource={referenceDocumentList}
|
| 91 |
-
renderItem={(item) => {
|
| 92 |
-
const fileThumbnail = fileThumbnails[item.doc_id];
|
| 93 |
-
const fileExtension = getExtension(item.doc_name);
|
| 94 |
-
return (
|
| 95 |
-
<List.Item>
|
| 96 |
-
<Flex gap={'small'} align="center">
|
| 97 |
-
{fileThumbnail ? (
|
| 98 |
-
<img
|
| 99 |
-
src={fileThumbnail}
|
| 100 |
-
className={styles.thumbnailImg}
|
| 101 |
-
></img>
|
| 102 |
-
) : (
|
| 103 |
-
<SvgIcon
|
| 104 |
-
name={`file-icon/${fileExtension}`}
|
| 105 |
-
width={24}
|
| 106 |
-
></SvgIcon>
|
| 107 |
-
)}
|
| 108 |
-
|
| 109 |
-
<NewDocumentLink
|
| 110 |
-
link={getDocumentUrl(item.doc_id)}
|
| 111 |
-
preventDefault={!isPdf(item.doc_name)}
|
| 112 |
-
>
|
| 113 |
-
{item.doc_name}
|
| 114 |
-
</NewDocumentLink>
|
| 115 |
-
</Flex>
|
| 116 |
-
</List.Item>
|
| 117 |
-
);
|
| 118 |
-
}}
|
| 119 |
-
/>
|
| 120 |
-
)}
|
| 121 |
-
</Flex>
|
| 122 |
-
</div>
|
| 123 |
-
</section>
|
| 124 |
-
</div>
|
| 125 |
-
);
|
| 126 |
-
};
|
| 127 |
|
| 128 |
const ChatContainer = () => {
|
| 129 |
const { t } = useTranslate('chat');
|
|
@@ -163,6 +51,7 @@ const ChatContainer = () => {
|
|
| 163 |
<MessageItem
|
| 164 |
key={message.id}
|
| 165 |
item={message}
|
|
|
|
| 166 |
reference={buildMessageItemReference(conversation, message)}
|
| 167 |
loading={
|
| 168 |
message.role === MessageType.Assistant &&
|
|
|
|
| 1 |
+
import MessageItem from '@/components/message-item';
|
| 2 |
import { MessageType } from '@/constants/chat';
|
| 3 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 4 |
+
import { useSendButtonDisabled } from '@/pages/chat/hooks';
|
| 5 |
+
import { Button, Flex, Input, Spin } from 'antd';
|
| 6 |
+
import { forwardRef } from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import {
|
| 8 |
useCreateSharedConversationOnMount,
|
| 9 |
useSelectCurrentSharedConversation,
|
| 10 |
useSendSharedMessage,
|
| 11 |
} from '../shared-hooks';
|
| 12 |
import { buildMessageItemReference } from '../utils';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
import styles from './index.less';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
const ChatContainer = () => {
|
| 17 |
const { t } = useTranslate('chat');
|
|
|
|
| 51 |
<MessageItem
|
| 52 |
key={message.id}
|
| 53 |
item={message}
|
| 54 |
+
nickname="You"
|
| 55 |
reference={buildMessageItemReference(conversation, message)}
|
| 56 |
loading={
|
| 57 |
message.role === MessageType.Assistant &&
|
web/src/pages/flow/chat/box.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { Button, Drawer, Flex, Input, Spin } from 'antd';
|
|
| 8 |
|
| 9 |
import { useSelectCurrentMessages, useSendMessage } from './hooks';
|
| 10 |
|
|
|
|
| 11 |
import styles from './index.less';
|
| 12 |
|
| 13 |
const FlowChatBox = () => {
|
|
@@ -31,6 +32,7 @@ const FlowChatBox = () => {
|
|
| 31 |
useClickDrawer();
|
| 32 |
useGetFileIcon();
|
| 33 |
const { t } = useTranslate('chat');
|
|
|
|
| 34 |
|
| 35 |
return (
|
| 36 |
<>
|
|
@@ -47,6 +49,8 @@ const FlowChatBox = () => {
|
|
| 47 |
currentMessages.length - 1 === i
|
| 48 |
}
|
| 49 |
key={message.id}
|
|
|
|
|
|
|
| 50 |
item={message}
|
| 51 |
reference={buildMessageItemReference(
|
| 52 |
{ message: currentMessages, reference },
|
|
|
|
| 8 |
|
| 9 |
import { useSelectCurrentMessages, useSendMessage } from './hooks';
|
| 10 |
|
| 11 |
+
import { useSelectUserInfo } from '@/hooks/userSettingHook';
|
| 12 |
import styles from './index.less';
|
| 13 |
|
| 14 |
const FlowChatBox = () => {
|
|
|
|
| 32 |
useClickDrawer();
|
| 33 |
useGetFileIcon();
|
| 34 |
const { t } = useTranslate('chat');
|
| 35 |
+
const userInfo = useSelectUserInfo();
|
| 36 |
|
| 37 |
return (
|
| 38 |
<>
|
|
|
|
| 49 |
currentMessages.length - 1 === i
|
| 50 |
}
|
| 51 |
key={message.id}
|
| 52 |
+
nickname={userInfo.nickname}
|
| 53 |
+
avatar={userInfo.avatar}
|
| 54 |
item={message}
|
| 55 |
reference={buildMessageItemReference(
|
| 56 |
{ message: currentMessages, reference },
|