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,208 @@
1
+ import { CHART_BLUE_COLOR, CHART_SECONDARY_COLOR, PREFIX_CLS } from '../../../common/constants';
2
+ import { MsgDataType } from '../../../common/type';
3
+ import {
4
+ formatByDataFormatType,
5
+ getChartLightenColor,
6
+ getFormattedValue,
7
+ } from '../../../utils/utils';
8
+ import type { ECharts } from 'echarts';
9
+ import * as echarts from 'echarts';
10
+ import {
11
+ forwardRef,
12
+ ForwardRefRenderFunction,
13
+ useContext,
14
+ useEffect,
15
+ useImperativeHandle,
16
+ useRef,
17
+ } from 'react';
18
+ import NoPermissionChart from '../NoPermissionChart';
19
+ import { ColumnType } from '../../../common/type';
20
+ import { Spin } from 'antd';
21
+ import { ChartItemContext } from '../../ChatItem';
22
+ import { useExportByEcharts } from '../../../hooks';
23
+
24
+ type Props = {
25
+ data: MsgDataType;
26
+ question?: string;
27
+ triggerResize?: boolean;
28
+ loading: boolean;
29
+ metricField: ColumnType;
30
+ onApplyAuth?: (model: string) => void;
31
+ };
32
+
33
+ const BarChart: React.FC<Props> = ({
34
+ data,
35
+ question="",
36
+ triggerResize,
37
+ loading,
38
+ metricField,
39
+ onApplyAuth,
40
+ }) => {
41
+ const chartRef = useRef<any>();
42
+ const instanceRef = useRef<ECharts>();
43
+
44
+ const { queryColumns, queryResults, entityInfo } = data;
45
+
46
+ const categoryColumnName =
47
+ queryColumns?.find(column => column.showType === 'CATEGORY')?.bizName || '';
48
+ const metricColumn = queryColumns?.find(column => column.showType === 'NUMBER');
49
+ const metricColumnName = metricColumn?.bizName || '';
50
+
51
+ const renderChart = () => {
52
+ let instanceObj: any;
53
+ if (!instanceRef.current) {
54
+ instanceObj = echarts.init(chartRef.current);
55
+ instanceRef.current = instanceObj;
56
+ } else {
57
+ instanceObj = instanceRef.current;
58
+ }
59
+ const data = (queryResults || []);
60
+ const xData = data.map(item =>
61
+ item[categoryColumnName] !== undefined ? item[categoryColumnName] : '未知'
62
+ );
63
+ instanceObj.setOption({
64
+ xAxis: {
65
+ type: 'category',
66
+ axisTick: {
67
+ show: false,
68
+ },
69
+ axisLine: {
70
+ lineStyle: {
71
+ color: CHART_SECONDARY_COLOR,
72
+ },
73
+ },
74
+ axisLabel: {
75
+ width: 200,
76
+ overflow: 'truncate',
77
+ showMaxLabel: true,
78
+ hideOverlap: false,
79
+ interval: 0,
80
+ color: '#333',
81
+ rotate: 30,
82
+ },
83
+ data: xData,
84
+ },
85
+ yAxis: {
86
+ type: 'value',
87
+ splitLine: {
88
+ lineStyle: {
89
+ opacity: 0.3,
90
+ },
91
+ },
92
+ axisLabel: {
93
+ formatter: function (value: any) {
94
+ return value === 0
95
+ ? 0
96
+ : metricField.dataFormatType === 'percent'
97
+ ? formatByDataFormatType(value, metricField.dataFormatType, metricField.dataFormat)
98
+ : getFormattedValue(value);
99
+ },
100
+ },
101
+ },
102
+ tooltip: {
103
+ trigger: 'axis',
104
+ formatter: function (params: any[]) {
105
+ const param = params[0];
106
+ const valueLabels = params
107
+ .map(
108
+ (item: any) =>
109
+ `<div style="margin-top: 3px;">${
110
+ item.marker
111
+ } <span style="display: inline-block; width: 70px; margin-right: 12px;">${
112
+ item.seriesName
113
+ }</span><span style="display: inline-block; width: 90px; text-align: right; font-weight: 500;">${
114
+ item.value === ''
115
+ ? '-'
116
+ : metricField.dataFormatType === 'percent' ||
117
+ metricField.dataFormatType === 'decimal'
118
+ ? formatByDataFormatType(item.value, metricField.dataFormatType, metricField.dataFormat)
119
+ : getFormattedValue(item.value)
120
+ }</span></div>`
121
+ )
122
+ .join('');
123
+ return `${param.name}<br />${valueLabels}`;
124
+ },
125
+ },
126
+ grid: {
127
+ left: '2%',
128
+ right: '1%',
129
+ bottom: '3%',
130
+ top: 20,
131
+ containLabel: true,
132
+ },
133
+ series: {
134
+ type: 'bar',
135
+ name: metricColumn?.name,
136
+ barWidth: 20,
137
+ itemStyle: {
138
+ borderRadius: [10, 10, 0, 0],
139
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
140
+ { offset: 0, color: CHART_BLUE_COLOR },
141
+ { offset: 1, color: getChartLightenColor(CHART_BLUE_COLOR) },
142
+ ]),
143
+ },
144
+ label: {
145
+ show: true,
146
+ position: 'top',
147
+ formatter: function ({ value }: any) {
148
+ return value === 0
149
+ ? 0
150
+ : metricField.dataFormatType === 'percent'
151
+ ? formatByDataFormatType(value, metricField.dataFormatType, metricField.dataFormat)
152
+ : getFormattedValue(value);
153
+ },
154
+ },
155
+ data: data.map(item => {
156
+ return item[metricColumn?.bizName || ''];
157
+ }),
158
+ },
159
+ });
160
+ instanceObj.resize();
161
+ };
162
+
163
+ useEffect(() => {
164
+ if (queryResults && queryResults.length > 0 && metricColumn?.authorized) {
165
+ renderChart();
166
+ }
167
+ }, [queryResults]);
168
+
169
+ useEffect(() => {
170
+ if (triggerResize && instanceRef.current) {
171
+ instanceRef.current.resize();
172
+ }
173
+ }, [triggerResize]);
174
+
175
+ if (metricColumn && !metricColumn?.authorized) {
176
+ return (
177
+ <NoPermissionChart
178
+ model={entityInfo?.dataSetInfo.name || ''}
179
+ chartType="barChart"
180
+ onApplyAuth={onApplyAuth}
181
+ />
182
+ );
183
+ }
184
+
185
+ const prefixCls = `${PREFIX_CLS}-bar`;
186
+
187
+ const { downloadChartAsImage } = useExportByEcharts({
188
+ instanceRef,
189
+ question,
190
+ });
191
+
192
+ const { register } = useContext(ChartItemContext);
193
+
194
+ register('downloadChartAsImage', downloadChartAsImage);
195
+
196
+ return (
197
+ <div>
198
+ <div className={`${prefixCls}-top-bar`}>
199
+ <div className={`${prefixCls}-indicator-name`}>{question}</div>
200
+ </div>
201
+ <Spin spinning={loading}>
202
+ <div className={`${prefixCls}-chart`} ref={chartRef} />
203
+ </Spin>
204
+ </div>
205
+ );
206
+ };
207
+
208
+ export default BarChart;
@@ -0,0 +1,60 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @bar-cls: ~'@{supersonic-chat-prefix}-bar';
4
+
5
+ .@{bar-cls} {
6
+
7
+ &-chart {
8
+ height: 260px;
9
+ margin-top: 16px;
10
+ }
11
+
12
+ &-top-bar {
13
+ display: flex;
14
+ align-items: baseline;
15
+ flex-wrap: wrap;
16
+ column-gap: 8px;
17
+ row-gap: 12px;
18
+ }
19
+
20
+ &-filter-section-wrapper {
21
+ display: flex;
22
+ align-items: center;
23
+ color: var(--text-color-third);
24
+ }
25
+
26
+ &-filter-section {
27
+ display: flex;
28
+ align-items: center;
29
+ font-size: 13px;
30
+ column-gap: 12px;
31
+ color: var(--text-color-third);
32
+ }
33
+
34
+ &-filter-item {
35
+ display: flex;
36
+ align-items: center;
37
+ }
38
+
39
+ &-filter-item-label {
40
+ color: var(--text-color-third);
41
+ }
42
+
43
+ &-filter-item-value {
44
+ color: var(--text-color);
45
+ font-weight: 500;
46
+ }
47
+
48
+ &-indicator-name {
49
+ font-size: 14px;
50
+ color: var(--text-color);
51
+ font-weight: 500;
52
+ margin-top: 2px;
53
+ }
54
+
55
+ &-date-range {
56
+ margin-top: 12px;
57
+ font-size: 13px;
58
+ color: var(--text-color-third);
59
+ }
60
+ }
@@ -0,0 +1,46 @@
1
+ import classNames from 'classnames';
2
+ import { CLS_PREFIX, DATE_TYPES } from '../../../common/constants';
3
+ import { isMobile } from '../../../utils/utils';
4
+ import { ChatContextType } from '../../../common/type';
5
+
6
+ type Props = {
7
+ chatContext: ChatContextType;
8
+ currentDateOption?: number;
9
+ onSelectDateOption: (value: number) => void;
10
+ };
11
+
12
+ const DateOptions: React.FC<Props> = ({ chatContext, currentDateOption, onSelectDateOption }) => {
13
+ const prefixCls = `${CLS_PREFIX}-date-options`;
14
+
15
+ const dateOptions = DATE_TYPES[chatContext?.dateInfo?.period] || DATE_TYPES.DAY;
16
+
17
+ return (
18
+ <div className={prefixCls}>
19
+ {dateOptions.map((dateOption: { label: string; value: number }, index: number) => {
20
+ const dateOptionClass = classNames(`${prefixCls}-item`, {
21
+ [`${prefixCls}-date-active`]: dateOption.value === currentDateOption,
22
+ [`${prefixCls}-date-mobile`]: isMobile,
23
+ });
24
+ return (
25
+ <>
26
+ <div
27
+ key={dateOption.value}
28
+ className={dateOptionClass}
29
+ onClick={() => {
30
+ onSelectDateOption(dateOption.value);
31
+ }}
32
+ >
33
+ {dateOption.label}
34
+ {dateOption.value === currentDateOption && (
35
+ <div className={`${prefixCls}-active-identifier`} />
36
+ )}
37
+ </div>
38
+ {index !== dateOptions.length - 1 && <div className={`${prefixCls}-item-divider`} />}
39
+ </>
40
+ );
41
+ })}
42
+ </div>
43
+ );
44
+ };
45
+
46
+ export default DateOptions;
@@ -0,0 +1,43 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @date-options-prefix-cls: ~'@{supersonic-chat-prefix}-date-options';
4
+
5
+ .@{date-options-prefix-cls} {
6
+ display: flex;
7
+ align-items: center;
8
+ column-gap: 20px;
9
+ font-size: 14px;
10
+
11
+ &-item {
12
+ position: relative;
13
+ color: var(--text-color-secondary);
14
+ cursor: pointer;
15
+
16
+ &:hover {
17
+ color: var(--chat-blue);
18
+ }
19
+ }
20
+
21
+ &-date-active {
22
+ color: var(--chat-blue);
23
+ }
24
+
25
+ &-date-mobile {
26
+ font-size: 12px;
27
+ }
28
+
29
+ &-active-identifier {
30
+ position: absolute;
31
+ bottom: -6px;
32
+ width: 100%;
33
+ height: 4px;
34
+ background-color: var(--chat-blue);
35
+ border-radius: 4px 4px 0 0;
36
+ }
37
+
38
+ &-item-divider {
39
+ width: 1px;
40
+ height: 16px;
41
+ background-color: var(--text-color-fifth);
42
+ }
43
+ }
@@ -0,0 +1,42 @@
1
+ import { PREFIX_CLS } from '../../../common/constants';
2
+ import { ChatContextType, EntityInfoType } from '../../../common/type';
3
+
4
+ type Props = {
5
+ chatContext?: ChatContextType;
6
+ entityInfo?: EntityInfoType;
7
+ };
8
+
9
+ const FilterSection: React.FC<Props> = ({ chatContext, entityInfo }) => {
10
+ const prefixCls = `${PREFIX_CLS}-filter-section`;
11
+
12
+ const entityInfoList =
13
+ entityInfo?.dimensions?.filter(dimension => !dimension.bizName.includes('photo')) || [];
14
+
15
+ const { dimensionFilters } = chatContext || {};
16
+
17
+ const hasFilterSection = dimensionFilters && dimensionFilters.length > 0;
18
+
19
+ return hasFilterSection ? (
20
+ <div className={prefixCls}>
21
+ <div className={`${prefixCls}-field-label`}>筛选条件:</div>
22
+ <div className={`${prefixCls}-filter-values`}>
23
+ {(entityInfoList.length > 0 ? entityInfoList : dimensionFilters).map(filterItem => {
24
+ const filterValue =
25
+ typeof filterItem.value === 'string' ? [filterItem.value] : filterItem.value || [];
26
+ return (
27
+ <div
28
+ className={`${prefixCls}-filter-item`}
29
+ key={filterItem.name}
30
+ title={filterValue.join('、')}
31
+ >
32
+ <span className={`${prefixCls}-field-name`}>{filterItem.name}:</span>
33
+ <span className={`${prefixCls}-filter-value`}>{filterValue.join('、')}</span>
34
+ </div>
35
+ );
36
+ })}
37
+ </div>
38
+ </div>
39
+ ) : null;
40
+ };
41
+
42
+ export default FilterSection;
@@ -0,0 +1,37 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @filter-section-prefix-cls: ~'@{supersonic-chat-prefix}-filter-section';
4
+
5
+ .@{filter-section-prefix-cls} {
6
+ display: flex;
7
+ align-items: center;
8
+ flex-wrap: wrap;
9
+ row-gap: 12px;
10
+ color: var(--text-color-secondary);
11
+ font-weight: normal;
12
+ font-size: 13px;
13
+
14
+ &-field-label {
15
+ color: var(--text-color-fourth);
16
+ }
17
+
18
+ &-filter-values {
19
+ display: flex;
20
+ align-items: center;
21
+ flex-wrap: wrap;
22
+ column-gap: 12px;
23
+ }
24
+
25
+ &-filter-item {
26
+ color: var(--text-color-third);
27
+ max-width: 200px;
28
+ text-overflow: ellipsis;
29
+ white-space: nowrap;
30
+ overflow: hidden;
31
+ }
32
+
33
+ &-filter-value {
34
+ color: var(--text-color);
35
+ font-weight: 500;
36
+ }
37
+ }
@@ -0,0 +1,26 @@
1
+ import { CLS_PREFIX } from '../../../common/constants';
2
+ import rehypeHighlight from 'rehype-highlight';
3
+ import remarkGfm from 'remark-gfm';
4
+ import Markdown from 'react-markdown';
5
+ import 'github-markdown-css/github-markdown.css';
6
+ import 'highlight.js/styles/github.css';
7
+
8
+ type Props = {
9
+ markdown: string;
10
+ loading?: boolean;
11
+ onApplyAuth?: (model: string) => void;
12
+ };
13
+
14
+ const MarkDown: React.FC<Props> = ({ markdown, loading, onApplyAuth }) => {
15
+ const prefixCls = `${CLS_PREFIX}-markdown`;
16
+
17
+ return (
18
+ <div className={`${prefixCls} markdown-body`} style={{ fontSize: 14 }}>
19
+ <Markdown rehypePlugins={[rehypeHighlight]} remarkPlugins={[remarkGfm]}>
20
+ {markdown}
21
+ </Markdown>
22
+ </div>
23
+ );
24
+ };
25
+
26
+ export default MarkDown;
@@ -0,0 +1,9 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @markdown-prefix-cls: ~'@{supersonic-chat-prefix}-markdown';
4
+
5
+ .@{markdown-prefix-cls} {
6
+ margin-top: 6px;
7
+
8
+
9
+ }
@@ -0,0 +1,105 @@
1
+ import { EntityInfoType, ChatContextType } from '../../../common/type';
2
+ import { PREFIX_CLS } from '../../../common/constants';
3
+
4
+ type Props = {
5
+ position: 'left' | 'right';
6
+ width?: number | string;
7
+ maxWidth?: number | string;
8
+ height?: number | string;
9
+ title?: string;
10
+ followQuestions?: string[];
11
+ bubbleClassName?: string;
12
+ chatContext?: ChatContextType;
13
+ entityInfo?: EntityInfoType;
14
+ children?: React.ReactNode;
15
+ isMobileMode?: boolean;
16
+ queryMode?: string;
17
+ };
18
+
19
+ const Message: React.FC<Props> = ({
20
+ width,
21
+ maxWidth,
22
+ height,
23
+ children,
24
+ bubbleClassName,
25
+ entityInfo,
26
+ queryMode,
27
+ chatContext,
28
+ }) => {
29
+ const prefixCls = `${PREFIX_CLS}-message`;
30
+
31
+ const { modelName, dateInfo, dimensionFilters } = chatContext || {};
32
+ const { startDate, endDate } = dateInfo || {};
33
+
34
+ const entityInfoList =
35
+ entityInfo?.dimensions?.filter(dimension => !dimension.bizName.includes('photo')) || [];
36
+
37
+ return (
38
+ <div className={prefixCls}>
39
+ <div className={`${prefixCls}-content`}>
40
+ <div className={`${prefixCls}-body`}>
41
+ <div
42
+ className={`${prefixCls}-bubble${bubbleClassName ? ` ${bubbleClassName}` : ''}`}
43
+ style={{ width, height, maxWidth }}
44
+ onClick={e => {
45
+ e.stopPropagation();
46
+ }}
47
+ >
48
+ {(queryMode === 'METRIC_ID' || queryMode === 'TAG_DETAIL') &&
49
+ entityInfoList.length > 0 && (
50
+ <div className={`${prefixCls}-info-bar`}>
51
+ <div className={`${prefixCls}-main-entity-info`}>
52
+ {entityInfoList.slice(0, 4).map(dimension => {
53
+ return (
54
+ <div className={`${prefixCls}-info-item`} key={dimension.bizName}>
55
+ <div className={`${prefixCls}-info-name`}>{dimension.name}:</div>
56
+ {dimension.bizName.includes('photo') ? (
57
+ <img width={40} height={40} src={dimension.value} alt="" />
58
+ ) : (
59
+ <div className={`${prefixCls}-info-value`}>{dimension.value}</div>
60
+ )}
61
+ </div>
62
+ );
63
+ })}
64
+ </div>
65
+ </div>
66
+ )}
67
+ {queryMode === 'TAG_LIST_FILTER' && (
68
+ <div className={`${prefixCls}-info-bar`}>
69
+ <div className={`${prefixCls}-main-entity-info`}>
70
+ <div className={`${prefixCls}-info-item`}>
71
+ <div className={`${prefixCls}-info-name`}>数据模型:</div>
72
+ <div className={`${prefixCls}-info-value`}>{modelName}</div>
73
+ </div>
74
+ <div className={`${prefixCls}-info-item`}>
75
+ <div className={`${prefixCls}-info-name`}>时间:</div>
76
+ <div className={`${prefixCls}-info-value`}>
77
+ {startDate === endDate ? startDate : `${startDate} ~ ${endDate}`}
78
+ </div>
79
+ </div>
80
+ {dimensionFilters && dimensionFilters?.length > 0 && (
81
+ <div className={`${prefixCls}-info-item`}>
82
+ <div className={`${prefixCls}-info-name`}>筛选条件:</div>
83
+ {dimensionFilters.map((filter, index) => (
84
+ <div className={`${prefixCls}-info-value`}>
85
+ <span>{filter.name}:</span>
86
+ <span>
87
+ {Array.isArray(filter.value) ? filter.value.join('、') : filter.value}
88
+ </span>
89
+ {index !== dimensionFilters.length - 1 && <span>、</span>}
90
+ </div>
91
+ ))}
92
+ </div>
93
+ )}
94
+ </div>
95
+ </div>
96
+ )}
97
+ <div className={`${prefixCls}-children`}>{children}</div>
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ );
103
+ };
104
+
105
+ export default Message;
@@ -0,0 +1,119 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @msg-prefix-cls: ~'@{supersonic-chat-prefix}-message';
4
+
5
+ .@{msg-prefix-cls} {
6
+ &-title-bar {
7
+ display: flex;
8
+ align-items: baseline;
9
+ column-gap: 10px;
10
+ margin-bottom: 6px;
11
+ }
12
+
13
+ &-model-name {
14
+ color: var(--text-color);
15
+ margin-left: 4px;
16
+ font-weight: 500;
17
+ font-size: 15px;
18
+ }
19
+
20
+ &-top-bar {
21
+ position: relative;
22
+ max-width: 80%;
23
+ color: var(--text-color-third);
24
+ font-size: 13px;
25
+ white-space: nowrap;
26
+ text-overflow: ellipsis;
27
+ overflow: hidden;
28
+ }
29
+
30
+ &-content {
31
+ display: flex;
32
+ align-items: flex-start;
33
+ }
34
+
35
+ &-body {
36
+ width: 100%;
37
+ }
38
+
39
+ &-bubble {
40
+ position: relative;
41
+ box-sizing: border-box;
42
+ min-width: 1px;
43
+ max-width: 100%;
44
+ padding: 8px 16px 10px;
45
+ background: rgba(255, 255, 255, 0.8);
46
+ border: 1px solid transparent;
47
+ border-radius: 12px;
48
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.14), 0 0 2px rgba(0, 0, 0, 0.12);
49
+ }
50
+
51
+ &-filter-section {
52
+ display: flex;
53
+ align-items: center;
54
+ color: var(--text-color-secondary);
55
+ font-weight: normal;
56
+ font-size: 13px;
57
+ }
58
+
59
+ &-filter-values {
60
+ display: flex;
61
+ align-items: center;
62
+ column-gap: 6px;
63
+ }
64
+
65
+ &-filter-item {
66
+ padding: 2px 12px;
67
+ color: var(--text-color-secondary);
68
+ background-color: #edf2f2;
69
+ border-radius: 13px;
70
+ max-width: 200px;
71
+ text-overflow: ellipsis;
72
+ white-space: nowrap;
73
+ overflow: hidden;
74
+ }
75
+
76
+ &-tip {
77
+ margin-left: 6px;
78
+ color: var(--text-color-third);
79
+ }
80
+
81
+ &-info-bar {
82
+ display: flex;
83
+ align-items: center;
84
+ row-gap: 12px;
85
+ flex-wrap: wrap;
86
+ margin-top: 2px;
87
+ margin-bottom: 12px;
88
+ column-gap: 20px;
89
+ color: var(--text-color-secondary);
90
+ background: rgba(133, 156, 241, 0.1);
91
+ padding: 4px 12px;
92
+ width: fit-content;
93
+ border-radius: 8px;
94
+ }
95
+
96
+ &-main-entity-info {
97
+ display: flex;
98
+ flex-wrap: wrap;
99
+ align-items: center;
100
+ column-gap: 20px;
101
+ row-gap: 10px;
102
+ }
103
+
104
+ &-info-item {
105
+ display: flex;
106
+ align-items: center;
107
+ }
108
+
109
+ &-info-name {
110
+ color: var(--text-color-secondary);
111
+ }
112
+
113
+ &-info-value {
114
+ color: var(--text-color);
115
+ font-weight: 500;
116
+ }
117
+ }
118
+
119
+