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.
Files changed (208) hide show
  1. package/.prettierrc.js +24 -0
  2. package/README.md +46 -0
  3. package/config/env.js +104 -0
  4. package/config/getHttpsConfig.js +66 -0
  5. package/config/jest/babelTransform.js +29 -0
  6. package/config/jest/cssTransform.js +14 -0
  7. package/config/jest/fileTransform.js +40 -0
  8. package/config/modules.js +134 -0
  9. package/config/paths.js +77 -0
  10. package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
  11. package/config/webpack.config.js +785 -0
  12. package/config/webpackDevServer.config.js +127 -0
  13. package/dist/Chat/AgentList/index.d.ts +9 -0
  14. package/dist/Chat/ChatFooter/index.d.ts +17 -0
  15. package/dist/Chat/Conversation/index.d.ts +11 -0
  16. package/dist/Chat/MessageContainer/index.d.ts +19 -0
  17. package/dist/Chat/MobileAgents/index.d.ts +11 -0
  18. package/dist/Chat/components/AgentTip/index.d.ts +8 -0
  19. package/dist/Chat/components/ConversationModal/index.d.ts +10 -0
  20. package/dist/Chat/components/CopilotAvatar/index.d.ts +2 -0
  21. package/dist/Chat/components/Message.d.ts +10 -0
  22. package/dist/Chat/components/RecommendQuestions/index.d.ts +6 -0
  23. package/dist/Chat/components/Text.d.ts +9 -0
  24. package/dist/Chat/constants.d.ts +19 -0
  25. package/dist/Chat/index.d.ts +17 -0
  26. package/dist/Chat/service.d.ts +11 -0
  27. package/dist/Chat/type.d.ts +97 -0
  28. package/dist/Copilot/constants.d.ts +11 -0
  29. package/dist/Copilot/index.d.ts +13 -0
  30. package/dist/ShowCase/index.d.ts +8 -0
  31. package/dist/ShowCase/service.d.ts +2 -0
  32. package/dist/ShowCase/type.d.ts +11 -0
  33. package/dist/common/constants.d.ts +58 -0
  34. package/dist/common/env.d.ts +3 -0
  35. package/dist/common/type.d.ts +247 -0
  36. package/dist/components/ChatItem/ExecuteItem.d.ts +25 -0
  37. package/dist/components/ChatItem/ExpandParseTip.d.ts +20 -0
  38. package/dist/components/ChatItem/FilterItem.d.ts +17 -0
  39. package/dist/components/ChatItem/Loading.d.ts +2 -0
  40. package/dist/components/ChatItem/ParseTip.d.ts +26 -0
  41. package/dist/components/ChatItem/ParseTipUtils.d.ts +10 -0
  42. package/dist/components/ChatItem/SimilarQuestionItem.d.ts +10 -0
  43. package/dist/components/ChatItem/SqlItem.d.ts +17 -0
  44. package/dist/components/ChatItem/SwitchEntity.d.ts +9 -0
  45. package/dist/components/ChatItem/Text.d.ts +6 -0
  46. package/dist/components/ChatItem/Typing.d.ts +2 -0
  47. package/dist/components/ChatItem/index.d.ts +33 -0
  48. package/dist/components/ChatMsg/ApplyAuth/index.d.ts +7 -0
  49. package/dist/components/ChatMsg/Bar/index.d.ts +13 -0
  50. package/dist/components/ChatMsg/DateOptions/index.d.ts +9 -0
  51. package/dist/components/ChatMsg/FilterSection/index.d.ts +8 -0
  52. package/dist/components/ChatMsg/MarkDown/index.d.ts +10 -0
  53. package/dist/components/ChatMsg/Message/index.d.ts +18 -0
  54. package/dist/components/ChatMsg/MetricCard/PeriodCompareItem.d.ts +7 -0
  55. package/dist/components/ChatMsg/MetricCard/index.d.ts +10 -0
  56. package/dist/components/ChatMsg/MetricTrend/MetricInfo.d.ts +8 -0
  57. package/dist/components/ChatMsg/MetricTrend/MetricTrendChart.d.ts +14 -0
  58. package/dist/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.d.ts +12 -0
  59. package/dist/components/ChatMsg/MetricTrend/index.d.ts +16 -0
  60. package/dist/components/ChatMsg/NoPermissionChart/index.d.ts +8 -0
  61. package/dist/components/ChatMsg/Pie/PieChart.d.ts +11 -0
  62. package/dist/components/ChatMsg/Pie/index.d.ts +14 -0
  63. package/dist/components/ChatMsg/Table/index.d.ts +12 -0
  64. package/dist/components/ChatMsg/Text/index.d.ts +9 -0
  65. package/dist/components/ChatMsg/WebPage/index.d.ts +8 -0
  66. package/dist/components/ChatMsg/index.d.ts +15 -0
  67. package/dist/components/DrillDownDimensions/DimensionSection.d.ts +11 -0
  68. package/dist/components/DrillDownDimensions/index.d.ts +13 -0
  69. package/dist/components/IconFont/index.d.ts +3 -0
  70. package/dist/components/MetricOptions/index.d.ts +11 -0
  71. package/dist/components/RecommendOptions/index.d.ts +9 -0
  72. package/dist/components/Tools/FeedbackModal.d.ts +9 -0
  73. package/dist/components/Tools/index.d.ts +12 -0
  74. package/dist/demo/Chat.d.ts +2 -0
  75. package/dist/demo/ChatDemo.d.ts +4 -0
  76. package/dist/demo/CopilotDemo.d.ts +2 -0
  77. package/dist/hooks/index.d.ts +3 -0
  78. package/dist/hooks/useComposing.d.ts +5 -0
  79. package/dist/hooks/useExportByEcharts.d.ts +10 -0
  80. package/dist/hooks/useMethodRegister.d.ts +4 -0
  81. package/dist/index.d.ts +10 -0
  82. package/dist/index.es.js +1 -0
  83. package/dist/service/axiosInstance.d.ts +3 -0
  84. package/dist/service/index.d.ts +25 -0
  85. package/dist/utils/utils.d.ts +45 -0
  86. package/package.json +214 -0
  87. package/public/favicon.ico +0 -0
  88. package/public/index.html +43 -0
  89. package/public/manifest.json +15 -0
  90. package/public/robots.txt +3 -0
  91. package/rollup/rollup.config.mjs +37 -0
  92. package/rollup/rollup.esm.config.mjs +21 -0
  93. package/rollup/rollup.umd.config.mjs +30 -0
  94. package/scripts/build.js +217 -0
  95. package/scripts/start.js +154 -0
  96. package/scripts/test.js +52 -0
  97. package/src/Chat/AgentList/index.tsx +52 -0
  98. package/src/Chat/AgentList/style.module.less +83 -0
  99. package/src/Chat/ChatFooter/index.tsx +423 -0
  100. package/src/Chat/ChatFooter/style.module.less +225 -0
  101. package/src/Chat/Conversation/index.tsx +236 -0
  102. package/src/Chat/Conversation/style.module.less +171 -0
  103. package/src/Chat/MessageContainer/index.tsx +145 -0
  104. package/src/Chat/MessageContainer/style.module.less +53 -0
  105. package/src/Chat/MobileAgents/index.tsx +62 -0
  106. package/src/Chat/MobileAgents/style.module.less +55 -0
  107. package/src/Chat/components/AgentTip/index.tsx +48 -0
  108. package/src/Chat/components/AgentTip/style.module.less +44 -0
  109. package/src/Chat/components/ConversationModal/index.tsx +65 -0
  110. package/src/Chat/components/CopilotAvatar/index.tsx +8 -0
  111. package/src/Chat/components/CopilotAvatar/style.module.less +13 -0
  112. package/src/Chat/components/Message.tsx +38 -0
  113. package/src/Chat/components/RecommendQuestions/index.tsx +64 -0
  114. package/src/Chat/components/RecommendQuestions/style.module.less +36 -0
  115. package/src/Chat/components/Text.tsx +42 -0
  116. package/src/Chat/components/style.module.less +311 -0
  117. package/src/Chat/constants.ts +37 -0
  118. package/src/Chat/index.tsx +526 -0
  119. package/src/Chat/service.ts +49 -0
  120. package/src/Chat/style.module.less +119 -0
  121. package/src/Chat/type.ts +107 -0
  122. package/src/Copilot/constants.ts +11 -0
  123. package/src/Copilot/index.tsx +149 -0
  124. package/src/Copilot/style.module.less +151 -0
  125. package/src/ShowCase/index.tsx +120 -0
  126. package/src/ShowCase/service.ts +12 -0
  127. package/src/ShowCase/style.module.less +46 -0
  128. package/src/ShowCase/type.ts +14 -0
  129. package/src/common/constants.ts +93 -0
  130. package/src/common/env.ts +5 -0
  131. package/src/common/type.ts +270 -0
  132. package/src/components/ChatItem/ExecuteItem.tsx +210 -0
  133. package/src/components/ChatItem/ExpandParseTip.tsx +333 -0
  134. package/src/components/ChatItem/FilterItem.tsx +209 -0
  135. package/src/components/ChatItem/Loading.tsx +14 -0
  136. package/src/components/ChatItem/ParseTip.tsx +322 -0
  137. package/src/components/ChatItem/ParseTipUtils.tsx +205 -0
  138. package/src/components/ChatItem/SimilarQuestionItem.tsx +84 -0
  139. package/src/components/ChatItem/SqlItem.tsx +410 -0
  140. package/src/components/ChatItem/SwitchEntity.tsx +52 -0
  141. package/src/components/ChatItem/Text.tsx +17 -0
  142. package/src/components/ChatItem/Typing.tsx +19 -0
  143. package/src/components/ChatItem/index.tsx +843 -0
  144. package/src/components/ChatItem/style.less +670 -0
  145. package/src/components/ChatMsg/ApplyAuth/index.tsx +30 -0
  146. package/src/components/ChatMsg/ApplyAuth/style.less +13 -0
  147. package/src/components/ChatMsg/Bar/index.tsx +208 -0
  148. package/src/components/ChatMsg/Bar/style.less +60 -0
  149. package/src/components/ChatMsg/DateOptions/index.tsx +46 -0
  150. package/src/components/ChatMsg/DateOptions/style.less +43 -0
  151. package/src/components/ChatMsg/FilterSection/index.tsx +42 -0
  152. package/src/components/ChatMsg/FilterSection/style.less +37 -0
  153. package/src/components/ChatMsg/MarkDown/index.tsx +26 -0
  154. package/src/components/ChatMsg/MarkDown/style.less +9 -0
  155. package/src/components/ChatMsg/Message/index.tsx +105 -0
  156. package/src/components/ChatMsg/Message/style.less +119 -0
  157. package/src/components/ChatMsg/MetricCard/PeriodCompareItem.tsx +29 -0
  158. package/src/components/ChatMsg/MetricCard/index.tsx +80 -0
  159. package/src/components/ChatMsg/MetricCard/style.less +126 -0
  160. package/src/components/ChatMsg/MetricTrend/MetricInfo.tsx +60 -0
  161. package/src/components/ChatMsg/MetricTrend/MetricTrendChart.tsx +235 -0
  162. package/src/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.tsx +162 -0
  163. package/src/components/ChatMsg/MetricTrend/index.tsx +127 -0
  164. package/src/components/ChatMsg/MetricTrend/style.less +195 -0
  165. package/src/components/ChatMsg/NoPermissionChart/index.tsx +28 -0
  166. package/src/components/ChatMsg/NoPermissionChart/style.less +26 -0
  167. package/src/components/ChatMsg/Pie/PieChart.tsx +120 -0
  168. package/src/components/ChatMsg/Pie/index.tsx +88 -0
  169. package/src/components/ChatMsg/Pie/style.less +43 -0
  170. package/src/components/ChatMsg/Table/index.tsx +103 -0
  171. package/src/components/ChatMsg/Table/style.less +131 -0
  172. package/src/components/ChatMsg/Text/index.tsx +70 -0
  173. package/src/components/ChatMsg/Text/style.less +38 -0
  174. package/src/components/ChatMsg/WebPage/index.tsx +125 -0
  175. package/src/components/ChatMsg/index.tsx +428 -0
  176. package/src/components/ChatMsg/style.less +28 -0
  177. package/src/components/DrillDownDimensions/DimensionSection.tsx +99 -0
  178. package/src/components/DrillDownDimensions/index.tsx +76 -0
  179. package/src/components/DrillDownDimensions/style.less +64 -0
  180. package/src/components/IconFont/index.tsx +7 -0
  181. package/src/components/MetricOptions/index.tsx +75 -0
  182. package/src/components/MetricOptions/style.less +69 -0
  183. package/src/components/RecommendOptions/index.tsx +126 -0
  184. package/src/components/RecommendOptions/style.less +24 -0
  185. package/src/components/Tools/FeedbackModal.tsx +55 -0
  186. package/src/components/Tools/index.tsx +126 -0
  187. package/src/components/Tools/style.less +67 -0
  188. package/src/demo/Chat.tsx +73 -0
  189. package/src/demo/ChatDemo.tsx +14 -0
  190. package/src/demo/CopilotDemo.tsx +43 -0
  191. package/src/demo/style.module.less +19 -0
  192. package/src/hooks/index.ts +3 -0
  193. package/src/hooks/useComposing.ts +31 -0
  194. package/src/hooks/useExportByEcharts.ts +41 -0
  195. package/src/hooks/useMethodRegister.ts +25 -0
  196. package/src/index.tsx +44 -0
  197. package/src/service/axiosInstance.ts +58 -0
  198. package/src/service/index.ts +174 -0
  199. package/src/setupProxy.js +18 -0
  200. package/src/setupTests.ts +5 -0
  201. package/src/styles/global.less +52 -0
  202. package/src/styles/index.less +39 -0
  203. package/src/styles/reboot.less +14 -0
  204. package/src/styles/variables.less +80 -0
  205. package/src/typings.d.ts +179 -0
  206. package/src/utils/utils.ts +346 -0
  207. package/tsconfig.build.json +20 -0
  208. package/tsconfig.json +27 -0
