@myun/gimi-chat 0.8.2 → 0.8.3

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.
@@ -128,12 +128,9 @@ var AnswerItem = function AnswerItem(_ref) {
128
128
  }, {
129
129
  type: 'knowledge',
130
130
  component: function component(value) {
131
- var newVal = {
131
+ return /*#__PURE__*/React.createElement(KnowledgeIconGroup, {
132
132
  content: value.value,
133
133
  messageId: item.id
134
- };
135
- return /*#__PURE__*/React.createElement(KnowledgeIconGroup, {
136
- value: newVal
137
134
  });
138
135
  }
139
136
  }, {
@@ -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);
@@ -246,10 +246,6 @@
246
246
  .icon_btn span {
247
247
  white-space: nowrap;
248
248
  }
249
- .icon_btn:hover {
250
- background-color: #FFFFFF;
251
- color: #4086FF;
252
- }
253
249
 
254
250
  .icon_btn_active {
255
251
  background-color: #4086ff;
@@ -120,6 +120,11 @@ var MessageList = function MessageList(_ref) {
120
120
  _useState2 = _slicedToArray(_useState, 2),
121
121
  scrollParent = _useState2[0],
122
122
  setScrollParent = _useState2[1];
123
+ var _useState3 = useState(false),
124
+ _useState4 = _slicedToArray(_useState3, 2),
125
+ useVirtualScroll = _useState4[0],
126
+ setUseVirtualScroll = _useState4[1];
127
+ var VIRTUAL_SCROLL_THRESHOLD = 1200;
123
128
  useEffect(function () {
124
129
  if (containerRef.current && containerRef.current !== scrollParent) {
125
130
  setScrollParent(containerRef.current);
@@ -133,6 +138,21 @@ var MessageList = function MessageList(_ref) {
133
138
  return true;
134
139
  });
135
140
  }, [chatList, hideUserMessage]);
141
+ useEffect(function () {
142
+ if (!scrollParent) return;
143
+ var checkScrollHeight = function checkScrollHeight() {
144
+ var shouldUseVirtual = scrollParent.scrollHeight > VIRTUAL_SCROLL_THRESHOLD && scrollParent.scrollHeight > scrollParent.clientHeight;
145
+ setUseVirtualScroll(shouldUseVirtual);
146
+ };
147
+ var resizeObserver = new ResizeObserver(function () {
148
+ checkScrollHeight();
149
+ });
150
+ resizeObserver.observe(scrollParent);
151
+ checkScrollHeight();
152
+ return function () {
153
+ resizeObserver.disconnect();
154
+ };
155
+ }, [scrollParent, visibleChatList.length]);
136
156
  var renderItem = useCallback(function (_, v) {
137
157
  var _v$quoteTeachModelLis, _v$quoteProductList;
138
158
  if (!v) return null;
@@ -202,7 +222,7 @@ var MessageList = function MessageList(_ref) {
202
222
  className: classNames(styles.container)
203
223
  }, visibleChatList.length > 0 && /*#__PURE__*/React.createElement("div", {
204
224
  className: styles.textWrap
205
- }, scrollParent && /*#__PURE__*/React.createElement(Virtuoso, {
225
+ }, useVirtualScroll && scrollParent ? /*#__PURE__*/React.createElement(Virtuoso, {
206
226
  style: {
207
227
  height: '100%',
208
228
  minHeight: 1
@@ -210,7 +230,13 @@ var MessageList = function MessageList(_ref) {
210
230
  customScrollParent: scrollParent,
211
231
  data: visibleChatList,
212
232
  itemContent: renderItem
213
- }), /*#__PURE__*/React.createElement("div", {
233
+ }) : /*#__PURE__*/React.createElement("div", {
234
+ style: {
235
+ minHeight: '100%'
236
+ }
237
+ }, visibleChatList.map(function (v, index) {
238
+ return renderItem(index, v);
239
+ })), /*#__PURE__*/React.createElement("div", {
214
240
  className: styles.answerLoading,
215
241
  style: {
216
242
  visibility: msgLoading ? 'visible' : 'hidden'
@@ -10,12 +10,8 @@
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
- .icon_btn:hover {
18
- cursor: pointer;
19
- background-color: #FFFFFF;
20
- color: #4086FF;
21
17
  }
@@ -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