@myun/gimi-chat 0.8.2 → 0.8.4

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.
@@ -95,25 +95,8 @@ var AnswerItem = function AnswerItem(_ref) {
95
95
  var agentDetail = useAppSelector(function (state) {
96
96
  return state.gimiMenu.agentObj || {};
97
97
  });
98
- return /*#__PURE__*/React.createElement("div", {
99
- className: styles.title,
100
- onClickCapture: handleLinkClickCapture
101
- }, /*#__PURE__*/React.createElement("div", {
102
- className: classNames(styles.answer)
103
- }, item.mcp && /*#__PURE__*/React.createElement(WorkFlowContent, {
104
- chatItem: item
105
- }), item.vipLevel === 1 && item.reasoningContent && /*#__PURE__*/React.createElement(ReasoningContent, {
106
- reasoningTitle: reasoningTitle,
107
- item: item
108
- }), showTaskSuccess && /*#__PURE__*/React.createElement("div", {
109
- className: styles.completed
110
- }, /*#__PURE__*/React.createElement(IconTickCircle, {
111
- className: styles.checkIcon
112
- }), /*#__PURE__*/React.createElement("span", {
113
- className: styles.checkText
114
- }, "\u672C\u6B21\u4EFB\u52A1\u5DF2\u5B8C\u6210\uFF01")), showContentFlag && /*#__PURE__*/React.createElement(MMarkdown, {
115
- content: processString(item.content || ''),
116
- customRender: [{
98
+ var customRender = React.useMemo(function () {
99
+ return [{
117
100
  type: 'excel',
118
101
  component: function component(value) {
119
102
  var newVal = {
@@ -128,12 +111,9 @@ var AnswerItem = function AnswerItem(_ref) {
128
111
  }, {
129
112
  type: 'knowledge',
130
113
  component: function component(value) {
131
- var newVal = {
114
+ return /*#__PURE__*/React.createElement(KnowledgeIconGroup, {
132
115
  content: value.value,
133
116
  messageId: item.id
134
- };
135
- return /*#__PURE__*/React.createElement(KnowledgeIconGroup, {
136
- value: newVal
137
117
  });
138
118
  }
139
119
  }, {
@@ -144,7 +124,27 @@ var AnswerItem = function AnswerItem(_ref) {
144
124
  // type: 'correction',
145
125
  // component: AICorrection
146
126
  // }
147
- ],
127
+ ];
128
+ }, [onDownloadCallback, model, item.id]);
129
+ return /*#__PURE__*/React.createElement("div", {
130
+ className: styles.title,
131
+ onClickCapture: handleLinkClickCapture
132
+ }, /*#__PURE__*/React.createElement("div", {
133
+ className: classNames(styles.answer)
134
+ }, item.mcp && /*#__PURE__*/React.createElement(WorkFlowContent, {
135
+ chatItem: item
136
+ }), item.vipLevel === 1 && item.reasoningContent && /*#__PURE__*/React.createElement(ReasoningContent, {
137
+ reasoningTitle: reasoningTitle,
138
+ item: item
139
+ }), showTaskSuccess && /*#__PURE__*/React.createElement("div", {
140
+ className: styles.completed
141
+ }, /*#__PURE__*/React.createElement(IconTickCircle, {
142
+ className: styles.checkIcon
143
+ }), /*#__PURE__*/React.createElement("span", {
144
+ className: styles.checkText
145
+ }, "\u672C\u6B21\u4EFB\u52A1\u5DF2\u5B8C\u6210\uFF01")), showContentFlag && /*#__PURE__*/React.createElement(MMarkdown, {
146
+ content: processString(item.content || ''),
147
+ customRender: customRender,
148
148
  showLoading: item.loading
149
149
  }), showAskTag && /*#__PURE__*/React.createElement(AskCard, {
150
150
  item: item,
@@ -1,7 +1,8 @@
1
1
  import type { KonwledgeTraceState } from '.';
2
2
  import React from 'react';
3
3
  export declare const KnowledgeIconComponent: React.FC<KonwledgeTraceState>;
4
- declare const KnowledgeIconGroup: ({ value }: {
5
- value: any;
6
- }) => React.JSX.Element;
7
- export default KnowledgeIconGroup;
4
+ declare const _default: React.MemoExoticComponent<({ content, messageId }: {
5
+ content: string;
6
+ messageId: number;
7
+ }) => React.JSX.Element>;
8
+ export default _default;
@@ -35,7 +35,7 @@ export var KnowledgeIconComponent = function KnowledgeIconComponent(_ref2) {
35
35
  });
36
36
  var isLastMessage = lastMessageId !== undefined && lastMessageId === messageId;
37
37
  var iconUrl = type === 'video' ? knowledgeConstants.VIDEO_ICON_KNOWLADGE_TRACE_ADDRESS : type === 'document' ? knowledgeConstants.DOCUMENT_ICON_ADDRESS : knowledgeConstants.CLASS_ICON_ADDRESS;
38
- var handleIconClick = function handleIconClick() {
38
+ var handleIconClick = React.useCallback(function () {
39
39
  if (isMsgRecieving && isLastMessage) return; // 最新一条正在流式输出的消息,不打开溯源面板
40
40
  dispatch(openSidebar({
41
41
  type: 'knowledgeTrace',
@@ -47,7 +47,7 @@ export var KnowledgeIconComponent = function KnowledgeIconComponent(_ref2) {
47
47
  }
48
48
  }
49
49
  }));
50
- };
50
+ }, [isMsgRecieving, isLastMessage, dispatch, messageId, resources, type]);
51
51
  return /*#__PURE__*/React.createElement("div", {
52
52
  className: styles.icon_btn,
53
53
  onClick: handleIconClick
@@ -56,11 +56,12 @@ export var KnowledgeIconComponent = function KnowledgeIconComponent(_ref2) {
56
56
  }), /*#__PURE__*/React.createElement("span", null, "".concat(resources === null || resources === void 0 ? void 0 : resources.length, "\u4E2A").concat(type === 'video' ? '视频' : type === 'product' ? '课程' : '文档')));
57
57
  };
58
58
  var KnowledgeIconGroup = function KnowledgeIconGroup(_ref3) {
59
- var value = _ref3.value;
59
+ var content = _ref3.content,
60
+ messageId = _ref3.messageId;
60
61
  var knowledgeMap = React.useMemo(function () {
61
62
  var returnMap = new Map();
62
63
  try {
63
- var parseArr = JSON.parse(value.content);
64
+ var parseArr = JSON.parse(content);
64
65
  if (!Array.isArray(parseArr)) return returnMap;
65
66
  parseArr.forEach(function (item) {
66
67
  var orgArr = returnMap.get(item.type) || [];
@@ -82,7 +83,7 @@ var KnowledgeIconGroup = function KnowledgeIconGroup(_ref3) {
82
83
  } catch (error) {
83
84
  return returnMap;
84
85
  }
85
- }, [value.content]);
86
+ }, [content]);
86
87
  var renderList = knowledgeMap.keys().toArray() || [];
87
88
  return /*#__PURE__*/React.createElement("div", {
88
89
  style: {
@@ -99,8 +100,8 @@ var KnowledgeIconGroup = function KnowledgeIconGroup(_ref3) {
99
100
  type: item,
100
101
  resources: knowledgeMap.get(item) || [],
101
102
  key: item,
102
- messageId: value.messageId
103
+ messageId: messageId
103
104
  });
104
105
  })));
105
106
  };
106
- export default KnowledgeIconGroup;
107
+ export default /*#__PURE__*/React.memo(KnowledgeIconGroup);
@@ -24,6 +24,95 @@ import { FileStatus } from "../../interfaces/fileInterface";
24
24
  import useChatActions from "../../hooks/useChatActions";
25
25
  import CopyButton from "../message-actions/CopyButton";
26
26
  import { Virtuoso } from 'react-virtuoso';
27
+ var MessageItem = /*#__PURE__*/React.memo(function (props) {
28
+ var _v$quoteTeachModelLis, _v$quoteProductList;
29
+ var v = props.v,
30
+ chatUI = props.chatUI,
31
+ hideUserMessage = props.hideUserMessage,
32
+ showOpera = props.showOpera,
33
+ handleReTry = props.handleReTry,
34
+ onCopyCallback = props.onCopyCallback,
35
+ onSucessExcel = props.onSucessExcel,
36
+ onFailureExcel = props.onFailureExcel,
37
+ onRetryExcel = props.onRetryExcel,
38
+ onLikeCallback = props.onLikeCallback,
39
+ onUnLikeCallback = props.onUnLikeCallback,
40
+ showCommend = props.showCommend,
41
+ handleClickPromptWord = props.handleClickPromptWord,
42
+ handleShowCourse = props.handleShowCourse,
43
+ handleClickAskList = props.handleClickAskList,
44
+ playTTSByText = props.playTTSByText,
45
+ stopTTSByText = props.stopTTSByText,
46
+ isPlaying = props.isPlaying,
47
+ onRegenerateClick = props.onRegenerateClick,
48
+ enableCopy = props.enableCopy,
49
+ enableLike = props.enableLike,
50
+ enableUnLike = props.enableUnLike,
51
+ enableRegenerate = props.enableRegenerate,
52
+ enableVoicePlay = props.enableVoicePlay,
53
+ onDownloadCallback = props.onDownloadCallback,
54
+ reasoningTitle = props.reasoningTitle,
55
+ model = props.model;
56
+ if (!v) return null;
57
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
58
+ className: classNames(styles.textItem, _defineProperty({}, styles.question, (v === null || v === void 0 ? void 0 : v.type) === 0)),
59
+ onMouseLeave: function onMouseLeave() {
60
+ return chatUI.setShowCopyId(0);
61
+ },
62
+ onMouseEnter: function onMouseEnter() {
63
+ if (!v.loading) chatUI.setShowCopyId(v.id);
64
+ }
65
+ }, (v === null || v === void 0 ? void 0 : v.type) === 0 && !hideUserMessage && /*#__PURE__*/React.createElement(React.Fragment, null, v.status !== 1 && /*#__PURE__*/React.createElement("div", {
66
+ className: styles.qusetionOpera
67
+ }, v.status === 0 && /*#__PURE__*/React.createElement(Spin, {
68
+ size: "small"
69
+ })), (((_v$quoteTeachModelLis = v.quoteTeachModelList) === null || _v$quoteTeachModelLis === void 0 ? void 0 : _v$quoteTeachModelLis.length) > 0 || ((_v$quoteProductList = v.quoteProductList) === null || _v$quoteProductList === void 0 ? void 0 : _v$quoteProductList.length) > 0) && /*#__PURE__*/React.createElement(References, {
70
+ quoteProductList: v.quoteProductList,
71
+ quoteTeachModelList: v.quoteTeachModelList
72
+ }), v.content && /*#__PURE__*/React.createElement("div", {
73
+ className: styles.title
74
+ }, replaceBraces(v.content)), v.messageFiles && /*#__PURE__*/React.createElement("div", {
75
+ className: styles.listBox
76
+ }, /*#__PURE__*/React.createElement(UploadList, {
77
+ file: v.messageFiles,
78
+ showDel: false,
79
+ handleDelFile: function handleDelFile() {},
80
+ handleReTry: handleReTry
81
+ })), v.content && /*#__PURE__*/React.createElement("div", {
82
+ className: styles.copyBtn,
83
+ style: {
84
+ opacity: showOpera(v.id) ? 1 : 0
85
+ }
86
+ }, /*#__PURE__*/React.createElement(CopyButton, {
87
+ item: replaceBraces(v.content),
88
+ onCopyCallback: onCopyCallback
89
+ }))), (v === null || v === void 0 ? void 0 : v.type) === 1 && /*#__PURE__*/React.createElement(AnswerItem, {
90
+ item: v,
91
+ showOpera: showOpera,
92
+ onSucess: onSucessExcel,
93
+ onFailure: onFailureExcel,
94
+ onRetry: onRetryExcel,
95
+ onCopyCallback: onCopyCallback,
96
+ onLikeCallback: onLikeCallback,
97
+ onUnLikeCallback: onUnLikeCallback,
98
+ showCommend: showCommend,
99
+ handleClickPromptWord: handleClickPromptWord,
100
+ handleShowCourse: handleShowCourse,
101
+ handleClickAskList: handleClickAskList,
102
+ playTTSByText: playTTSByText,
103
+ stopTTSByText: stopTTSByText,
104
+ isVoicePlaying: isPlaying,
105
+ onRegenerateClick: onRegenerateClick,
106
+ enableCopy: enableCopy,
107
+ enableLike: enableLike,
108
+ enableUnLike: enableUnLike,
109
+ enableRegenerate: enableRegenerate,
110
+ enableVoicePlay: enableVoicePlay,
111
+ onDownloadCallback: onDownloadCallback,
112
+ reasoningTitle: reasoningTitle,
113
+ model: model
114
+ })));
115
+ });
27
116
  var MessageList = function MessageList(_ref) {
28
117
  var chatList = _ref.chatList,
29
118
  handleSend = _ref.handleSend,
@@ -120,6 +209,11 @@ var MessageList = function MessageList(_ref) {
120
209
  _useState2 = _slicedToArray(_useState, 2),
121
210
  scrollParent = _useState2[0],
122
211
  setScrollParent = _useState2[1];
212
+ var _useState3 = useState(false),
213
+ _useState4 = _slicedToArray(_useState3, 2),
214
+ useVirtualScroll = _useState4[0],
215
+ setUseVirtualScroll = _useState4[1];
216
+ var VIRTUAL_SCROLL_THRESHOLD = 1200;
123
217
  useEffect(function () {
124
218
  if (containerRef.current && containerRef.current !== scrollParent) {
125
219
  setScrollParent(containerRef.current);
@@ -133,48 +227,32 @@ var MessageList = function MessageList(_ref) {
133
227
  return true;
134
228
  });
135
229
  }, [chatList, hideUserMessage]);
230
+ useEffect(function () {
231
+ if (!scrollParent) return;
232
+ var checkScrollHeight = function checkScrollHeight() {
233
+ var shouldUseVirtual = scrollParent.scrollHeight > VIRTUAL_SCROLL_THRESHOLD && scrollParent.scrollHeight > scrollParent.clientHeight;
234
+ setUseVirtualScroll(shouldUseVirtual);
235
+ };
236
+ var resizeObserver = new ResizeObserver(function () {
237
+ checkScrollHeight();
238
+ });
239
+ resizeObserver.observe(scrollParent);
240
+ checkScrollHeight();
241
+ return function () {
242
+ resizeObserver.disconnect();
243
+ };
244
+ }, [scrollParent, visibleChatList.length]);
136
245
  var renderItem = useCallback(function (_, v) {
137
- var _v$quoteTeachModelLis, _v$quoteProductList;
138
- if (!v) return null;
139
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
140
- className: classNames(styles.textItem, _defineProperty({}, styles.question, (v === null || v === void 0 ? void 0 : v.type) === 0)),
141
- onMouseLeave: function onMouseLeave() {
142
- return chatUI.setShowCopyId(0);
143
- },
144
- onMouseEnter: function onMouseEnter() {
145
- if (!v.loading) chatUI.setShowCopyId(v.id);
146
- }
147
- }, (v === null || v === void 0 ? void 0 : v.type) === 0 && !hideUserMessage && /*#__PURE__*/React.createElement(React.Fragment, null, v.status !== 1 && /*#__PURE__*/React.createElement("div", {
148
- className: styles.qusetionOpera
149
- }, v.status === 0 && /*#__PURE__*/React.createElement(Spin, {
150
- size: "small"
151
- })), (((_v$quoteTeachModelLis = v.quoteTeachModelList) === null || _v$quoteTeachModelLis === void 0 ? void 0 : _v$quoteTeachModelLis.length) > 0 || ((_v$quoteProductList = v.quoteProductList) === null || _v$quoteProductList === void 0 ? void 0 : _v$quoteProductList.length) > 0) && /*#__PURE__*/React.createElement(References, {
152
- quoteProductList: v.quoteProductList,
153
- quoteTeachModelList: v.quoteTeachModelList
154
- }), v.content && /*#__PURE__*/React.createElement("div", {
155
- className: styles.title
156
- }, replaceBraces(v.content)), v.messageFiles && /*#__PURE__*/React.createElement("div", {
157
- className: styles.listBox
158
- }, /*#__PURE__*/React.createElement(UploadList, {
159
- file: v.messageFiles,
160
- showDel: false,
161
- handleDelFile: function handleDelFile() {},
162
- handleReTry: handleReTry
163
- })), v.content && /*#__PURE__*/React.createElement("div", {
164
- className: styles.copyBtn,
165
- style: {
166
- opacity: showOpera(v.id) ? 1 : 0
167
- }
168
- }, /*#__PURE__*/React.createElement(CopyButton, {
169
- item: replaceBraces(v.content),
170
- onCopyCallback: onCopyCallback
171
- }))), (v === null || v === void 0 ? void 0 : v.type) === 1 && /*#__PURE__*/React.createElement(AnswerItem, {
172
- item: v,
246
+ return /*#__PURE__*/React.createElement(MessageItem, {
247
+ v: v,
248
+ chatUI: chatUI,
249
+ hideUserMessage: hideUserMessage,
173
250
  showOpera: showOpera,
174
- onSucess: onSucessExcel,
175
- onFailure: onFailureExcel,
176
- onRetry: onRetryExcel,
251
+ handleReTry: handleReTry,
177
252
  onCopyCallback: onCopyCallback,
253
+ onSucessExcel: onSucessExcel,
254
+ onFailureExcel: onFailureExcel,
255
+ onRetryExcel: onRetryExcel,
178
256
  onLikeCallback: onLikeCallback,
179
257
  onUnLikeCallback: onUnLikeCallback,
180
258
  showCommend: showCommend,
@@ -183,7 +261,7 @@ var MessageList = function MessageList(_ref) {
183
261
  handleClickAskList: handleClickAskList,
184
262
  playTTSByText: playTTSByText,
185
263
  stopTTSByText: stopTTSByText,
186
- isVoicePlaying: isPlaying,
264
+ isPlaying: isPlaying,
187
265
  onRegenerateClick: onRegenerateClick,
188
266
  enableCopy: enableCopy,
189
267
  enableLike: enableLike,
@@ -193,7 +271,7 @@ var MessageList = function MessageList(_ref) {
193
271
  onDownloadCallback: onDownloadCallback,
194
272
  reasoningTitle: reasoningTitle,
195
273
  model: model
196
- })));
274
+ });
197
275
  }, [chatUI, hideUserMessage, showOpera, onCopyCallback, onSucessExcel, onFailureExcel, onRetryExcel, showCommend, handleClickPromptWord, handleShowCourse, handleClickAskList, playTTSByText, stopTTSByText, isPlaying, onRegenerateClick, enableCopy, enableLike, enableUnLike, enableRegenerate, enableVoicePlay, onDownloadCallback, reasoningTitle, model, handleReTry, onLikeCallback, onUnLikeCallback]);
198
276
  return /*#__PURE__*/React.createElement("div", {
199
277
  className: classNames(styles.main),
@@ -202,7 +280,7 @@ var MessageList = function MessageList(_ref) {
202
280
  className: classNames(styles.container)
203
281
  }, visibleChatList.length > 0 && /*#__PURE__*/React.createElement("div", {
204
282
  className: styles.textWrap
205
- }, scrollParent && /*#__PURE__*/React.createElement(Virtuoso, {
283
+ }, useVirtualScroll && scrollParent ? /*#__PURE__*/React.createElement(Virtuoso, {
206
284
  style: {
207
285
  height: '100%',
208
286
  minHeight: 1
@@ -210,7 +288,13 @@ var MessageList = function MessageList(_ref) {
210
288
  customScrollParent: scrollParent,
211
289
  data: visibleChatList,
212
290
  itemContent: renderItem
213
- }), /*#__PURE__*/React.createElement("div", {
291
+ }) : /*#__PURE__*/React.createElement("div", {
292
+ style: {
293
+ minHeight: '100%'
294
+ }
295
+ }, visibleChatList.map(function (v, index) {
296
+ return renderItem(index, v);
297
+ })), /*#__PURE__*/React.createElement("div", {
214
298
  className: styles.answerLoading,
215
299
  style: {
216
300
  visibility: msgLoading ? 'visible' : 'hidden'
@@ -10,12 +10,12 @@
10
10
  gap: 5px;
11
11
  border: 0;
12
12
  background-color: #f1f7ff;
13
+ cursor: pointer;
13
14
  }
14
15
  .icon_btn span {
15
16
  white-space: nowrap;
16
17
  }
17
18
  .icon_btn:hover {
18
- cursor: pointer;
19
19
  background-color: #FFFFFF;
20
20
  color: #4086FF;
21
21
  }
@@ -602,6 +602,9 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
602
602
  return item.role === 0;
603
603
  }).pop(); // 检查最后一条消息是否为未完成的AI消息
604
604
  if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 0 && lastMessage.chatId) {
605
+ if (lastMessage.vipLevel === 1) {
606
+ vipLevelRef.current = 1;
607
+ }
605
608
  newMessageList = [].concat(_toConsumableArray(chatList.slice(0, -1)), [_objectSpread(_objectSpread({}, lastMessage), {}, {
606
609
  expand: true,
607
610
  stop: 0