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,410 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { format } from 'sql-formatter';
3
+ import { CopyToClipboard } from 'react-copy-to-clipboard';
4
+ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
5
+ import { solarizedlight } from 'react-syntax-highlighter/dist/esm/styles/prism';
6
+ import { Button, message } from 'antd';
7
+ import { PREFIX_CLS } from '../../common/constants';
8
+ import { CheckCircleFilled, DownloadOutlined, UpOutlined } from '@ant-design/icons';
9
+ import { SqlInfoType } from '../../common/type';
10
+ import { exportTextFile } from '../../utils/utils';
11
+
12
+ type Props = {
13
+ agentId?: number;
14
+ queryId?: number;
15
+ question: string;
16
+ llmReq?: any;
17
+ llmResp?: any;
18
+ integrateSystem?: string;
19
+ queryMode?: string;
20
+ sqlInfo: SqlInfoType;
21
+ sqlTimeCost?: number;
22
+ executeErrorMsg: string;
23
+ dataSetIds?: number[]; // 添加dataSetIds属性
24
+ };
25
+
26
+ const SqlItem: React.FC<Props> = ({
27
+ agentId,
28
+ queryId,
29
+ question,
30
+ llmReq,
31
+ llmResp,
32
+ integrateSystem,
33
+ queryMode,
34
+ sqlInfo,
35
+ sqlTimeCost,
36
+ executeErrorMsg,
37
+ dataSetIds, // 接收dataSetIds
38
+ }) => {
39
+ const [sqlType, setSqlType] = useState('');
40
+
41
+ // 监听sqlInfo变化,确保在数据集切换后更新显示
42
+ useEffect(() => {
43
+ // 当sqlInfo发生变化时,重置sqlType以确保显示最新的SQL信息
44
+ setSqlType(prevSqlType => {
45
+ // 如果当前显示的SQL类型在新的sqlInfo中不存在,则重置为默认显示
46
+ if (prevSqlType && !sqlInfo[prevSqlType]) {
47
+ // 按优先级选择要显示的SQL类型
48
+ if (sqlInfo.querySQL) return 'querySQL';
49
+ if (sqlInfo.correctedQuerySQL) return 'correctedQuerySQL';
50
+ if (sqlInfo.correctedS2SQL) return 'correctedS2SQL';
51
+ if (sqlInfo.parsedS2SQL) return 'parsedS2SQL';
52
+ return '';
53
+ }
54
+
55
+ // 如果当前没有选择任何SQL类型,但sqlInfo中有可用的SQL,则默认显示querySQL
56
+ if (!prevSqlType && sqlInfo.querySQL) {
57
+ return 'querySQL';
58
+ }
59
+
60
+ return prevSqlType;
61
+ });
62
+ }, [sqlInfo]);
63
+
64
+ // 监听数据集切换,当数据集切换时强制重置SQL显示状态
65
+ useEffect(() => {
66
+ // 当数据集切换时,重置sqlType状态以确保显示最新的SQL信息
67
+ setSqlType('');
68
+
69
+ // 延迟设置默认显示的SQL类型,确保UI能够正确更新
70
+ // 这里不需要使用currentSqlInfo,因为当新的sqlInfo到达时,第一个useEffect会处理显示逻辑
71
+ setTimeout(() => {
72
+ if (sqlInfo.querySQL) {
73
+ setSqlType('querySQL');
74
+ } else if (sqlInfo.correctedQuerySQL) {
75
+ setSqlType('correctedQuerySQL');
76
+ } else if (sqlInfo.correctedS2SQL) {
77
+ setSqlType('correctedS2SQL');
78
+ } else if (sqlInfo.parsedS2SQL) {
79
+ setSqlType('parsedS2SQL');
80
+ }
81
+ }, 100);
82
+ }, [dataSetIds]); // 只监听dataSetIds的变化
83
+
84
+ const tipPrefixCls = `${PREFIX_CLS}-item`;
85
+ const prefixCls = `${PREFIX_CLS}-sql-item`;
86
+
87
+ const handleCopy = (_: string, result: any) => {
88
+ result ? message.success('复制SQL成功', 1) : message.error('复制SQL失败', 1);
89
+ };
90
+
91
+ const onCollapse = () => {
92
+ setSqlType('');
93
+ };
94
+
95
+ if (!llmReq && !sqlInfo.parsedS2SQL && !sqlInfo.correctedS2SQL && !sqlInfo.querySQL) {
96
+ return null;
97
+ }
98
+
99
+ const { schema, terms, priorExts } = llmReq || {};
100
+
101
+ const fewShots = (Object.values(llmResp?.sqlRespMap || {})[0] as any)?.fewShots || [];
102
+
103
+ const getSchemaMapText = () => {
104
+ return `
105
+ Schema映射
106
+ ${schema?.fieldNameList?.length > 0 ? `名称:${schema.fieldNameList.join('、')}` : ''}${schema?.values?.length > 0
107
+ ? `
108
+ 取值:${schema.values
109
+ .map((item: any) => {
110
+ return `${item.fieldName}: ${item.fieldValue}`;
111
+ })
112
+ .join('、')}`
113
+ : ''
114
+ }${priorExts
115
+ ? `
116
+ 附加:${priorExts}`
117
+ : ''
118
+ }${terms?.length > 0
119
+ ? `
120
+ 术语:${terms
121
+ .map((item: any) => {
122
+ return `${item.name}${item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''}: ${item.description
123
+ }`;
124
+ })
125
+ .join('、')}`
126
+ : ''
127
+ }
128
+
129
+ `;
130
+ };
131
+
132
+ const getFewShotText = () => {
133
+ return `
134
+ Few-shot示例${fewShots
135
+ .map((item: any, index: number) => {
136
+ return `
137
+
138
+ 示例${index + 1}:
139
+ 问题:${item.question}
140
+ SQL:
141
+ ${format(item.sql)}
142
+ `;
143
+ })
144
+ .join('')}
145
+ `;
146
+ };
147
+
148
+ const getParsedS2SQLText = () => {
149
+ return `
150
+ ${queryMode === 'LLM_S2SQL' || queryMode === 'PLAIN_TEXT' ? 'LLM' : 'Rule'}解析S2SQL
151
+
152
+ ${format(sqlInfo.parsedS2SQL)}
153
+ `;
154
+ };
155
+
156
+ const getCorrectedS2SQLText = () => {
157
+ return `
158
+ 修正S2SQL
159
+
160
+ ${format(sqlInfo.correctedS2SQL)}
161
+ `;
162
+ };
163
+
164
+ const getCorrectedQuerySQLText = () => {
165
+ return `
166
+ 物理SQL修正
167
+
168
+ ${format(sqlInfo.correctedQuerySQL || '')}
169
+ `;
170
+ };
171
+
172
+ const getQuerySQLText = () => {
173
+ return `
174
+ 最终执行SQL
175
+
176
+ ${format(sqlInfo.querySQL)}
177
+ `;
178
+ };
179
+
180
+ const getErrorMsgText = () => {
181
+ return `
182
+ 异常日志
183
+
184
+ ${executeErrorMsg}
185
+ `;
186
+ };
187
+
188
+ const onExportLog = () => {
189
+ let text = '';
190
+ if (question) {
191
+ text += `
192
+ 问题:${question}
193
+ `;
194
+ }
195
+ if (llmReq) {
196
+ text += getSchemaMapText();
197
+ }
198
+ if (fewShots.length > 0) {
199
+ text += getFewShotText();
200
+ }
201
+ if (sqlInfo.parsedS2SQL) {
202
+ text += getParsedS2SQLText();
203
+ }
204
+ if (sqlInfo.correctedS2SQL) {
205
+ text += getCorrectedS2SQLText();
206
+ }
207
+ if (sqlInfo.correctedQuerySQL) {
208
+ text += getCorrectedQuerySQLText();
209
+ }
210
+ if (sqlInfo.querySQL) {
211
+ text += getQuerySQLText();
212
+ }
213
+ if (!!executeErrorMsg) {
214
+ text += getErrorMsgText();
215
+ }
216
+ exportTextFile(text, `supersonic-debug-${agentId}-${queryId}.log`);
217
+ };
218
+
219
+ return (
220
+ <div className={`${tipPrefixCls}-parse-tip`}>
221
+ <div className={`${tipPrefixCls}-title-bar`}>
222
+ <CheckCircleFilled className={`${tipPrefixCls}-step-icon`} />
223
+ <div className={`${tipPrefixCls}-step-title`}>
224
+ SQL生成
225
+ {!!sqlTimeCost && (
226
+ <span className={`${tipPrefixCls}-title-tip`}>(耗时: {sqlTimeCost}ms)</span>
227
+ )}
228
+
229
+ {sqlType && (
230
+ <span className={`${prefixCls}-toggle-expand-btn`} onClick={onCollapse}>
231
+ <UpOutlined />
232
+ </span>
233
+ )}
234
+ </div>
235
+ <div className={`${tipPrefixCls}-content-options`}>
236
+ {llmReq && (
237
+ <div
238
+ className={`${tipPrefixCls}-content-option ${sqlType === 'schemaMap' ? `${tipPrefixCls}-content-option-active` : ''
239
+ }`}
240
+ onClick={() => {
241
+ setSqlType(sqlType === 'schemaMap' ? '' : 'schemaMap');
242
+ }}
243
+ >
244
+ Schema映射
245
+ </div>
246
+ )}
247
+ {fewShots.length > 0 && (
248
+ <div
249
+ className={`${tipPrefixCls}-content-option ${sqlType === 'fewShots' ? `${tipPrefixCls}-content-option-active` : ''
250
+ }`}
251
+ onClick={() => {
252
+ setSqlType(sqlType === 'fewShots' ? '' : 'fewShots');
253
+ }}
254
+ >
255
+ Few-shot示例
256
+ </div>
257
+ )}
258
+ {sqlInfo.parsedS2SQL && (
259
+ <div
260
+ className={`${tipPrefixCls}-content-option ${sqlType === 'parsedS2SQL' ? `${tipPrefixCls}-content-option-active` : ''
261
+ }`}
262
+ onClick={() => {
263
+ setSqlType(sqlType === 'parsedS2SQL' ? '' : 'parsedS2SQL');
264
+ }}
265
+ >
266
+ {queryMode === 'LLM_S2SQL' || queryMode === 'PLAIN_TEXT' ? 'LLM' : 'Rule'}解析S2SQL
267
+ </div>
268
+ )}
269
+ {sqlInfo.correctedS2SQL && (
270
+ <div
271
+ className={`${tipPrefixCls}-content-option ${sqlType === 'correctedS2SQL' ? `${tipPrefixCls}-content-option-active` : ''
272
+ }`}
273
+ onClick={() => {
274
+ setSqlType(sqlType === 'correctedS2SQL' ? '' : 'correctedS2SQL');
275
+ }}
276
+ >
277
+ 修正S2SQL
278
+ </div>
279
+ )}
280
+ {sqlInfo.correctedQuerySQL && (
281
+ <div
282
+ className={`${tipPrefixCls}-content-option ${sqlType === 'correctedQuerySQL' ? `${tipPrefixCls}-content-option-active` : ''
283
+ }`}
284
+ onClick={() => {
285
+ setSqlType(sqlType === 'correctedQuerySQL' ? '' : 'correctedQuerySQL');
286
+ }}
287
+ >
288
+ 物理SQL修正
289
+ </div>
290
+ )}
291
+ {sqlInfo.querySQL && (
292
+ <div
293
+ className={`${tipPrefixCls}-content-option ${sqlType === 'querySQL' ? `${tipPrefixCls}-content-option-active` : ''
294
+ }`}
295
+ onClick={() => {
296
+ setSqlType(sqlType === 'querySQL' ? '' : 'querySQL');
297
+ }}
298
+ >
299
+ {sqlInfo.correctedQuerySQL ? '最终执行SQL' : '最终执行SQL'}
300
+ </div>
301
+ )}
302
+ <Button className={`${prefixCls}-export-log`} size="small" onClick={onExportLog}>
303
+ <DownloadOutlined />
304
+ 导出日志
305
+ </Button>
306
+ </div>
307
+ </div>
308
+ <div
309
+ className={`${prefixCls} ${!window.location.pathname.includes('/chat') &&
310
+ integrateSystem &&
311
+ integrateSystem !== 'wiki'
312
+ ? `${prefixCls}-copilot`
313
+ : ''
314
+ }`}
315
+ >
316
+ {sqlType === 'schemaMap' && (
317
+ <div className={`${prefixCls}-code`}>
318
+ {schema?.fieldNameList?.length > 0 && (
319
+ <div className={`${prefixCls}-schema-row`}>
320
+ <div className={`${prefixCls}-schema-title`}>名称:</div>
321
+ <div className={`${prefixCls}-schema-content`}>
322
+ {schema.fieldNameList.join('、')}
323
+ </div>
324
+ </div>
325
+ )}
326
+ {schema?.values?.length > 0 && (
327
+ <div className={`${prefixCls}-schema-row`}>
328
+ <div className={`${prefixCls}-schema-title`}>取值:</div>
329
+ <div className={`${prefixCls}-schema-content`}>
330
+ {schema.values
331
+ .map((item: any) => {
332
+ return `${item.fieldName}: ${item.fieldValue}`;
333
+ })
334
+ .join('、')}
335
+ </div>
336
+ </div>
337
+ )}
338
+ {priorExts && (
339
+ <div className={`${prefixCls}-schema-row`}>
340
+ <div className={`${prefixCls}-schema-title`}>附加:</div>
341
+ <div className={`${prefixCls}-schema-content`}>{priorExts}</div>
342
+ </div>
343
+ )}
344
+ {terms?.length > 0 && (
345
+ <div className={`${prefixCls}-schema-row`}>
346
+ <div className={`${prefixCls}-schema-title`}>术语:</div>
347
+ <div className={`${prefixCls}-schema-content`}>
348
+ {terms
349
+ .map((item: any) => {
350
+ return `${item.name}${item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''
351
+ }: ${item.description}`;
352
+ })
353
+ .join('、')}
354
+ </div>
355
+ </div>
356
+ )}
357
+ </div>
358
+ )}
359
+ {sqlType === 'fewShots' && (
360
+ <div className={`${prefixCls}-code`}>
361
+ {fewShots.map((item: any, index: number) => {
362
+ return (
363
+ <div key={index} className={`${prefixCls}-few-shot-item`}>
364
+ <div className={`${prefixCls}-few-shot-title`}>示例{index + 1}:</div>
365
+ <div className={`${prefixCls}-few-shot-content`}>
366
+ <div className={`${prefixCls}-few-shot-content-item`}>
367
+ <div className={`${prefixCls}-few-shot-content-title`}>问题:</div>
368
+ <div className={`${prefixCls}-few-shot-content-text`}>{item.question}</div>
369
+ </div>
370
+ <div className={`${prefixCls}-few-shot-content-item`}>
371
+ <div className={`${prefixCls}-few-shot-content-title`}>SQL:</div>
372
+ <div className={`${prefixCls}-few-shot-content-text`}>
373
+ <SyntaxHighlighter
374
+ className={`${prefixCls}-few-shot-code`}
375
+ language="sql"
376
+ style={solarizedlight}
377
+ >
378
+ {item.sql}
379
+ </SyntaxHighlighter>
380
+ </div>
381
+ </div>
382
+ </div>
383
+ </div>
384
+ );
385
+ })}
386
+ </div>
387
+ )}
388
+ {sqlType && sqlInfo[sqlType] && (
389
+ <>
390
+ <SyntaxHighlighter
391
+ className={`${prefixCls}-code`}
392
+ language="sql"
393
+ style={solarizedlight}
394
+ >
395
+ {format(sqlInfo[sqlType])}
396
+ </SyntaxHighlighter>
397
+ <CopyToClipboard
398
+ text={format(sqlInfo[sqlType])}
399
+ onCopy={(text, result) => handleCopy(text, result)}
400
+ >
401
+ <button className={`${prefixCls}-copy-btn`}>复制代码</button>
402
+ </CopyToClipboard>
403
+ </>
404
+ )}
405
+ </div>
406
+ </div>
407
+ );
408
+ };
409
+
410
+ export default SqlItem;
@@ -0,0 +1,52 @@
1
+ import { useState } from 'react';
2
+ import { ChatContextType } from '../../common/type';
3
+ import { Popover } from 'antd';
4
+ import { DownOutlined } from '@ant-design/icons';
5
+ import RecommendOptions from '../RecommendOptions';
6
+ import { PREFIX_CLS } from '../../common/constants';
7
+
8
+ type Props = {
9
+ entityName: string;
10
+ chatContext: ChatContextType;
11
+ onSwitchEntity: (entityId: string) => void;
12
+ };
13
+
14
+ const SwicthEntity: React.FC<Props> = ({ entityName, chatContext, onSwitchEntity }) => {
15
+ const [recommendOptionsOpen, setRecommendOptionsOpen] = useState(false);
16
+ const { modelId, modelName, dimensionFilters } = chatContext || {};
17
+
18
+ const prefixCls = `${PREFIX_CLS}-item`;
19
+
20
+ const switchEntity = (option: string) => {
21
+ setRecommendOptionsOpen(false);
22
+ onSwitchEntity(option);
23
+ };
24
+
25
+ const entityId = dimensionFilters?.find(
26
+ filter => filter?.bizName === 'zyqk_song_id' || filter?.bizName === 'singer_id'
27
+ )?.value;
28
+
29
+ return (
30
+ <Popover
31
+ content={
32
+ <RecommendOptions
33
+ entityId={entityId!}
34
+ modelId={modelId}
35
+ modelName={modelName}
36
+ onSelect={switchEntity}
37
+ />
38
+ }
39
+ placement="bottomLeft"
40
+ trigger="click"
41
+ open={recommendOptionsOpen}
42
+ onOpenChange={open => setRecommendOptionsOpen(open)}
43
+ >
44
+ <div className={`${prefixCls}-tip-item-value ${prefixCls}-switch-entity`}>
45
+ {entityName}
46
+ <DownOutlined className={`${prefixCls}-down-icon`} />
47
+ </div>
48
+ </Popover>
49
+ );
50
+ };
51
+
52
+ export default SwicthEntity;
@@ -0,0 +1,17 @@
1
+ import Message from '../ChatMsg/Message';
2
+ import { PREFIX_CLS } from '../../common/constants';
3
+
4
+ type Props = {
5
+ data: any;
6
+ };
7
+
8
+ const Text: React.FC<Props> = ({ data }) => {
9
+ const prefixCls = `${PREFIX_CLS}-item`;
10
+ return (
11
+ <Message position="left" bubbleClassName={`${prefixCls}-text-bubble`}>
12
+ <div className={`${prefixCls}-text`}>{data}</div>
13
+ </Message>
14
+ );
15
+ };
16
+
17
+ export default Text;
@@ -0,0 +1,19 @@
1
+ import { CHAT_BLUE, PREFIX_CLS } from '../../common/constants';
2
+ import { Spin } from 'antd';
3
+ import BeatLoader from 'react-spinners/BeatLoader';
4
+ import Message from '../ChatMsg/Message';
5
+
6
+ const Typing = () => {
7
+ const prefixCls = `${PREFIX_CLS}-item`;
8
+ return (
9
+ <Message position="left" bubbleClassName={`${prefixCls}-typing-bubble`}>
10
+ <Spin
11
+ spinning={true}
12
+ indicator={<BeatLoader color={CHAT_BLUE} size={10} />}
13
+ className={`${prefixCls}-typing`}
14
+ />
15
+ </Message>
16
+ );
17
+ };
18
+
19
+ export default Typing;