@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.
- package/dist/components/answer-item/index.js +1 -4
- package/dist/components/knowledge-trace/KnowledgeIconComponent.d.ts +5 -4
- package/dist/components/knowledge-trace/KnowledgeIconComponent.js +8 -7
- package/dist/components/knowledge-trace/index.module.css +0 -4
- package/dist/components/message-list/index.js +28 -2
- package/dist/components/product-tag/index.module.css +1 -5
- package/dist/hooks/useCommonChatAPI.js +3 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -128,12 +128,9 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
128
128
|
}, {
|
|
129
129
|
type: 'knowledge',
|
|
130
130
|
component: function component(value) {
|
|
131
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
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
|
|
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(
|
|
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
|
-
}, [
|
|
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:
|
|
103
|
+
messageId: messageId
|
|
103
104
|
});
|
|
104
105
|
})));
|
|
105
106
|
};
|
|
106
|
-
export default KnowledgeIconGroup;
|
|
107
|
+
export default /*#__PURE__*/React.memo(KnowledgeIconGroup);
|
|
@@ -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
|
-
},
|
|
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
|
-
})
|
|
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'
|
|
@@ -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
|