[feature](webapp) merge query steps to one card

This commit is contained in:
williamhliu
2023-08-29 22:14:14 +08:00
parent 93ca060c45
commit 36fd737440
40 changed files with 994 additions and 496 deletions

View File

@@ -11,7 +11,7 @@ import defaultSettings from '../config/defaultSettings';
import settings from '../config/themeSettings';
import { queryToken } from './services/login';
import { queryCurrentUser } from './services/user';
import { traverseRoutes, deleteUrlQuery } from './utils/utils';
import { traverseRoutes, deleteUrlQuery, isMobile } from './utils/utils';
import { publicPath } from '../config/defaultSettings';
import Copilot from './pages/Copilot';
export { request } from './services/request';
@@ -160,7 +160,7 @@ export const layout: RunTimeLayoutConfig = (params) => {
return (
<>
{dom}
{history.location.pathname !== '/chat' && <Copilot />}
{history.location.pathname !== '/chat' && !isMobile && <Copilot />}
</>
);
},

View File

@@ -4,7 +4,6 @@ import { isEqual } from 'lodash';
import { ChatItem } from 'supersonic-chat-sdk';
import type { MsgDataType } from 'supersonic-chat-sdk';
import { AgentType, MessageItem, MessageTypeEnum } from './type';
import Plugin from './components/Plugin';
import { updateMessageContainerScroll } from '@/utils/utils';
import styles from './style.less';
import { MODEL_MODEL_ENTITY_ID_FILTER_MAP } from './constants';
@@ -71,34 +70,6 @@ const MessageContainer: React.FC<Props> = ({
updateMessageContainerScroll();
}, [copilotFullscreen]);
const getFollowQuestions = (index: number) => {
const followQuestions: string[] = [];
const currentMsg = messageList[index];
const currentMsgData = currentMsg.msgData;
const msgs = messageList.slice(0, index).reverse();
for (let i = 0; i < msgs.length; i++) {
const msg = msgs[i];
const msgModelId = msg.msgData?.chatContext?.modelId;
const msgEntityId = msg.msgData?.entityInfo?.entityId;
const currentMsgModelId = currentMsgData?.chatContext?.modelId;
const currentMsgEntityId = currentMsgData?.entityInfo?.entityId;
if (
(msg.type === MessageTypeEnum.QUESTION || msg.type === MessageTypeEnum.PLUGIN) &&
!!currentMsgModelId &&
msgModelId === currentMsgModelId &&
msgEntityId === currentMsgEntityId &&
msg.msg
) {
followQuestions.push(msg.msg);
} else {
break;
}
}
return followQuestions;
};
const getFilters = (modelId?: number, entityId?: string) => {
if (!modelId || !entityId) {
return undefined;
@@ -130,8 +101,6 @@ const MessageContainer: React.FC<Props> = ({
parseOptions,
} = msgItem;
const followQuestions = getFollowQuestions(index);
return (
<div key={msgId} id={`${msgId}`} className={styles.messageItem}>
{type === MessageTypeEnum.TEXT && <Text position="left" data={msg} />}
@@ -142,7 +111,7 @@ const MessageContainer: React.FC<Props> = ({
<AgentList
currentAgentName={msg!}
data={agentList}
copilotFullscreen={copilotFullscreen}
copilotFullscreen={copilotFullscreen || !isMobileMode}
onSelectAgent={onSelectAgent}
/>
)}
@@ -159,6 +128,7 @@ const MessageContainer: React.FC<Props> = ({
filter={getFilters(modelId, entityId)}
isLastMessage={index === messageList.length - 1}
isMobileMode={isMobileMode}
isHistory={isHistory}
triggerResize={triggerResize}
onMsgDataLoaded={(data: MsgDataType, valid: boolean) => {
onMsgDataLoaded(data, msgId, msgValue || msg || '', valid);
@@ -176,6 +146,7 @@ const MessageContainer: React.FC<Props> = ({
filter={getFilters(modelId, entityId)}
isLastMessage={index === messageList.length - 1}
isMobileMode={isMobileMode}
isHistory={isHistory}
triggerResize={triggerResize}
parseOptions={parseOptions}
onMsgDataLoaded={(data: MsgDataType, valid: boolean) => {
@@ -184,24 +155,6 @@ const MessageContainer: React.FC<Props> = ({
onUpdateMessageScroll={updateMessageContainerScroll}
/>
)}
{type === MessageTypeEnum.PLUGIN && (
<>
<Plugin
id={msgId}
followQuestions={followQuestions}
data={msgData!}
scoreValue={score}
msg={msgValue || msg || ''}
isHistory={isHistory}
isLastMessage={index === messageList.length - 1}
isMobileMode={isMobileMode}
onReportLoaded={(height: number) => {
updateMessageContainerScroll(true, height);
}}
onCheckMore={onCheckMore}
/>
</>
)}
</div>
);
})}

View File

@@ -4,6 +4,7 @@ import Message from '../Message';
import styles from './style.less';
import { queryRecommendQuestions } from '../../service';
import Typing from '../Typing';
import { isMobile } from '@/utils/utils';
type Props = {
onSelectQuestion: (value: string) => void;
@@ -34,7 +35,7 @@ const RecommendQuestions: React.FC<Props> = ({ onSelectQuestion }) => {
return (
<div className={styles.recommendQuestions}>
<LeftAvatar />
{!isMobile && <LeftAvatar />}
{loading ? (
<Typing />
) : questions.length > 0 ? (

View File

@@ -13,6 +13,7 @@
.content {
display: flex;
align-items: center;
flex-wrap: wrap;
column-gap: 16px;
row-gap: 20px;

View File

@@ -58,7 +58,7 @@ const Chat: React.FC<Props> = ({
const [currentConversation, setCurrentConversation] = useState<
ConversationDetailType | undefined
>(isMobile ? { chatId: 0, chatName: `${CHAT_TITLE}问答` } : undefined);
const [conversationCollapsed, setConversationCollapsed] = useState(isCopilotMode);
const [conversationCollapsed, setConversationCollapsed] = useState(isMobileMode);
const [models, setModels] = useState<ModelType[]>([]);
const [currentModel, setCurrentModel] = useState<ModelType>();
const [defaultEntity, setDefaultEntity] = useState<DefaultEntityType>();
@@ -161,10 +161,10 @@ const Chat: React.FC<Props> = ({
const sendHelloRsp = () => {
setMessageList([
{
id: uuid(),
type: MessageTypeEnum.RECOMMEND_QUESTIONS,
// type: MessageTypeEnum.AGENT_LIST,
// msg: currentAgent?.name || '查信息',
// id: uuid(),
// type: MessageTypeEnum.RECOMMEND_QUESTIONS,
type: MessageTypeEnum.AGENT_LIST,
msg: currentAgent?.name || '查信息',
},
]);
};
@@ -172,10 +172,7 @@ const Chat: React.FC<Props> = ({
const convertHistoryMsg = (list: HistoryMsgItemType[]) => {
return list.map((item: HistoryMsgItemType) => ({
id: item.questionId,
type:
item.queryResult?.queryMode === MessageTypeEnum.WEB_PAGE
? MessageTypeEnum.PLUGIN
: MessageTypeEnum.QUESTION,
type: MessageTypeEnum.QUESTION,
msg: item.queryText,
msgData: item.queryResult,
score: item.score,
@@ -350,7 +347,12 @@ const Chat: React.FC<Props> = ({
}
};
const onMsgDataLoaded = (data: MsgDataType, questionId: string | number) => {
const onMsgDataLoaded = (
data: MsgDataType,
questionId: string | number,
question: string,
valid: boolean,
) => {
if (!isMobile) {
conversationRef?.current?.updateData();
}
@@ -366,28 +368,15 @@ const Chat: React.FC<Props> = ({
parseOptions: data.parseOptions,
};
}
if (data.queryMode === 'WEB_PAGE') {
setMessageList([
...messageList,
{
id: uuid(),
msg: messageList[messageList.length - 1]?.msg,
type: MessageTypeEnum.PLUGIN,
msgData: data,
},
...(parseOptionsItem ? [parseOptionsItem] : []),
]);
} else {
const msgs = cloneDeep(messageList);
const msg = msgs.find((item) => item.id === questionId);
if (msg) {
msg.msgData = data;
setMessageList([...msgs, ...(parseOptionsItem ? [parseOptionsItem] : [])]);
}
updateMessageContainerScroll();
const msgs = cloneDeep(messageList);
const msg = msgs.find((item) => item.id === questionId);
if (msg) {
msg.msgData = data;
const msgList = [...msgs, ...(parseOptionsItem ? [parseOptionsItem] : [])];
setMessageList(msgList);
updateChatFilter(data, msgList);
}
updateChatFilter(data);
updateMessageContainerScroll(`${questionId}`);
};
const onCheckMore = (data: MsgDataType) => {

View File

@@ -136,7 +136,7 @@
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: 16px 0;
margin: 16px 0 0;
row-gap: 8px;
}
@@ -437,7 +437,7 @@
}
}
.mobile {
.mobileMode {
.messageList {
padding: 20px 12px 60px !important;
}
@@ -786,10 +786,5 @@
.ss-chat-item-typing-bubble {
padding: 16px !important;
}
ss-chat-metric-card-drill-down-dimensions {
bottom: -38px !important;
left: 0 !important;
}
}