test-chat-sdk 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.js +24 -0
- package/README.md +46 -0
- package/config/env.js +104 -0
- package/config/getHttpsConfig.js +66 -0
- package/config/jest/babelTransform.js +29 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +134 -0
- package/config/paths.js +77 -0
- package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
- package/config/webpack.config.js +785 -0
- package/config/webpackDevServer.config.js +127 -0
- package/dist/Chat/AgentList/index.d.ts +9 -0
- package/dist/Chat/ChatFooter/index.d.ts +17 -0
- package/dist/Chat/Conversation/index.d.ts +11 -0
- package/dist/Chat/MessageContainer/index.d.ts +19 -0
- package/dist/Chat/MobileAgents/index.d.ts +11 -0
- package/dist/Chat/components/AgentTip/index.d.ts +8 -0
- package/dist/Chat/components/ConversationModal/index.d.ts +10 -0
- package/dist/Chat/components/CopilotAvatar/index.d.ts +2 -0
- package/dist/Chat/components/Message.d.ts +10 -0
- package/dist/Chat/components/RecommendQuestions/index.d.ts +6 -0
- package/dist/Chat/components/Text.d.ts +9 -0
- package/dist/Chat/constants.d.ts +19 -0
- package/dist/Chat/index.d.ts +17 -0
- package/dist/Chat/service.d.ts +11 -0
- package/dist/Chat/type.d.ts +97 -0
- package/dist/Copilot/constants.d.ts +11 -0
- package/dist/Copilot/index.d.ts +13 -0
- package/dist/ShowCase/index.d.ts +8 -0
- package/dist/ShowCase/service.d.ts +2 -0
- package/dist/ShowCase/type.d.ts +11 -0
- package/dist/common/constants.d.ts +58 -0
- package/dist/common/env.d.ts +3 -0
- package/dist/common/type.d.ts +247 -0
- package/dist/components/ChatItem/ExecuteItem.d.ts +25 -0
- package/dist/components/ChatItem/ExpandParseTip.d.ts +20 -0
- package/dist/components/ChatItem/FilterItem.d.ts +17 -0
- package/dist/components/ChatItem/Loading.d.ts +2 -0
- package/dist/components/ChatItem/ParseTip.d.ts +26 -0
- package/dist/components/ChatItem/ParseTipUtils.d.ts +10 -0
- package/dist/components/ChatItem/SimilarQuestionItem.d.ts +10 -0
- package/dist/components/ChatItem/SqlItem.d.ts +17 -0
- package/dist/components/ChatItem/SwitchEntity.d.ts +9 -0
- package/dist/components/ChatItem/Text.d.ts +6 -0
- package/dist/components/ChatItem/Typing.d.ts +2 -0
- package/dist/components/ChatItem/index.d.ts +33 -0
- package/dist/components/ChatMsg/ApplyAuth/index.d.ts +7 -0
- package/dist/components/ChatMsg/Bar/index.d.ts +13 -0
- package/dist/components/ChatMsg/DateOptions/index.d.ts +9 -0
- package/dist/components/ChatMsg/FilterSection/index.d.ts +8 -0
- package/dist/components/ChatMsg/MarkDown/index.d.ts +10 -0
- package/dist/components/ChatMsg/Message/index.d.ts +18 -0
- package/dist/components/ChatMsg/MetricCard/PeriodCompareItem.d.ts +7 -0
- package/dist/components/ChatMsg/MetricCard/index.d.ts +10 -0
- package/dist/components/ChatMsg/MetricTrend/MetricInfo.d.ts +8 -0
- package/dist/components/ChatMsg/MetricTrend/MetricTrendChart.d.ts +14 -0
- package/dist/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.d.ts +12 -0
- package/dist/components/ChatMsg/MetricTrend/index.d.ts +16 -0
- package/dist/components/ChatMsg/NoPermissionChart/index.d.ts +8 -0
- package/dist/components/ChatMsg/Pie/PieChart.d.ts +11 -0
- package/dist/components/ChatMsg/Pie/index.d.ts +14 -0
- package/dist/components/ChatMsg/Table/index.d.ts +12 -0
- package/dist/components/ChatMsg/Text/index.d.ts +9 -0
- package/dist/components/ChatMsg/WebPage/index.d.ts +8 -0
- package/dist/components/ChatMsg/index.d.ts +15 -0
- package/dist/components/DrillDownDimensions/DimensionSection.d.ts +11 -0
- package/dist/components/DrillDownDimensions/index.d.ts +13 -0
- package/dist/components/IconFont/index.d.ts +3 -0
- package/dist/components/MetricOptions/index.d.ts +11 -0
- package/dist/components/RecommendOptions/index.d.ts +9 -0
- package/dist/components/Tools/FeedbackModal.d.ts +9 -0
- package/dist/components/Tools/index.d.ts +12 -0
- package/dist/demo/Chat.d.ts +2 -0
- package/dist/demo/ChatDemo.d.ts +4 -0
- package/dist/demo/CopilotDemo.d.ts +2 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useComposing.d.ts +5 -0
- package/dist/hooks/useExportByEcharts.d.ts +10 -0
- package/dist/hooks/useMethodRegister.d.ts +4 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.es.js +1 -0
- package/dist/service/axiosInstance.d.ts +3 -0
- package/dist/service/index.d.ts +25 -0
- package/dist/utils/utils.d.ts +45 -0
- package/package.json +214 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +43 -0
- package/public/manifest.json +15 -0
- package/public/robots.txt +3 -0
- package/rollup/rollup.config.mjs +37 -0
- package/rollup/rollup.esm.config.mjs +21 -0
- package/rollup/rollup.umd.config.mjs +30 -0
- package/scripts/build.js +217 -0
- package/scripts/start.js +154 -0
- package/scripts/test.js +52 -0
- package/src/Chat/AgentList/index.tsx +52 -0
- package/src/Chat/AgentList/style.module.less +83 -0
- package/src/Chat/ChatFooter/index.tsx +423 -0
- package/src/Chat/ChatFooter/style.module.less +225 -0
- package/src/Chat/Conversation/index.tsx +236 -0
- package/src/Chat/Conversation/style.module.less +171 -0
- package/src/Chat/MessageContainer/index.tsx +145 -0
- package/src/Chat/MessageContainer/style.module.less +53 -0
- package/src/Chat/MobileAgents/index.tsx +62 -0
- package/src/Chat/MobileAgents/style.module.less +55 -0
- package/src/Chat/components/AgentTip/index.tsx +48 -0
- package/src/Chat/components/AgentTip/style.module.less +44 -0
- package/src/Chat/components/ConversationModal/index.tsx +65 -0
- package/src/Chat/components/CopilotAvatar/index.tsx +8 -0
- package/src/Chat/components/CopilotAvatar/style.module.less +13 -0
- package/src/Chat/components/Message.tsx +38 -0
- package/src/Chat/components/RecommendQuestions/index.tsx +64 -0
- package/src/Chat/components/RecommendQuestions/style.module.less +36 -0
- package/src/Chat/components/Text.tsx +42 -0
- package/src/Chat/components/style.module.less +311 -0
- package/src/Chat/constants.ts +37 -0
- package/src/Chat/index.tsx +526 -0
- package/src/Chat/service.ts +49 -0
- package/src/Chat/style.module.less +119 -0
- package/src/Chat/type.ts +107 -0
- package/src/Copilot/constants.ts +11 -0
- package/src/Copilot/index.tsx +149 -0
- package/src/Copilot/style.module.less +151 -0
- package/src/ShowCase/index.tsx +120 -0
- package/src/ShowCase/service.ts +12 -0
- package/src/ShowCase/style.module.less +46 -0
- package/src/ShowCase/type.ts +14 -0
- package/src/common/constants.ts +93 -0
- package/src/common/env.ts +5 -0
- package/src/common/type.ts +270 -0
- package/src/components/ChatItem/ExecuteItem.tsx +210 -0
- package/src/components/ChatItem/ExpandParseTip.tsx +333 -0
- package/src/components/ChatItem/FilterItem.tsx +209 -0
- package/src/components/ChatItem/Loading.tsx +14 -0
- package/src/components/ChatItem/ParseTip.tsx +322 -0
- package/src/components/ChatItem/ParseTipUtils.tsx +205 -0
- package/src/components/ChatItem/SimilarQuestionItem.tsx +84 -0
- package/src/components/ChatItem/SqlItem.tsx +410 -0
- package/src/components/ChatItem/SwitchEntity.tsx +52 -0
- package/src/components/ChatItem/Text.tsx +17 -0
- package/src/components/ChatItem/Typing.tsx +19 -0
- package/src/components/ChatItem/index.tsx +843 -0
- package/src/components/ChatItem/style.less +670 -0
- package/src/components/ChatMsg/ApplyAuth/index.tsx +30 -0
- package/src/components/ChatMsg/ApplyAuth/style.less +13 -0
- package/src/components/ChatMsg/Bar/index.tsx +208 -0
- package/src/components/ChatMsg/Bar/style.less +60 -0
- package/src/components/ChatMsg/DateOptions/index.tsx +46 -0
- package/src/components/ChatMsg/DateOptions/style.less +43 -0
- package/src/components/ChatMsg/FilterSection/index.tsx +42 -0
- package/src/components/ChatMsg/FilterSection/style.less +37 -0
- package/src/components/ChatMsg/MarkDown/index.tsx +26 -0
- package/src/components/ChatMsg/MarkDown/style.less +9 -0
- package/src/components/ChatMsg/Message/index.tsx +105 -0
- package/src/components/ChatMsg/Message/style.less +119 -0
- package/src/components/ChatMsg/MetricCard/PeriodCompareItem.tsx +29 -0
- package/src/components/ChatMsg/MetricCard/index.tsx +80 -0
- package/src/components/ChatMsg/MetricCard/style.less +126 -0
- package/src/components/ChatMsg/MetricTrend/MetricInfo.tsx +60 -0
- package/src/components/ChatMsg/MetricTrend/MetricTrendChart.tsx +235 -0
- package/src/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.tsx +162 -0
- package/src/components/ChatMsg/MetricTrend/index.tsx +127 -0
- package/src/components/ChatMsg/MetricTrend/style.less +195 -0
- package/src/components/ChatMsg/NoPermissionChart/index.tsx +28 -0
- package/src/components/ChatMsg/NoPermissionChart/style.less +26 -0
- package/src/components/ChatMsg/Pie/PieChart.tsx +120 -0
- package/src/components/ChatMsg/Pie/index.tsx +88 -0
- package/src/components/ChatMsg/Pie/style.less +43 -0
- package/src/components/ChatMsg/Table/index.tsx +103 -0
- package/src/components/ChatMsg/Table/style.less +131 -0
- package/src/components/ChatMsg/Text/index.tsx +70 -0
- package/src/components/ChatMsg/Text/style.less +38 -0
- package/src/components/ChatMsg/WebPage/index.tsx +125 -0
- package/src/components/ChatMsg/index.tsx +428 -0
- package/src/components/ChatMsg/style.less +28 -0
- package/src/components/DrillDownDimensions/DimensionSection.tsx +99 -0
- package/src/components/DrillDownDimensions/index.tsx +76 -0
- package/src/components/DrillDownDimensions/style.less +64 -0
- package/src/components/IconFont/index.tsx +7 -0
- package/src/components/MetricOptions/index.tsx +75 -0
- package/src/components/MetricOptions/style.less +69 -0
- package/src/components/RecommendOptions/index.tsx +126 -0
- package/src/components/RecommendOptions/style.less +24 -0
- package/src/components/Tools/FeedbackModal.tsx +55 -0
- package/src/components/Tools/index.tsx +126 -0
- package/src/components/Tools/style.less +67 -0
- package/src/demo/Chat.tsx +73 -0
- package/src/demo/ChatDemo.tsx +14 -0
- package/src/demo/CopilotDemo.tsx +43 -0
- package/src/demo/style.module.less +19 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useComposing.ts +31 -0
- package/src/hooks/useExportByEcharts.ts +41 -0
- package/src/hooks/useMethodRegister.ts +25 -0
- package/src/index.tsx +44 -0
- package/src/service/axiosInstance.ts +58 -0
- package/src/service/index.ts +174 -0
- package/src/setupProxy.js +18 -0
- package/src/setupTests.ts +5 -0
- package/src/styles/global.less +52 -0
- package/src/styles/index.less +39 -0
- package/src/styles/reboot.less +14 -0
- package/src/styles/variables.less +80 -0
- package/src/typings.d.ts +179 -0
- package/src/utils/utils.ts +346 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { Dropdown, Input, Menu } from 'antd';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useState,
|
|
6
|
+
forwardRef,
|
|
7
|
+
ForwardRefRenderFunction,
|
|
8
|
+
useImperativeHandle,
|
|
9
|
+
memo,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import ConversationModal from '../components/ConversationModal';
|
|
12
|
+
import { deleteConversation, getAllConversations, saveConversation } from '../service';
|
|
13
|
+
import styles from './style.module.less';
|
|
14
|
+
import { AgentType, ConversationDetailType } from '../type';
|
|
15
|
+
import { DEFAULT_CONVERSATION_NAME } from '../constants';
|
|
16
|
+
import moment from 'moment';
|
|
17
|
+
import { CloseOutlined, DeleteOutlined, SearchOutlined } from '@ant-design/icons';
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
currentAgent?: AgentType;
|
|
21
|
+
currentConversation?: ConversationDetailType;
|
|
22
|
+
historyVisible?: boolean;
|
|
23
|
+
onSelectConversation: (
|
|
24
|
+
conversation: ConversationDetailType,
|
|
25
|
+
sendMsgParams?: any,
|
|
26
|
+
isAdd?: boolean
|
|
27
|
+
) => void;
|
|
28
|
+
onCloseConversation: () => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const Conversation: ForwardRefRenderFunction<any, Props> = (
|
|
32
|
+
{ currentAgent, currentConversation, historyVisible, onSelectConversation, onCloseConversation },
|
|
33
|
+
ref
|
|
34
|
+
) => {
|
|
35
|
+
const [conversations, setConversations] = useState<ConversationDetailType[]>([]);
|
|
36
|
+
const [editModalVisible, setEditModalVisible] = useState(false);
|
|
37
|
+
const [editConversation, setEditConversation] = useState<ConversationDetailType>();
|
|
38
|
+
const [searchValue, setSearchValue] = useState('');
|
|
39
|
+
|
|
40
|
+
useImperativeHandle(ref, () => ({
|
|
41
|
+
updateData,
|
|
42
|
+
onAddConversation,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
const updateData = async (agentId?: number) => {
|
|
46
|
+
const { data } = await getAllConversations(agentId || currentAgent!.id);
|
|
47
|
+
const conversationList = data || [];
|
|
48
|
+
setConversations(conversationList.slice(0, 200));
|
|
49
|
+
return conversationList;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const initData = async () => {
|
|
53
|
+
const data = await updateData();
|
|
54
|
+
if (data.length > 0) {
|
|
55
|
+
onSelectConversation(data[0]);
|
|
56
|
+
} else {
|
|
57
|
+
onAddConversation();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (currentAgent) {
|
|
63
|
+
if (currentAgent.initialSendMsgParams) {
|
|
64
|
+
onAddConversation(currentAgent.initialSendMsgParams);
|
|
65
|
+
} else {
|
|
66
|
+
initData();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [currentAgent]);
|
|
70
|
+
|
|
71
|
+
const addConversation = async (sendMsgParams?: any) => {
|
|
72
|
+
const agentId = sendMsgParams?.agentId || currentAgent!.id;
|
|
73
|
+
await saveConversation(DEFAULT_CONVERSATION_NAME, agentId);
|
|
74
|
+
return updateData(agentId);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const onDeleteConversation = async (id: number) => {
|
|
78
|
+
await deleteConversation(id);
|
|
79
|
+
initData();
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const onAddConversation = async (sendMsgParams?: any) => {
|
|
83
|
+
const data = await addConversation(sendMsgParams);
|
|
84
|
+
if (data.length > 0) {
|
|
85
|
+
onSelectConversation(data[0], sendMsgParams, true);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const onOperate = (key: string, conversation: ConversationDetailType) => {
|
|
90
|
+
if (key === 'editName') {
|
|
91
|
+
setEditConversation(conversation);
|
|
92
|
+
setEditModalVisible(true);
|
|
93
|
+
} else if (key === 'delete') {
|
|
94
|
+
onDeleteConversation(conversation.chatId);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const conversationClass = classNames(styles.conversation, {
|
|
99
|
+
[styles.historyVisible]: historyVisible,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const convertTime = (date: string) => {
|
|
103
|
+
moment.locale('zh-cn');
|
|
104
|
+
const now = moment();
|
|
105
|
+
const inputDate = moment(date);
|
|
106
|
+
const diffMinutes = now.diff(inputDate, 'minutes');
|
|
107
|
+
if (diffMinutes < 1) {
|
|
108
|
+
return '刚刚';
|
|
109
|
+
} else if (inputDate.isSame(now, 'day')) {
|
|
110
|
+
return inputDate.format('HH:mm');
|
|
111
|
+
} else if (inputDate.isSame(now.subtract(1, 'day'), 'day')) {
|
|
112
|
+
return '昨天';
|
|
113
|
+
}
|
|
114
|
+
return inputDate.format('MM/DD');
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const onSearchValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
118
|
+
setSearchValue(e.target.value);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div className={conversationClass}>
|
|
123
|
+
<div className={styles.rightSection}>
|
|
124
|
+
<div className={styles.titleBar}>
|
|
125
|
+
<div className={styles.title}>历史对话</div>
|
|
126
|
+
<div className={styles.rightOperation}>
|
|
127
|
+
<div
|
|
128
|
+
className={styles.newConversation}
|
|
129
|
+
onClick={() => {
|
|
130
|
+
addConversation();
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
新对话
|
|
134
|
+
</div>
|
|
135
|
+
<CloseOutlined className={styles.closeIcon} onClick={onCloseConversation} />
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
<div className={styles.searchConversation}>
|
|
139
|
+
<Input
|
|
140
|
+
placeholder="搜索"
|
|
141
|
+
prefix={<SearchOutlined className={styles.searchIcon} />}
|
|
142
|
+
className={styles.searchTask}
|
|
143
|
+
value={searchValue}
|
|
144
|
+
onChange={onSearchValueChange}
|
|
145
|
+
allowClear
|
|
146
|
+
/>
|
|
147
|
+
</div>
|
|
148
|
+
<div className={styles.conversationList}>
|
|
149
|
+
{conversations
|
|
150
|
+
.filter(
|
|
151
|
+
conversation =>
|
|
152
|
+
searchValue === '' ||
|
|
153
|
+
conversation.chatName.toLowerCase().includes(searchValue.toLowerCase())
|
|
154
|
+
)
|
|
155
|
+
.map(item => {
|
|
156
|
+
const conversationItemClass = classNames(styles.conversationItem, {
|
|
157
|
+
[styles.activeConversationItem]: currentConversation?.chatId === item.chatId,
|
|
158
|
+
});
|
|
159
|
+
return (
|
|
160
|
+
<Dropdown
|
|
161
|
+
key={item.chatId}
|
|
162
|
+
overlay={
|
|
163
|
+
<Menu
|
|
164
|
+
items={[
|
|
165
|
+
{ label: '修改对话名称', key: 'editName' },
|
|
166
|
+
{ label: '删除', key: 'delete' },
|
|
167
|
+
]}
|
|
168
|
+
onClick={({ key }) => {
|
|
169
|
+
onOperate(key, item);
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
}
|
|
173
|
+
trigger={['contextMenu']}
|
|
174
|
+
>
|
|
175
|
+
<div
|
|
176
|
+
className={conversationItemClass}
|
|
177
|
+
onClick={() => {
|
|
178
|
+
onSelectConversation(item);
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<div className={styles.conversationContent}>
|
|
182
|
+
<div className={styles.topTitleBar}>
|
|
183
|
+
<div className={styles.conversationTitleBar}>
|
|
184
|
+
<div className={styles.conversationName}>{item.chatName}</div>
|
|
185
|
+
{currentConversation?.chatId === item.chatId && (
|
|
186
|
+
<div className={styles.currentConversation}>当前对话</div>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
<div className={styles.conversationTime}>
|
|
190
|
+
{convertTime(item.lastTime || '')}
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
<div className={styles.bottomSection}>
|
|
194
|
+
<div className={styles.subTitle}>{item.lastQuestion}</div>
|
|
195
|
+
<DeleteOutlined
|
|
196
|
+
className={styles.deleteIcon}
|
|
197
|
+
onClick={e => {
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
onDeleteConversation(item.chatId);
|
|
200
|
+
}}
|
|
201
|
+
/>
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</Dropdown>
|
|
206
|
+
);
|
|
207
|
+
})}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
<ConversationModal
|
|
211
|
+
visible={editModalVisible}
|
|
212
|
+
editConversation={editConversation}
|
|
213
|
+
onClose={() => {
|
|
214
|
+
setEditModalVisible(false);
|
|
215
|
+
}}
|
|
216
|
+
onFinish={() => {
|
|
217
|
+
setEditModalVisible(false);
|
|
218
|
+
updateData();
|
|
219
|
+
}}
|
|
220
|
+
/>
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
function areEqual(prevProps: Props, nextProps: Props) {
|
|
226
|
+
if (
|
|
227
|
+
prevProps.currentAgent?.id === nextProps.currentAgent?.id &&
|
|
228
|
+
prevProps.currentConversation?.chatId === nextProps.currentConversation?.chatId &&
|
|
229
|
+
prevProps.historyVisible === nextProps.historyVisible
|
|
230
|
+
) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export default memo(forwardRef(Conversation), areEqual);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
.conversation {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 0;
|
|
4
|
+
height: 100%;
|
|
5
|
+
background: #fff;
|
|
6
|
+
|
|
7
|
+
.rightSection {
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
|
|
11
|
+
.titleBar {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
|
|
16
|
+
.title {
|
|
17
|
+
color: var(--text-color);
|
|
18
|
+
font-weight: 500;
|
|
19
|
+
font-size: 15px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.rightOperation {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
column-gap: 12px;
|
|
26
|
+
|
|
27
|
+
.newConversation {
|
|
28
|
+
color: var(--text-color);
|
|
29
|
+
font-size: 14px;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
|
|
32
|
+
&:hover {
|
|
33
|
+
color: var(--chat-blue);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.closeIcon {
|
|
38
|
+
color: var(--text-color);
|
|
39
|
+
font-size: 16px;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
|
|
42
|
+
&:hover {
|
|
43
|
+
color: var(--chat-blue);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.searchConversation {
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
padding: 12px 0 10px;
|
|
53
|
+
|
|
54
|
+
.searchIcon {
|
|
55
|
+
color: #999 !important;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.searchTask {
|
|
59
|
+
font-size: 13px;
|
|
60
|
+
background-color: #f5f5f5;
|
|
61
|
+
border: 0;
|
|
62
|
+
border-radius: 4px;
|
|
63
|
+
box-shadow: none !important;
|
|
64
|
+
|
|
65
|
+
:global {
|
|
66
|
+
.ant-input {
|
|
67
|
+
font-size: 13px !important;
|
|
68
|
+
background-color: transparent !important;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.conversationList {
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: column;
|
|
77
|
+
height: calc(100% - 70px);
|
|
78
|
+
padding: 2px 0 0;
|
|
79
|
+
overflow-y: auto;
|
|
80
|
+
row-gap: 12px;
|
|
81
|
+
|
|
82
|
+
.conversationItem {
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
padding: 8px 12px;
|
|
86
|
+
border: 1px solid #efefef;
|
|
87
|
+
border-radius: 8px;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
|
|
90
|
+
.conversationContent {
|
|
91
|
+
width: 100%;
|
|
92
|
+
|
|
93
|
+
.topTitleBar {
|
|
94
|
+
display: flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
justify-content: space-between;
|
|
97
|
+
width: 100%;
|
|
98
|
+
|
|
99
|
+
.conversationTitleBar {
|
|
100
|
+
display: flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
column-gap: 6px;
|
|
103
|
+
|
|
104
|
+
.conversationName {
|
|
105
|
+
max-width: 300px;
|
|
106
|
+
margin-right: 2px;
|
|
107
|
+
overflow: hidden;
|
|
108
|
+
color: var(--text-color);
|
|
109
|
+
font-weight: 500;
|
|
110
|
+
font-size: 14px;
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
text-overflow: ellipsis;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.currentConversation {
|
|
116
|
+
padding: 0 4px;
|
|
117
|
+
color: var(--chat-blue);
|
|
118
|
+
font-size: 12px;
|
|
119
|
+
background-color: var(--light-blue-background);
|
|
120
|
+
border-radius: 4px;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.conversationTime {
|
|
125
|
+
color: var(--text-color-six);
|
|
126
|
+
font-size: 12px;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.bottomSection {
|
|
131
|
+
display: flex;
|
|
132
|
+
align-items: center;
|
|
133
|
+
justify-content: space-between;
|
|
134
|
+
margin-top: 4px;
|
|
135
|
+
|
|
136
|
+
.subTitle {
|
|
137
|
+
width: 350px;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
color: var(--text-color-six);
|
|
140
|
+
font-size: 12px;
|
|
141
|
+
white-space: nowrap;
|
|
142
|
+
text-overflow: ellipsis;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.deleteIcon {
|
|
146
|
+
color: var(--text-color-six);
|
|
147
|
+
font-size: 14px;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
|
|
150
|
+
&:hover {
|
|
151
|
+
color: var(--chat-blue);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&:hover,
|
|
158
|
+
&.activeConversationItem {
|
|
159
|
+
background-color: #f0f0f0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
&.historyVisible {
|
|
166
|
+
width: 400px;
|
|
167
|
+
padding: 10px 16px;
|
|
168
|
+
border-left: 1px solid #f1f1f1;
|
|
169
|
+
z-index: 99;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import Text from '../components/Text';
|
|
2
|
+
import { memo, useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { isEqual } from 'lodash';
|
|
4
|
+
import { AgentType, MessageItem, MessageTypeEnum } from '../type';
|
|
5
|
+
import { isMobile, updateMessageContainerScroll } from '../../utils/utils';
|
|
6
|
+
import styles from './style.module.less';
|
|
7
|
+
import AgentTip from '../components/AgentTip';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import { MsgDataType } from '../../common/type';
|
|
10
|
+
import ChatItem from '../../components/ChatItem';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
id: string;
|
|
14
|
+
chatId: number;
|
|
15
|
+
messageList: MessageItem[];
|
|
16
|
+
historyVisible: boolean;
|
|
17
|
+
currentAgent?: AgentType;
|
|
18
|
+
chatVisible?: boolean;
|
|
19
|
+
isDeveloper?: boolean;
|
|
20
|
+
integrateSystem?: string;
|
|
21
|
+
isSimpleMode?: boolean;
|
|
22
|
+
isDebugMode?: boolean;
|
|
23
|
+
onMsgDataLoaded: (
|
|
24
|
+
data: MsgDataType,
|
|
25
|
+
questionId: string | number,
|
|
26
|
+
question: string,
|
|
27
|
+
valid: boolean,
|
|
28
|
+
isRefresh?: boolean
|
|
29
|
+
) => void;
|
|
30
|
+
onSendMsg: (value: string) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const MessageContainer: React.FC<Props> = ({
|
|
34
|
+
id,
|
|
35
|
+
chatId,
|
|
36
|
+
messageList,
|
|
37
|
+
historyVisible,
|
|
38
|
+
currentAgent,
|
|
39
|
+
chatVisible,
|
|
40
|
+
isDeveloper,
|
|
41
|
+
integrateSystem,
|
|
42
|
+
isSimpleMode,
|
|
43
|
+
isDebugMode,
|
|
44
|
+
onMsgDataLoaded,
|
|
45
|
+
onSendMsg,
|
|
46
|
+
}) => {
|
|
47
|
+
const [triggerResize, setTriggerResize] = useState(false);
|
|
48
|
+
const onResize = useCallback(() => {
|
|
49
|
+
setTriggerResize(true);
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
setTriggerResize(false);
|
|
52
|
+
}, 0);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
window.addEventListener('resize', onResize);
|
|
57
|
+
return () => {
|
|
58
|
+
window.removeEventListener('resize', onResize);
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
onResize();
|
|
64
|
+
}, [historyVisible, chatVisible]);
|
|
65
|
+
|
|
66
|
+
const messageContainerClass = classNames(styles.messageContainer, { [styles.mobile]: isMobile });
|
|
67
|
+
return (
|
|
68
|
+
<div id={id} className={messageContainerClass}>
|
|
69
|
+
<div className={styles.messageList}>
|
|
70
|
+
{messageList.map((msgItem: MessageItem, index: number) => {
|
|
71
|
+
const {
|
|
72
|
+
id: msgId,
|
|
73
|
+
questionId,
|
|
74
|
+
modelId,
|
|
75
|
+
agentId,
|
|
76
|
+
type,
|
|
77
|
+
msg,
|
|
78
|
+
msgValue,
|
|
79
|
+
score,
|
|
80
|
+
identityMsg,
|
|
81
|
+
parseInfos,
|
|
82
|
+
parseTimeCost,
|
|
83
|
+
msgData,
|
|
84
|
+
filters,
|
|
85
|
+
} = msgItem;
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div key={msgId} id={`${msgId}`} className={styles.messageItem}>
|
|
89
|
+
{type === MessageTypeEnum.TEXT && <Text position="left" data={msg} />}
|
|
90
|
+
{type === MessageTypeEnum.AGENT_LIST && (
|
|
91
|
+
<AgentTip currentAgent={currentAgent} onSendMsg={onSendMsg} />
|
|
92
|
+
)}
|
|
93
|
+
{type === MessageTypeEnum.QUESTION && (
|
|
94
|
+
<>
|
|
95
|
+
<Text position="right" data={msg} />
|
|
96
|
+
{identityMsg && <Text position="left" data={identityMsg} />}
|
|
97
|
+
<ChatItem
|
|
98
|
+
questionId={questionId}
|
|
99
|
+
currentAgent={currentAgent}
|
|
100
|
+
isSimpleMode={isSimpleMode}
|
|
101
|
+
isDebugMode={isDebugMode}
|
|
102
|
+
msg={msgValue || msg || ''}
|
|
103
|
+
parseInfos={parseInfos}
|
|
104
|
+
parseTimeCostValue={parseTimeCost}
|
|
105
|
+
msgData={msgData}
|
|
106
|
+
conversationId={chatId}
|
|
107
|
+
modelId={modelId}
|
|
108
|
+
agentId={agentId}
|
|
109
|
+
score={score}
|
|
110
|
+
filter={filters}
|
|
111
|
+
triggerResize={triggerResize}
|
|
112
|
+
isDeveloper={isDeveloper}
|
|
113
|
+
integrateSystem={integrateSystem}
|
|
114
|
+
onMsgDataLoaded={(data: MsgDataType, valid: boolean, isRefresh) => {
|
|
115
|
+
onMsgDataLoaded(data, msgId, msgValue || msg || '', valid, isRefresh);
|
|
116
|
+
}}
|
|
117
|
+
onUpdateMessageScroll={updateMessageContainerScroll}
|
|
118
|
+
onSendMsg={onSendMsg}
|
|
119
|
+
isLastMessage={index === messageList.length - 1}
|
|
120
|
+
/>
|
|
121
|
+
</>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
})}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
function areEqual(prevProps: Props, nextProps: Props) {
|
|
132
|
+
if (
|
|
133
|
+
prevProps.id === nextProps.id &&
|
|
134
|
+
isEqual(prevProps.messageList, nextProps.messageList) &&
|
|
135
|
+
prevProps.historyVisible === nextProps.historyVisible &&
|
|
136
|
+
prevProps.currentAgent === nextProps.currentAgent &&
|
|
137
|
+
prevProps.chatVisible === nextProps.chatVisible &&
|
|
138
|
+
prevProps.isSimpleMode === nextProps.isSimpleMode
|
|
139
|
+
) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export default memo(MessageContainer, areEqual);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.messageContainer {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex: 1;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
min-height: 0;
|
|
7
|
+
overflow-x: hidden;
|
|
8
|
+
overflow-y: scroll;
|
|
9
|
+
|
|
10
|
+
.messageList {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
padding: 70px 20px 60px 14px;
|
|
14
|
+
row-gap: 16px;
|
|
15
|
+
|
|
16
|
+
.messageItem {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
row-gap: 20px;
|
|
20
|
+
|
|
21
|
+
:global {
|
|
22
|
+
.ant-table-small {
|
|
23
|
+
.ant-table-tbody {
|
|
24
|
+
.ant-table-cell {
|
|
25
|
+
padding: 6px 0 !important;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
.ss-chat-table-formatted-value {
|
|
29
|
+
font-size: 15px !important;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
.ant-table-row {
|
|
33
|
+
background-color: #fff;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.ant-table-tbody > tr > td {
|
|
37
|
+
border-bottom: 1px solid #f0f0f0;
|
|
38
|
+
transition: background 0.2s, border-color 0.2s;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ss-chat-table-even-row {
|
|
42
|
+
background-color: #fbfbfb;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&.mobile {
|
|
49
|
+
.messageList {
|
|
50
|
+
padding: 20px 10px 30px;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import IconFont from '../../components/IconFont';
|
|
2
|
+
import { Drawer } from 'antd';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { AGENT_ICONS } from '../constants';
|
|
5
|
+
import { AgentType } from '../type';
|
|
6
|
+
import styles from './style.module.less';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
open: boolean;
|
|
10
|
+
agentList: AgentType[];
|
|
11
|
+
currentAgent?: AgentType;
|
|
12
|
+
onSelectAgent: (agent: AgentType) => void;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const MobileAgents: React.FC<Props> = ({
|
|
17
|
+
open,
|
|
18
|
+
agentList,
|
|
19
|
+
currentAgent,
|
|
20
|
+
onSelectAgent,
|
|
21
|
+
onClose,
|
|
22
|
+
}) => {
|
|
23
|
+
return (
|
|
24
|
+
<Drawer
|
|
25
|
+
title="智能助理"
|
|
26
|
+
placement="bottom"
|
|
27
|
+
open={open}
|
|
28
|
+
height="85%"
|
|
29
|
+
className={styles.mobileAgents}
|
|
30
|
+
onClose={onClose}
|
|
31
|
+
>
|
|
32
|
+
<div className={styles.agentListContent}>
|
|
33
|
+
{agentList.map((agent, index) => {
|
|
34
|
+
const agentItemClass = classNames(styles.agentItem, {
|
|
35
|
+
[styles.active]: currentAgent?.id === agent.id,
|
|
36
|
+
});
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
key={agent.id}
|
|
40
|
+
className={agentItemClass}
|
|
41
|
+
onClick={() => {
|
|
42
|
+
onSelectAgent(agent);
|
|
43
|
+
onClose();
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<div className={styles.agentTitleBar}>
|
|
47
|
+
<IconFont
|
|
48
|
+
type={AGENT_ICONS[index % AGENT_ICONS.length]}
|
|
49
|
+
className={styles.avatar}
|
|
50
|
+
/>
|
|
51
|
+
<div className={styles.agentName}>{agent.name}</div>
|
|
52
|
+
</div>
|
|
53
|
+
<div className={styles.agentDesc}>{agent.description}</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
57
|
+
</div>
|
|
58
|
+
</Drawer>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default MobileAgents;
|