@@ -0,0 +1,526 @@
1
+ import { updateMessageContainerScroll, isMobile, uuid, setToken } from '../utils/utils';
2
+ import {
3
+ ForwardRefRenderFunction,
4
+ forwardRef,
5
+ useEffect,
6
+ useImperativeHandle,
7
+ useRef,
8
+ useState,
9
+ } from 'react';
10
+ import MessageContainer from './MessageContainer';
11
+ import styles from './style.module.less';
12
+ import { ConversationDetailType, MessageItem, MessageTypeEnum, AgentType } from './type';
13
+ import { queryAgentList } from './service';
14
+ import { useThrottleFn } from 'ahooks';
15
+ import Conversation from './Conversation';
16
+ import ChatFooter from './ChatFooter';
17
+ import classNames from 'classnames';
18
+ import { cloneDeep, isBoolean } from 'lodash';
19
+ import AgentList from './AgentList';
20
+ import MobileAgents from './MobileAgents';
21
+ import { HistoryMsgItemType, MsgDataType, SendMsgParamsType } from '../common/type';
22
+ import { getHistoryMsg } from '../service';
23
+ import ShowCase from '../ShowCase';
24
+ import { jsonParse } from '../utils/utils';
25
+ import { ConfigProvider, Drawer, Modal, Row, Col, Space, Switch, Tooltip } from 'antd';
26
+ import locale from 'antd/locale/zh_CN';
27
+ import dayjs from 'dayjs';
28
+ import 'dayjs/locale/zh-cn';
29
+
30
+ dayjs.locale('zh-cn');
31
+
32
+ type Props = {
33
+ token?: string;
34
+ agentIds?: number[];
35
+ initialAgentId?: number;
36
+ chatVisible?: boolean;
37
+ noInput?: boolean;
38
+ isDeveloper?: boolean;
39
+ integrateSystem?: string;
40
+ isCopilot?: boolean;
41
+ onCurrentAgentChange?: (agent?: AgentType) => void;
42
+ onReportMsgEvent?: (msg: string, valid: boolean) => void;
43
+ };
44
+
45
+ const Chat: ForwardRefRenderFunction<any, Props> = (
46
+ {
47
+ token,
48
+ agentIds,
49
+ initialAgentId,
50
+ chatVisible,
51
+ noInput,
52
+ isDeveloper,
53
+ integrateSystem,
54
+ isCopilot,
55
+ onCurrentAgentChange,
56
+ onReportMsgEvent,
57
+ },
58
+ ref
59
+ ) => {
60
+ const [messageList, setMessageList] = useState<MessageItem[]>([]);
61
+ const [inputMsg, setInputMsg] = useState('');
62
+ const [pageNo, setPageNo] = useState(1);
63
+ const [hasNextPage, setHasNextPage] = useState(false);
64
+ const [historyInited, setHistoryInited] = useState(false);
65
+ const [currentConversation, setCurrentConversation] = useState<
66
+ ConversationDetailType | undefined
67
+ >(isMobile ? { chatId: 0, chatName: '问答' } : undefined);
68
+ const [historyVisible, setHistoryVisible] = useState(false);
69
+ const [agentList, setAgentList] = useState<AgentType[]>([]);
70
+ const [currentAgent, setCurrentAgent] = useState<AgentType>();
71
+ const [mobileAgentsVisible, setMobileAgentsVisible] = useState(false);
72
+ const [agentListVisible, setAgentListVisible] = useState(true);
73
+ const [showCaseVisible, setShowCaseVisible] = useState(false);
74
+
75
+ const [isSimpleMode, setIsSimpleMode] = useState<boolean>(false);
76
+ const [isDebugMode, setIsDebugMode] = useState<boolean>(true);
77
+
78
+ const conversationRef = useRef<any>();
79
+ const chatFooterRef = useRef<any>();
80
+
81
+ useImperativeHandle(ref, () => ({
82
+ sendCopilotMsg,
83
+ }));
84
+
85
+ const sendCopilotMsg = (params: SendMsgParamsType) => {
86
+ setAgentListVisible(false);
87
+ const { agentId, msg, modelId } = params;
88
+ if (currentAgent?.id !== agentId) {
89
+ setMessageList([]);
90
+ const agent = agentList.find(item => item.id === agentId) || ({} as AgentType);
91
+ updateCurrentAgent({ ...agent, initialSendMsgParams: params });
92
+ } else {
93
+ onSendMsg(msg, messageList, modelId, params);
94
+ }
95
+ };
96
+
97
+ const updateAgentConfigMode = (agent: AgentType) => {
98
+ const toolConfig = jsonParse(agent?.toolConfig, {});
99
+ const { simpleMode, debugMode } = toolConfig;
100
+ if (isBoolean(simpleMode)) {
101
+ setIsSimpleMode(simpleMode);
102
+ } else {
103
+ setIsSimpleMode(false);
104
+ }
105
+ if (isBoolean(debugMode)) {
106
+ setIsDebugMode(debugMode);
107
+ } else {
108
+ setIsDebugMode(true);
109
+ }
110
+ };
111
+
112
+ const updateCurrentAgent = (agent?: AgentType) => {
113
+ setCurrentAgent(agent);
114
+ onCurrentAgentChange?.(agent);
115
+ localStorage.setItem('AGENT_ID', `${agent?.id}`);
116
+ if (agent) {
117
+ updateAgentConfigMode(agent);
118
+ }
119
+ if (!isCopilot) {
120
+ window.history.replaceState({}, '', `${window.location.pathname}?agentId=${agent?.id}`);
121
+ }
122
+ };
123
+
124
+ const initAgentList = async () => {
125
+ const res = await queryAgentList();
126
+ const agentListValue = (res.data || []).filter(
127
+ item => item.status === 1 && (agentIds === undefined || agentIds.includes(item.id))
128
+ );
129
+ setAgentList(agentListValue);
130
+ if (agentListValue.length > 0) {
131
+ const agentId = initialAgentId || localStorage.getItem('AGENT_ID');
132
+ if (agentId) {
133
+ const agent = agentListValue.find(item => item.id === +agentId);
134
+ updateCurrentAgent(agent || agentListValue[0]);
135
+ } else {
136
+ updateCurrentAgent(agentListValue[0]);
137
+ }
138
+ }
139
+ };
140
+
141
+ useEffect(() => {
142
+ initAgentList();
143
+ }, []);
144
+
145
+ useEffect(() => {
146
+ if (token) {
147
+ setToken(token);
148
+ }
149
+ }, [token]);
150
+
151
+ useEffect(() => {
152
+ if (chatVisible) {
153
+ inputFocus();
154
+ updateMessageContainerScroll();
155
+ }
156
+ }, [chatVisible]);
157
+
158
+ useEffect(() => {
159
+ if (!currentConversation) {
160
+ return;
161
+ }
162
+ const { initialMsgParams, isAdd } = currentConversation;
163
+ if (isAdd) {
164
+ inputFocus();
165
+ if (initialMsgParams) {
166
+ onSendMsg(initialMsgParams.msg, [], initialMsgParams.modelId, initialMsgParams);
167
+ return;
168
+ }
169
+ sendHelloRsp();
170
+ return;
171
+ }
172
+ updateHistoryMsg(1);
173
+ setPageNo(1);
174
+ }, [currentConversation]);
175
+
176
+ useEffect(() => {
177
+ if (historyInited) {
178
+ const messageContainerEle = document.getElementById('messageContainer');
179
+ messageContainerEle?.addEventListener('scroll', handleScroll);
180
+ }
181
+ return () => {
182
+ const messageContainerEle = document.getElementById('messageContainer');
183
+ messageContainerEle?.removeEventListener('scroll', handleScroll);
184
+ };
185
+ }, [historyInited]);
186
+
187
+ const sendHelloRsp = (agent?: AgentType) => {
188
+ if (noInput) {
189
+ return;
190
+ }
191
+ setMessageList([
192
+ {
193
+ id: uuid(),
194
+ type: MessageTypeEnum.AGENT_LIST,
195
+ msg: agent?.name || currentAgent?.name || agentList?.[0]?.name,
196
+ },
197
+ ]);
198
+ };
199
+
200
+ const convertHistoryMsg = (list: HistoryMsgItemType[]) => {
201
+ return list.map((item: HistoryMsgItemType) => ({
202
+ id: item.questionId,
203
+ questionId: item.questionId,
204
+ type: MessageTypeEnum.QUESTION,
205
+ msg: item.queryText,
206
+ parseInfos: item.parseInfos,
207
+ parseTimeCost: item.parseTimeCost,
208
+ msgData: { ...(item.queryResult || {}), similarQueries: item.similarQueries },
209
+ score: item.score,
210
+ agentId: currentAgent?.id,
211
+ }));
212
+ };
213
+
214
+ const updateHistoryMsg = async (page: number) => {
215
+ const res = await getHistoryMsg(page, currentConversation!.chatId, 3);
216
+ const { hasNextPage, list } = res?.data || { hasNextPage: false, list: [] };
217
+ const msgList = [...convertHistoryMsg(list), ...(page === 1 ? [] : messageList)];
218
+ setMessageList(msgList);
219
+ setHasNextPage(hasNextPage);
220
+ if (page === 1) {
221
+ if (list.length === 0) {
222
+ sendHelloRsp();
223
+ }
224
+ updateMessageContainerScroll();
225
+ setHistoryInited(true);
226
+ inputFocus();
227
+ } else {
228
+ const msgEle = document.getElementById(`${messageList[0]?.id}`);
229
+ msgEle?.scrollIntoView();
230
+ }
231
+ };
232
+
233
+ const { run: handleScroll } = useThrottleFn(
234
+ e => {
235
+ if (e.target.scrollTop === 0 && hasNextPage) {
236
+ updateHistoryMsg(pageNo + 1);
237
+ setPageNo(pageNo + 1);
238
+ }
239
+ },
240
+ {
241
+ leading: true,
242
+ trailing: true,
243
+ wait: 200,
244
+ }
245
+ );
246
+
247
+ const inputFocus = () => {
248
+ if (!isMobile) {
249
+ chatFooterRef.current?.inputFocus();
250
+ }
251
+ };
252
+
253
+ const inputBlur = () => {
254
+ chatFooterRef.current?.inputBlur();
255
+ };
256
+
257
+ const onSendMsg = async (
258
+ msg?: string,
259
+ list?: MessageItem[],
260
+ modelId?: number,
261
+ sendMsgParams?: SendMsgParamsType
262
+ ) => {
263
+ const currentMsg = msg || inputMsg;
264
+ if (currentMsg.trim() === '') {
265
+ setInputMsg('');
266
+ return;
267
+ }
268
+
269
+ const msgAgent = agentList.find(item => currentMsg.indexOf(item.name) === 1);
270
+ const certainAgent = currentMsg[0] === '/' && msgAgent;
271
+ const agentIdValue = certainAgent ? msgAgent.id : undefined;
272
+ const agent = agentList.find(item => item.id === sendMsgParams?.agentId);
273
+
274
+ if (agent || certainAgent) {
275
+ updateCurrentAgent(agent || msgAgent);
276
+ }
277
+ const msgs = [
278
+ ...(list || messageList),
279
+ {
280
+ id: uuid(),
281
+ msg: currentMsg,
282
+ msgValue: certainAgent
283
+ ? currentMsg.replace(`/${certainAgent.name}`, '').trim()
284
+ : currentMsg,
285
+ modelId: modelId === -1 ? undefined : modelId,
286
+ agentId: agent?.id || agentIdValue || currentAgent?.id,
287
+ type: MessageTypeEnum.QUESTION,
288
+ filters: sendMsgParams?.filters,
289
+ },
290
+ ];
291
+ setMessageList(msgs);
292
+ updateMessageContainerScroll();
293
+ setInputMsg('');
294
+ };
295
+
296
+ const onInputMsgChange = (value: string) => {
297
+ const inputMsgValue = value || '';
298
+ setInputMsg(inputMsgValue);
299
+ };
300
+
301
+ const saveConversationToLocal = (conversation: ConversationDetailType) => {
302
+ if (conversation) {
303
+ if (conversation.chatId !== -1) {
304
+ localStorage.setItem('CONVERSATION_ID', `${conversation.chatId}`);
305
+ }
306
+ } else {
307
+ localStorage.removeItem('CONVERSATION_ID');
308
+ }
309
+ };
310
+
311
+ const onSelectConversation = (
312
+ conversation: ConversationDetailType,
313
+ sendMsgParams?: SendMsgParamsType,
314
+ isAdd?: boolean
315
+ ) => {
316
+ setCurrentConversation({
317
+ ...conversation,
318
+ initialMsgParams: sendMsgParams,
319
+ isAdd,
320
+ });
321
+ saveConversationToLocal(conversation);
322
+ };
323
+
324
+ const onMsgDataLoaded = (
325
+ data: MsgDataType,
326
+ questionId: string | number,
327
+ question: string,
328
+ valid: boolean,
329
+ isRefresh?: boolean
330
+ ) => {
331
+ onReportMsgEvent?.(question, valid);
332
+ if (!isMobile) {
333
+ conversationRef?.current?.updateData(currentAgent?.id);
334
+ }
335
+ if (!data) {
336
+ return;
337
+ }
338
+ const msgs = cloneDeep(messageList);
339
+ const msg = msgs.find(item => item.id === questionId);
340
+ if (msg) {
341
+ msg.msgData = data;
342
+ setMessageList(msgs);
343
+ }
344
+ if (!isRefresh) {
345
+ updateMessageContainerScroll(`${questionId}`);
346
+ }
347
+ };
348
+
349
+ const onToggleHistoryVisible = () => {
350
+ setHistoryVisible(!historyVisible);
351
+ };
352
+
353
+ const onAddConversation = () => {
354
+ conversationRef.current?.onAddConversation();
355
+ inputFocus();
356
+ };
357
+
358
+ const onSelectAgent = (agent: AgentType) => {
359
+ if (agent.id === currentAgent?.id) {
360
+ return;
361
+ }
362
+ if (messageList.length === 1 && messageList[0].type === MessageTypeEnum.AGENT_LIST) {
363
+ setMessageList([]);
364
+ }
365
+ updateCurrentAgent(agent);
366
+ updateMessageContainerScroll();
367
+ };
368
+
369
+ const sendMsg = (msg: string, modelId?: number) => {
370
+ onSendMsg(msg, messageList, modelId);
371
+ if (isMobile) {
372
+ inputBlur();
373
+ }
374
+ };
375
+
376
+ const onCloseConversation = () => {
377
+ setHistoryVisible(false);
378
+ };
379
+
380
+ const chatClass = classNames(styles.chat, {
381
+ [styles.mobile]: isMobile,
382
+ [styles.historyVisible]: historyVisible,
383
+ });
384
+
385
+ return (
386
+ <ConfigProvider locale={locale}>
387
+ <div className={chatClass}>
388
+ <div className={styles.chatSection}>
389
+ {!isMobile && agentList.length > 1 && agentListVisible && (
390
+ <AgentList
391
+ agentList={agentList}
392
+ currentAgent={currentAgent}
393
+ onSelectAgent={onSelectAgent}
394
+ />
395
+ )}
396
+ <div className={styles.chatApp}>
397
+ {currentConversation && (
398
+ <div className={styles.chatBody}>
399
+ <div className={styles.chatContent}>
400
+ {currentAgent && !isMobile && !noInput && (
401
+ <div className={styles.chatHeader}>
402
+ <Row style={{ width: '100%' }}>
403
+ <Col flex="1 1 200px">
404
+ <Space>
405
+ <div className={styles.chatHeaderTitle}>{currentAgent.name}</div>
406
+ <div className={styles.chatHeaderTip}>{currentAgent.description}</div>
407
+ <Tooltip title="精简模式下,问答结果将以文本形式输出">
408
+ <Switch
409
+ key={currentAgent.id}
410
+ style={{ position: 'relative', top: -1 }}
411
+ size="small"
412
+ value={isSimpleMode}
413
+ checkedChildren="精简模式"
414
+ unCheckedChildren="精简模式"
415
+ onChange={checked => {
416
+ setIsSimpleMode(checked);
417
+ }}
418
+ />
419
+ </Tooltip>
420
+ </Space>
421
+ </Col>
422
+ <Col flex="0 1 118px"></Col>
423
+ </Row>
424
+ </div>
425
+ )}
426
+ <MessageContainer
427
+ id="messageContainer"
428
+ isSimpleMode={isSimpleMode}
429
+ isDebugMode={isDebugMode}
430
+ messageList={messageList}
431
+ chatId={currentConversation?.chatId}
432
+ historyVisible={historyVisible}
433
+ currentAgent={currentAgent}
434
+ chatVisible={chatVisible}
435
+ isDeveloper={isDeveloper}
436
+ integrateSystem={integrateSystem}
437
+ onMsgDataLoaded={onMsgDataLoaded}
438
+ onSendMsg={onSendMsg}
439
+ />
440
+ {!noInput && (
441
+ <ChatFooter
442
+ inputMsg={inputMsg}
443
+ chatId={currentConversation?.chatId}
444
+ agentList={agentList}
445
+ currentAgent={currentAgent}
446
+ onToggleHistoryVisible={onToggleHistoryVisible}
447
+ onInputMsgChange={onInputMsgChange}
448
+ onSendMsg={sendMsg}
449
+ onAddConversation={onAddConversation}
450
+ onSelectAgent={onSelectAgent}
451
+ onOpenAgents={() => {
452
+ if (isMobile) {
453
+ setMobileAgentsVisible(true);
454
+ } else {
455
+ setAgentListVisible(!agentListVisible);
456
+ }
457
+ }}
458
+ onOpenShowcase={() => {
459
+ setShowCaseVisible(!showCaseVisible);
460
+ }}
461
+ ref={chatFooterRef}
462
+ />
463
+ )}
464
+ </div>
465
+ </div>
466
+ )}
467
+ </div>
468
+ <Conversation
469
+ currentAgent={currentAgent}
470
+ currentConversation={currentConversation}
471
+ historyVisible={historyVisible}
472
+ onSelectConversation={onSelectConversation}
473
+ onCloseConversation={onCloseConversation}
474
+ ref={conversationRef}
475
+ />
476
+ {currentAgent &&
477
+ (isMobile ? (
478
+ <Drawer
479
+ title="showcase"
480
+ placement="bottom"
481
+ height="95%"
482
+ open={showCaseVisible}
483
+ className={styles.showCaseDrawer}
484
+ destroyOnClose
485
+ onClose={() => {
486
+ setShowCaseVisible(false);
487
+ }}
488
+ >
489
+ <ShowCase agentId={currentAgent.id} onSendMsg={onSendMsg} />
490
+ </Drawer>
491
+ ) : (
492
+ <Modal
493
+ title="showcase"
494
+ width="98%"
495
+ open={showCaseVisible}
496
+ centered
497
+ footer={null}
498
+ wrapClassName={styles.showCaseModal}
499
+ destroyOnClose
500
+ onCancel={() => {
501
+ setShowCaseVisible(false);
502
+ }}
503
+ >
504
+ <ShowCase
505
+ height="calc(100vh - 140px)"
506
+ agentId={currentAgent.id}
507
+ onSendMsg={onSendMsg}
508
+ />
509
+ </Modal>
510
+ ))}
511
+ </div>
512
+ <MobileAgents
513
+ open={mobileAgentsVisible}
514
+ agentList={agentList}
515
+ currentAgent={currentAgent}
516
+ onSelectAgent={onSelectAgent}
517
+ onClose={() => {
518
+ setMobileAgentsVisible(false);
519
+ }}
520
+ />
521
+ </div>
522
+ </ConfigProvider>
523
+ );
524
+ };
525
+
526
+ export default forwardRef(Chat);
@@ -0,0 +1,49 @@
1
+ import axios from '../service/axiosInstance';
2
+ import { isMobile } from '../utils/utils';
3
+ import { AgentType, ModelType } from './type';
4
+
5
+ const prefix = isMobile ? '/openapi' : '/api';
6
+
7
+ export function saveConversation(chatName: string, agentId: number) {
8
+ return axios.post<any>(`${prefix}/chat/manage/save?chatName=${chatName}&agentId=${agentId}`);
9
+ }
10
+
11
+ export function updateConversationName(chatName: string, chatId: number = 0) {
12
+ return axios.post<any>(
13
+ `${prefix}/chat/manage/updateChatName?chatName=${chatName}&chatId=${chatId}`
14
+ );
15
+ }
16
+
17
+ export function deleteConversation(chatId: number) {
18
+ return axios.post<any>(`${prefix}/chat/manage/delete?chatId=${chatId}`);
19
+ }
20
+
21
+ export function getAllConversations(agentId?: number) {
22
+ return axios.get<any>(`${prefix}/chat/manage/getAll`, { params: { agentId } });
23
+ }
24
+
25
+ export function getModelList() {
26
+ return axios.get<ModelType[]>(`${prefix}/chat/conf/modelList/dataSet`);
27
+ }
28
+
29
+ export function updateQAFeedback(questionId: number, score: number) {
30
+ return axios.post<any>(
31
+ `${prefix}/chat/manage/updateQAFeedback?id=${questionId}&score=${score}&feedback=`
32
+ );
33
+ }
34
+
35
+ export function queryMetricSuggestion(modelId: number) {
36
+ return axios.get<any>(`${prefix}/chat/recommend/metric/${modelId}`);
37
+ }
38
+
39
+ export function querySuggestion(modelId: number) {
40
+ return axios.get<any>(`${prefix}/chat/recommend/${modelId}`);
41
+ }
42
+
43
+ export function queryRecommendQuestions() {
44
+ return axios.get<any>(`${prefix}/chat/recommend/question`);
45
+ }
46
+
47
+ export function queryAgentList() {
48
+ return axios.get<AgentType[]>(`${prefix}/chat/agent/getAgentList`);
49
+ }
@@ -0,0 +1,119 @@
1
+ .chat {
2
+ height: 100%;
3
+ overflow: hidden;
4
+ background: linear-gradient(180deg, rgba(23, 74, 228, 0) 29.44%, rgba(23, 74, 228, 0.06) 100%),
5
+ linear-gradient(90deg, #f3f3f7 0%, #f3f3f7 20%, #ebf0f9 60%, #f3f3f7 80%, #f3f3f7 100%);
6
+
7
+ .chatSection {
8
+ display: flex;
9
+ width: 100%;
10
+ height: 100%;
11
+ overflow: hidden;
12
+
13
+ .chatApp {
14
+ display: flex;
15
+ flex: 1;
16
+ flex-direction: column;
17
+ height: 100%;
18
+ color: rgba(0, 0, 0, 0.87);
19
+
20
+ .chatBody {
21
+ display: flex;
22
+ flex: 1;
23
+ height: 100%;
24
+
25
+ .chatContent {
26
+ position: relative;
27
+ display: flex;
28
+ flex-direction: column;
29
+ width: 100%;
30
+
31
+ .chatHeader {
32
+ position: absolute;
33
+ top: 0;
34
+ z-index: 9;
35
+ display: flex;
36
+ align-items: baseline;
37
+ width: 100%;
38
+ padding: 14px 16px;
39
+ background: rgba(243, 243, 247, 0.85);
40
+ backdrop-filter: blur(2px);
41
+
42
+ .chatHeaderTitle {
43
+ color: var(--text-color);
44
+ font-weight: 500;
45
+ font-size: 15px;
46
+ }
47
+
48
+ .chatHeaderTip {
49
+ max-width: 600px;
50
+ margin-left: 5px;
51
+ overflow: hidden;
52
+ color: var(--text-color-third);
53
+ font-size: 12px;
54
+ white-space: nowrap;
55
+ text-overflow: ellipsis;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ &.historyVisible {
64
+ .chatSection {
65
+ .chatApp {
66
+ width: calc(100% - 707px);
67
+ }
68
+ }
69
+ }
70
+
71
+ &.mobile {
72
+ .chatSection {
73
+ .chatApp {
74
+ width: 100%;
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ .showCaseModal {
81
+ :global {
82
+ .ant-modal-content {
83
+ border-radius: 8px;
84
+
85
+ .ant-modal-header {
86
+ border-radius: 8px 8px 0 0;
87
+ }
88
+
89
+ .ant-modal-body {
90
+ padding: 20px 0 !important;
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ .showCaseDrawer {
97
+ :global {
98
+ .ant-drawer-content {
99
+ border-top-left-radius: 12px;
100
+ border-top-right-radius: 12px;
101
+ .ant-drawer-body {
102
+ padding: 4px 0 !important;
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ :global {
109
+ .ss-chat-recommend-options {
110
+ .ant-table-thead .ant-table-cell {
111
+ padding: 8px !important;
112
+ }
113
+
114
+ .ant-table-tbody .ant-table-cell {
115
+ padding: 8px !important;
116
+ border-bottom: 1px solid #f0f0f0;
117
+ }
118
+ }
119
+ }