@myun/gimi-chat 0.1.9 → 0.2.1
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/apis/useApi.d.ts +3 -0
- package/dist/apis/useApi.js +24 -3
- package/dist/components/chat-input/index.js +9 -1
- package/dist/components/preset-agent-content/index.js +0 -1
- package/dist/hooks/useChatStream.d.ts +1 -1
- package/dist/hooks/useChatStream.js +2 -2
- package/dist/hooks/useCommonChatAPI.d.ts +1 -1
- package/dist/hooks/useCommonChatAPI.js +169 -120
- package/dist/store/slices/gimiMenuSlice.d.ts +6 -1
- package/dist/store/slices/gimiMenuSlice.js +8 -2
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -21,7 +21,7 @@ import useApi from "../apis/useApi";
|
|
|
21
21
|
import React, { useRef } from 'react';
|
|
22
22
|
import { Toast } from "@douyinfe/semi-ui";
|
|
23
23
|
import { useAppDispatch, useAppSelector } from "../store/hooks";
|
|
24
|
-
import { setMessageList, setFileList, setConversationId, setAgentDetail } from "../store/slices/gimiMenuSlice";
|
|
24
|
+
import { setMessageList, setFileList, setConversationId, setAgentDetail, setAutoLoadConversation } from "../store/slices/gimiMenuSlice";
|
|
25
25
|
import { fileValidation, processString } from "../utils/tools";
|
|
26
26
|
import { filterPropmptFromUserInput } from "../utils/tools";
|
|
27
27
|
import { useChatMessage } from "./useChatMessage";
|
|
@@ -39,7 +39,8 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
39
39
|
createRoomId = _useApi.createRoomId,
|
|
40
40
|
getAgentDetail = _useApi.getAgentDetail,
|
|
41
41
|
deleteConversationById = _useApi.deleteConversationById,
|
|
42
|
-
getAiCorrection = _useApi.getAiCorrection
|
|
42
|
+
getAiCorrection = _useApi.getAiCorrection,
|
|
43
|
+
checkRetry = _useApi.checkRetry;
|
|
43
44
|
var dispatch = useAppDispatch();
|
|
44
45
|
var _React$useState = React.useState(''),
|
|
45
46
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
@@ -60,14 +61,13 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
60
61
|
setStatus = _React$useState8[1]; // 0 没输入内容 1 正在输入 2 ai正在回复 3 ai即将回复
|
|
61
62
|
var valueRef = React.useRef(''); // 输入框的值
|
|
62
63
|
var vipLevelRef = React.useRef(null);
|
|
63
|
-
var isNewConversationRef = React.useRef(false);
|
|
64
64
|
var step = React.useRef(0); // 接口请求step
|
|
65
65
|
var controllerRef = React.useRef(null); // 发起对话接口controller
|
|
66
66
|
var inputModelRef = React.useRef(null);
|
|
67
67
|
var _useChatMessage = useChatMessage(),
|
|
68
68
|
createUserChat = _useChatMessage.createUserChat,
|
|
69
69
|
createAiChat = _useChatMessage.createAiChat;
|
|
70
|
-
var _useChatStream = useChatStream(),
|
|
70
|
+
var _useChatStream = useChatStream(platform),
|
|
71
71
|
fetchChatStreamHook = _useChatStream.fetchChatStream,
|
|
72
72
|
setIgnoreOnMessage = _useChatStream.setIgnoreOnMessage,
|
|
73
73
|
streamEsAbortRef = _useChatStream.esAbortRef;
|
|
@@ -115,6 +115,9 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
115
115
|
var token = useAppSelector(function (state) {
|
|
116
116
|
return state.gimiMenu.token;
|
|
117
117
|
});
|
|
118
|
+
var autoLoadConversation = useAppSelector(function (state) {
|
|
119
|
+
return state.gimiMenu.autoLoadConversation;
|
|
120
|
+
});
|
|
118
121
|
|
|
119
122
|
// 使用 ref 存储最新的值,避免闭包陷阱
|
|
120
123
|
var messageListRef = useRef(messageList || []);
|
|
@@ -140,7 +143,6 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
140
143
|
agentObjRef.current = agentObj;
|
|
141
144
|
isMsgRecievingRef.current = isMsgRecieving;
|
|
142
145
|
fileListRef.current = fileList;
|
|
143
|
-
conversationIdRef.current = conversationId;
|
|
144
146
|
bussinessParamsRef.current = bussinessParams;
|
|
145
147
|
quoteProductListRef.current = quoteProductList;
|
|
146
148
|
quoteTeachModelListRef.current = quoteTeachModelList;
|
|
@@ -214,14 +216,6 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
214
216
|
return _ref.apply(this, arguments);
|
|
215
217
|
};
|
|
216
218
|
}(), [getAiCorrection]);
|
|
217
|
-
var regenerate = React.useCallback(function () {
|
|
218
|
-
var _reverse$find;
|
|
219
|
-
var value = (_reverse$find = _toConsumableArray(messageListRef.current).reverse().find(function (item) {
|
|
220
|
-
return item.role === 0;
|
|
221
|
-
})) === null || _reverse$find === void 0 ? void 0 : _reverse$find.content;
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
223
|
-
handleSend(value || '');
|
|
224
|
-
}, []);
|
|
225
219
|
var deleteConversation = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
226
220
|
var res;
|
|
227
221
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
@@ -674,13 +668,56 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
674
668
|
return _ref8.apply(this, arguments);
|
|
675
669
|
};
|
|
676
670
|
}(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList]);
|
|
671
|
+
var regenerate = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
672
|
+
var res, retryId, newMessageList;
|
|
673
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
674
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
675
|
+
case 0:
|
|
676
|
+
_context10.prev = 0;
|
|
677
|
+
_context10.next = 3;
|
|
678
|
+
return checkRetry({
|
|
679
|
+
conversationId: conversationIdRef.current
|
|
680
|
+
});
|
|
681
|
+
case 3:
|
|
682
|
+
res = _context10.sent;
|
|
683
|
+
if (res.status === 0 && res.result) {
|
|
684
|
+
retryId = res.result;
|
|
685
|
+
setMsgLoading(true);
|
|
686
|
+
newMessageList = [].concat(_toConsumableArray(messageListRef.current.slice(0, -1)), [_objectSpread(_objectSpread({}, messageListRef.current[messageListRef.current.length - 1]), {}, {
|
|
687
|
+
content: '',
|
|
688
|
+
reasoningResponse: '',
|
|
689
|
+
relatedResourceList: [],
|
|
690
|
+
loading: false,
|
|
691
|
+
reasoningLoading: false,
|
|
692
|
+
stop: 0
|
|
693
|
+
})]);
|
|
694
|
+
dispatch(setMessageList({
|
|
695
|
+
messageList: newMessageList
|
|
696
|
+
}));
|
|
697
|
+
// 继续流式处理聊天
|
|
698
|
+
streamChat(retryId, false);
|
|
699
|
+
} else {
|
|
700
|
+
Toast.error(res.message || '不可进行重试');
|
|
701
|
+
}
|
|
702
|
+
_context10.next = 10;
|
|
703
|
+
break;
|
|
704
|
+
case 7:
|
|
705
|
+
_context10.prev = 7;
|
|
706
|
+
_context10.t0 = _context10["catch"](0);
|
|
707
|
+
Toast.error('重试失败');
|
|
708
|
+
case 10:
|
|
709
|
+
case "end":
|
|
710
|
+
return _context10.stop();
|
|
711
|
+
}
|
|
712
|
+
}, _callee10, null, [[0, 7]]);
|
|
713
|
+
})), [streamChat]);
|
|
677
714
|
|
|
678
715
|
// 单独的断点续传
|
|
679
716
|
var checkUnfinishedMessage = React.useCallback( /*#__PURE__*/function () {
|
|
680
|
-
var
|
|
717
|
+
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(chatList) {
|
|
681
718
|
var lastMessage, newMessageList, _agentObjRef$current, lastUserRequestMessage;
|
|
682
|
-
return _regeneratorRuntime().wrap(function
|
|
683
|
-
while (1) switch (
|
|
719
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
720
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
684
721
|
case 0:
|
|
685
722
|
lastMessage = chatList[chatList.length - 1]; // 检查最后一条消息是否为未完成的AI消息
|
|
686
723
|
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 0 && lastMessage.chatId) {
|
|
@@ -698,7 +735,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
698
735
|
}, agentObjRef.current); // 调用续传接口
|
|
699
736
|
}
|
|
700
737
|
if (!((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 1)) {
|
|
701
|
-
|
|
738
|
+
_context11.next = 8;
|
|
702
739
|
break;
|
|
703
740
|
}
|
|
704
741
|
removeLastEventId("".concat(lastMessage.chatId));
|
|
@@ -707,19 +744,19 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
707
744
|
return item.role === 0;
|
|
708
745
|
}).slice(-1)[0];
|
|
709
746
|
if (!(((_agentObjRef$current = agentObjRef.current) === null || _agentObjRef$current === void 0 ? void 0 : _agentObjRef$current.isEnableRelated) === 1 && !(lastUserRequestMessage !== null && lastUserRequestMessage !== void 0 && lastUserRequestMessage.relatedResourceList) && ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'end' || (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'COMPLETED') && lastMessage.stop === 0)) {
|
|
710
|
-
|
|
747
|
+
_context11.next = 8;
|
|
711
748
|
break;
|
|
712
749
|
}
|
|
713
|
-
|
|
750
|
+
_context11.next = 8;
|
|
714
751
|
return rewriteRecommendListFormHistory(chatList, "".concat(lastUserRequestMessage.chatId));
|
|
715
752
|
case 8:
|
|
716
753
|
case "end":
|
|
717
|
-
return
|
|
754
|
+
return _context11.stop();
|
|
718
755
|
}
|
|
719
|
-
},
|
|
756
|
+
}, _callee11);
|
|
720
757
|
}));
|
|
721
758
|
return function (_x21) {
|
|
722
|
-
return
|
|
759
|
+
return _ref11.apply(this, arguments);
|
|
723
760
|
};
|
|
724
761
|
}(), [dispatch, streamChat, removeLastEventId, rewriteRecommendListFormHistory]);
|
|
725
762
|
var _useChatHistory = useChatHistory(checkUnfinishedMessage, scrollBottomForce, containerRef),
|
|
@@ -738,52 +775,55 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
738
775
|
|
|
739
776
|
// 获取对话标题
|
|
740
777
|
var getHeaderValue = /*#__PURE__*/function () {
|
|
741
|
-
var
|
|
778
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(conversationId) {
|
|
742
779
|
var res, _res$result3;
|
|
743
|
-
return _regeneratorRuntime().wrap(function
|
|
744
|
-
while (1) switch (
|
|
780
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
781
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
745
782
|
case 0:
|
|
746
783
|
if (conversationId) {
|
|
747
|
-
|
|
784
|
+
_context12.next = 2;
|
|
748
785
|
break;
|
|
749
786
|
}
|
|
750
|
-
return
|
|
787
|
+
return _context12.abrupt("return");
|
|
751
788
|
case 2:
|
|
752
|
-
|
|
753
|
-
|
|
789
|
+
_context12.prev = 2;
|
|
790
|
+
_context12.next = 5;
|
|
754
791
|
return getMessageTitle("".concat(conversationId));
|
|
755
792
|
case 5:
|
|
756
|
-
res =
|
|
793
|
+
res = _context12.sent;
|
|
757
794
|
if ((res === null || res === void 0 ? void 0 : res.status) === 0) {
|
|
758
795
|
setHeaderValue(res === null || res === void 0 || (_res$result3 = res.result) === null || _res$result3 === void 0 ? void 0 : _res$result3.title);
|
|
759
796
|
}
|
|
760
|
-
|
|
797
|
+
_context12.next = 12;
|
|
761
798
|
break;
|
|
762
799
|
case 9:
|
|
763
|
-
|
|
764
|
-
|
|
800
|
+
_context12.prev = 9;
|
|
801
|
+
_context12.t0 = _context12["catch"](2);
|
|
765
802
|
Toast.error('网络异常');
|
|
766
803
|
case 12:
|
|
767
804
|
case "end":
|
|
768
|
-
return
|
|
805
|
+
return _context12.stop();
|
|
769
806
|
}
|
|
770
|
-
},
|
|
807
|
+
}, _callee12, null, [[2, 9]]);
|
|
771
808
|
}));
|
|
772
809
|
return function getHeaderValue(_x22) {
|
|
773
|
-
return
|
|
810
|
+
return _ref12.apply(this, arguments);
|
|
774
811
|
};
|
|
775
812
|
}();
|
|
776
813
|
React.useEffect(function () {
|
|
777
|
-
if (conversationId &&
|
|
778
|
-
|
|
779
|
-
|
|
814
|
+
if (conversationId && conversationIdRef.current !== conversationId) {
|
|
815
|
+
conversationIdRef.current = conversationId;
|
|
816
|
+
if (autoLoadConversation) {
|
|
817
|
+
getHeaderValue(conversationId);
|
|
818
|
+
getContentMessageList();
|
|
819
|
+
}
|
|
780
820
|
}
|
|
781
|
-
}, [conversationId]);
|
|
821
|
+
}, [conversationId, autoLoadConversation]);
|
|
782
822
|
|
|
783
823
|
// 开始会话
|
|
784
824
|
var startChat = React.useCallback( /*#__PURE__*/function () {
|
|
785
|
-
var
|
|
786
|
-
var _reverse$
|
|
825
|
+
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(messageList) {
|
|
826
|
+
var _reverse$find, _bussinessParamsRef$c;
|
|
787
827
|
var isSystemAuto,
|
|
788
828
|
conversationId,
|
|
789
829
|
isAskFileSend,
|
|
@@ -799,17 +839,17 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
799
839
|
responseMsg,
|
|
800
840
|
result,
|
|
801
841
|
aiChat,
|
|
802
|
-
|
|
803
|
-
return _regeneratorRuntime().wrap(function
|
|
804
|
-
while (1) switch (
|
|
842
|
+
_args13 = arguments;
|
|
843
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
844
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
805
845
|
case 0:
|
|
806
|
-
isSystemAuto =
|
|
807
|
-
conversationId =
|
|
808
|
-
isAskFileSend =
|
|
846
|
+
isSystemAuto = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
|
|
847
|
+
conversationId = _args13.length > 2 ? _args13[2] : undefined;
|
|
848
|
+
isAskFileSend = _args13.length > 3 ? _args13[3] : undefined;
|
|
809
849
|
// 如果是ask卡片的file上传,发送content为''
|
|
810
|
-
val = isAskFileSend ? '' : (_reverse$
|
|
850
|
+
val = isAskFileSend ? '' : (_reverse$find = _toConsumableArray(messageList).reverse().find(function (item) {
|
|
811
851
|
return item.role === 0;
|
|
812
|
-
})) === null || _reverse$
|
|
852
|
+
})) === null || _reverse$find === void 0 ? void 0 : _reverse$find.content;
|
|
813
853
|
if (controllerRef.current) {
|
|
814
854
|
controllerRef.current.abort();
|
|
815
855
|
}
|
|
@@ -820,11 +860,12 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
820
860
|
signal = controllerRef.current.signal;
|
|
821
861
|
step.current = 1;
|
|
822
862
|
currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c = bussinessParamsRef.current) === null || _bussinessParamsRef$c === void 0 ? void 0 : _bussinessParamsRef$c.bussinessParams) || {});
|
|
823
|
-
|
|
863
|
+
_context13.prev = 10;
|
|
824
864
|
params = _objectSpread({
|
|
825
865
|
content: val,
|
|
826
866
|
conversationId: conversationId || conversationIdRef.current,
|
|
827
|
-
conversationType: (_agentObjRef$current2 = agentObjRef.current) === null || _agentObjRef$current2 === void 0 ? void 0 : _agentObjRef$current2.conversationType
|
|
867
|
+
conversationType: (_agentObjRef$current2 = agentObjRef.current) === null || _agentObjRef$current2 === void 0 ? void 0 : _agentObjRef$current2.conversationType,
|
|
868
|
+
preview: platform === 'preview' ? 1 : 0
|
|
828
869
|
}, currentBussinessParams);
|
|
829
870
|
_fileList = fileListRef.current;
|
|
830
871
|
if ((_fileList === null || _fileList === void 0 ? void 0 : _fileList.length) > 0) {
|
|
@@ -849,7 +890,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
849
890
|
if (isSystemAuto) {
|
|
850
891
|
params.isSystemAuto = 1;
|
|
851
892
|
}
|
|
852
|
-
|
|
893
|
+
_context13.next = 20;
|
|
853
894
|
return fetch("https://".concat(baseUrlRef.current, "/mbot/web/agent-message"), {
|
|
854
895
|
method: 'POST',
|
|
855
896
|
headers: {
|
|
@@ -860,15 +901,15 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
860
901
|
body: JSON.stringify(params)
|
|
861
902
|
});
|
|
862
903
|
case 20:
|
|
863
|
-
_response =
|
|
904
|
+
_response = _context13.sent;
|
|
864
905
|
if (!_response.ok) {
|
|
865
|
-
|
|
906
|
+
_context13.next = 27;
|
|
866
907
|
break;
|
|
867
908
|
}
|
|
868
|
-
|
|
909
|
+
_context13.next = 24;
|
|
869
910
|
return _response.json();
|
|
870
911
|
case 24:
|
|
871
|
-
responseMsg =
|
|
912
|
+
responseMsg = _context13.sent;
|
|
872
913
|
// 清空发送时的引用
|
|
873
914
|
dispatch(setFileList({
|
|
874
915
|
fileList: []
|
|
@@ -882,7 +923,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
882
923
|
}));
|
|
883
924
|
// }
|
|
884
925
|
// 继续流式处理聊天
|
|
885
|
-
streamChat(result.id, false
|
|
926
|
+
streamChat(result.id, false);
|
|
886
927
|
} else {
|
|
887
928
|
Toast.error(responseMsg.message);
|
|
888
929
|
setMsgLoading(false);
|
|
@@ -893,12 +934,12 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
893
934
|
}
|
|
894
935
|
}
|
|
895
936
|
case 27:
|
|
896
|
-
|
|
937
|
+
_context13.next = 32;
|
|
897
938
|
break;
|
|
898
939
|
case 29:
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
if (
|
|
940
|
+
_context13.prev = 29;
|
|
941
|
+
_context13.t0 = _context13["catch"](10);
|
|
942
|
+
if (_context13.t0.name === 'AbortError') {
|
|
902
943
|
setMsgLoading(false);
|
|
903
944
|
if (valueRef.current) {
|
|
904
945
|
setStatus(1);
|
|
@@ -916,66 +957,66 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
916
957
|
}
|
|
917
958
|
case 32:
|
|
918
959
|
case "end":
|
|
919
|
-
return
|
|
960
|
+
return _context13.stop();
|
|
920
961
|
}
|
|
921
|
-
},
|
|
962
|
+
}, _callee13, null, [[10, 29]]);
|
|
922
963
|
}));
|
|
923
964
|
return function (_x23) {
|
|
924
|
-
return
|
|
965
|
+
return _ref13.apply(this, arguments);
|
|
925
966
|
};
|
|
926
967
|
}(), [dispatch]);
|
|
927
968
|
var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
|
|
928
|
-
var
|
|
969
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(agentId) {
|
|
929
970
|
var res;
|
|
930
|
-
return _regeneratorRuntime().wrap(function
|
|
931
|
-
while (1) switch (
|
|
971
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
972
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
932
973
|
case 0:
|
|
933
|
-
|
|
934
|
-
|
|
974
|
+
_context14.prev = 0;
|
|
975
|
+
_context14.next = 3;
|
|
935
976
|
return getAgentDetail(agentId);
|
|
936
977
|
case 3:
|
|
937
|
-
res =
|
|
978
|
+
res = _context14.sent;
|
|
938
979
|
if (!(res.status === 0)) {
|
|
939
|
-
|
|
980
|
+
_context14.next = 9;
|
|
940
981
|
break;
|
|
941
982
|
}
|
|
942
983
|
dispatch(setAgentDetail({
|
|
943
984
|
agentDetail: res.result
|
|
944
985
|
}));
|
|
945
|
-
return
|
|
986
|
+
return _context14.abrupt("return", res.result);
|
|
946
987
|
case 9:
|
|
947
988
|
Toast.error(res.message);
|
|
948
|
-
return
|
|
989
|
+
return _context14.abrupt("return", null);
|
|
949
990
|
case 11:
|
|
950
|
-
|
|
991
|
+
_context14.next = 17;
|
|
951
992
|
break;
|
|
952
993
|
case 13:
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
console.log('error',
|
|
956
|
-
return
|
|
994
|
+
_context14.prev = 13;
|
|
995
|
+
_context14.t0 = _context14["catch"](0);
|
|
996
|
+
console.log('error', _context14.t0);
|
|
997
|
+
return _context14.abrupt("return", null);
|
|
957
998
|
case 17:
|
|
958
999
|
case "end":
|
|
959
|
-
return
|
|
1000
|
+
return _context14.stop();
|
|
960
1001
|
}
|
|
961
|
-
},
|
|
1002
|
+
}, _callee14, null, [[0, 13]]);
|
|
962
1003
|
}));
|
|
963
1004
|
return function (_x24) {
|
|
964
|
-
return
|
|
1005
|
+
return _ref14.apply(this, arguments);
|
|
965
1006
|
};
|
|
966
1007
|
}(), []);
|
|
967
1008
|
var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
|
|
968
|
-
var
|
|
1009
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(value) {
|
|
969
1010
|
var _agentObjRef$current3, _bussinessParamsRef$c2;
|
|
970
1011
|
var currentBussinessParams, params, res;
|
|
971
|
-
return _regeneratorRuntime().wrap(function
|
|
972
|
-
while (1) switch (
|
|
1012
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1013
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
973
1014
|
case 0:
|
|
974
1015
|
if ((_agentObjRef$current3 = agentObjRef.current) !== null && _agentObjRef$current3 !== void 0 && _agentObjRef$current3.agentId) {
|
|
975
|
-
|
|
1016
|
+
_context15.next = 2;
|
|
976
1017
|
break;
|
|
977
1018
|
}
|
|
978
|
-
return
|
|
1019
|
+
return _context15.abrupt("return", Toast.error('请先关联智能体'));
|
|
979
1020
|
case 2:
|
|
980
1021
|
currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c2 = bussinessParamsRef.current) === null || _bussinessParamsRef$c2 === void 0 ? void 0 : _bussinessParamsRef$c2.bussinessParams) || {});
|
|
981
1022
|
params = _objectSpread({
|
|
@@ -983,14 +1024,16 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
983
1024
|
conversationType: agentObjRef.current.conversationType,
|
|
984
1025
|
botId: agentObjRef.current.botId,
|
|
985
1026
|
preview: platform === 'preview' ? 1 : 0
|
|
986
|
-
}, currentBussinessParams);
|
|
987
|
-
|
|
988
|
-
|
|
1027
|
+
}, currentBussinessParams); // 手动创建会话,不自动加载历史消息
|
|
1028
|
+
dispatch(setAutoLoadConversation({
|
|
1029
|
+
autoLoadConversation: false
|
|
1030
|
+
}));
|
|
1031
|
+
_context15.prev = 5;
|
|
989
1032
|
setMsgLoading(true);
|
|
990
|
-
|
|
1033
|
+
_context15.next = 9;
|
|
991
1034
|
return createRoomId(params);
|
|
992
1035
|
case 9:
|
|
993
|
-
res =
|
|
1036
|
+
res = _context15.sent;
|
|
994
1037
|
if (res.status === 0) {
|
|
995
1038
|
dispatch(setConversationId({
|
|
996
1039
|
conversationId: res.result
|
|
@@ -999,25 +1042,30 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
999
1042
|
getHeaderValue(res.result);
|
|
1000
1043
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
1001
1044
|
handleSend(value, agentObjRef.current, false, res.result);
|
|
1045
|
+
setTimeout(function () {
|
|
1046
|
+
dispatch(setAutoLoadConversation({
|
|
1047
|
+
autoLoadConversation: true
|
|
1048
|
+
}));
|
|
1049
|
+
}, 3000);
|
|
1002
1050
|
} else {
|
|
1003
1051
|
Toast.error(res.message);
|
|
1004
1052
|
}
|
|
1005
|
-
|
|
1053
|
+
_context15.next = 18;
|
|
1006
1054
|
break;
|
|
1007
1055
|
case 13:
|
|
1008
|
-
|
|
1009
|
-
|
|
1056
|
+
_context15.prev = 13;
|
|
1057
|
+
_context15.t0 = _context15["catch"](5);
|
|
1010
1058
|
Toast.error('创建会话失败');
|
|
1011
|
-
console.log('error',
|
|
1059
|
+
console.log('error', _context15.t0);
|
|
1012
1060
|
setMsgLoading(false);
|
|
1013
1061
|
case 18:
|
|
1014
1062
|
case "end":
|
|
1015
|
-
return
|
|
1063
|
+
return _context15.stop();
|
|
1016
1064
|
}
|
|
1017
|
-
},
|
|
1065
|
+
}, _callee15, null, [[5, 13]]);
|
|
1018
1066
|
}));
|
|
1019
1067
|
return function (_x25) {
|
|
1020
|
-
return
|
|
1068
|
+
return _ref15.apply(this, arguments);
|
|
1021
1069
|
};
|
|
1022
1070
|
}(), []);
|
|
1023
1071
|
React.useEffect(function () {
|
|
@@ -1037,10 +1085,11 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1037
1085
|
dispatch(setMessageList({
|
|
1038
1086
|
messageList: []
|
|
1039
1087
|
}));
|
|
1088
|
+
setHeaderValue('');
|
|
1040
1089
|
}
|
|
1041
1090
|
}, [resetKey]);
|
|
1042
1091
|
var handleSend = React.useCallback( /*#__PURE__*/function () {
|
|
1043
|
-
var
|
|
1092
|
+
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(val) {
|
|
1044
1093
|
var agent,
|
|
1045
1094
|
isSystemAuto,
|
|
1046
1095
|
conversationId,
|
|
@@ -1052,41 +1101,41 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1052
1101
|
_prevChatList,
|
|
1053
1102
|
lastItem,
|
|
1054
1103
|
newChatList,
|
|
1055
|
-
|
|
1056
|
-
return _regeneratorRuntime().wrap(function
|
|
1057
|
-
while (1) switch (
|
|
1104
|
+
_args16 = arguments;
|
|
1105
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1106
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1058
1107
|
case 0:
|
|
1059
|
-
agent =
|
|
1060
|
-
isSystemAuto =
|
|
1061
|
-
conversationId =
|
|
1108
|
+
agent = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : agentObjRef.current;
|
|
1109
|
+
isSystemAuto = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : false;
|
|
1110
|
+
conversationId = _args16.length > 3 ? _args16[3] : undefined;
|
|
1062
1111
|
value = val.trim();
|
|
1063
1112
|
if (!(!value && !isSystemAuto)) {
|
|
1064
|
-
|
|
1113
|
+
_context16.next = 6;
|
|
1065
1114
|
break;
|
|
1066
1115
|
}
|
|
1067
|
-
return
|
|
1116
|
+
return _context16.abrupt("return");
|
|
1068
1117
|
case 6:
|
|
1069
1118
|
if (navigator.onLine) {
|
|
1070
|
-
|
|
1119
|
+
_context16.next = 9;
|
|
1071
1120
|
break;
|
|
1072
1121
|
}
|
|
1073
1122
|
Toast.error('无法连接到网络');
|
|
1074
|
-
return
|
|
1123
|
+
return _context16.abrupt("return");
|
|
1075
1124
|
case 9:
|
|
1076
1125
|
if (!(status === 2 || isMsgRecievingRef.current)) {
|
|
1077
|
-
|
|
1126
|
+
_context16.next = 12;
|
|
1078
1127
|
break;
|
|
1079
1128
|
}
|
|
1080
1129
|
Toast.error('AI正在输出中,请稍后');
|
|
1081
|
-
return
|
|
1130
|
+
return _context16.abrupt("return");
|
|
1082
1131
|
case 12:
|
|
1083
1132
|
fileValidationMsg = fileValidation(fileListRef.current);
|
|
1084
1133
|
if (!fileValidationMsg) {
|
|
1085
|
-
|
|
1134
|
+
_context16.next = 16;
|
|
1086
1135
|
break;
|
|
1087
1136
|
}
|
|
1088
1137
|
Toast.error(fileValidationMsg);
|
|
1089
|
-
return
|
|
1138
|
+
return _context16.abrupt("return");
|
|
1090
1139
|
case 16:
|
|
1091
1140
|
if (isPlaying) {
|
|
1092
1141
|
// 点击发送按钮时,先停止播放
|
|
@@ -1121,12 +1170,12 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1121
1170
|
}
|
|
1122
1171
|
case 23:
|
|
1123
1172
|
case "end":
|
|
1124
|
-
return
|
|
1173
|
+
return _context16.stop();
|
|
1125
1174
|
}
|
|
1126
|
-
},
|
|
1175
|
+
}, _callee16);
|
|
1127
1176
|
}));
|
|
1128
1177
|
return function (_x26) {
|
|
1129
|
-
return
|
|
1178
|
+
return _ref16.apply(this, arguments);
|
|
1130
1179
|
};
|
|
1131
1180
|
}(), [dispatch, startChat]);
|
|
1132
1181
|
var handleSendFile = React.useCallback(function (messageList) {
|
|
@@ -1164,10 +1213,10 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1164
1213
|
}));
|
|
1165
1214
|
// 当有文件内容时处理请求
|
|
1166
1215
|
if ((_fileList$ = fileList[0]) !== null && _fileList$ !== void 0 && _fileList$.content && ((_messageList = messageList[messageList.length - 2]) === null || _messageList === void 0 ? void 0 : _messageList.moduleType) === 'ask') {
|
|
1167
|
-
var _reverse$
|
|
1168
|
-
var moduleInfo = (_reverse$
|
|
1216
|
+
var _reverse$find2, _messageListRef$curre;
|
|
1217
|
+
var moduleInfo = (_reverse$find2 = _toConsumableArray(messageList).reverse().find(function (v) {
|
|
1169
1218
|
return v.moduleType === 'ask';
|
|
1170
|
-
})) === null || _reverse$
|
|
1219
|
+
})) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.moduleInfo;
|
|
1171
1220
|
var _inputModel = _defineProperty({}, "".concat(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.id, ".input"), '');
|
|
1172
1221
|
inputModelRef.current = _inputModel;
|
|
1173
1222
|
if (((_messageListRef$curre = messageListRef.current) === null || _messageListRef$curre === void 0 ? void 0 : _messageListRef$curre.length) > 0) {
|
|
@@ -7,6 +7,7 @@ export interface GimiMenuState {
|
|
|
7
7
|
token: string;
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
conversationId: number | null;
|
|
10
|
+
autoLoadConversation: boolean;
|
|
10
11
|
messageList: IChatMessageItem[];
|
|
11
12
|
isMsgRecieving: boolean;
|
|
12
13
|
currentMessageId: number | null;
|
|
@@ -91,6 +92,10 @@ export declare const setAgentDetail: import("@reduxjs/toolkit").ActionCreatorWit
|
|
|
91
92
|
quoteTeachModelList: GimiMenuState['quoteTeachModelList'];
|
|
92
93
|
}, "gimiMenu/setQuoteTeachModelList">, setShowMicWarning: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
93
94
|
showMicWarning: boolean;
|
|
94
|
-
}, "gimiMenu/setShowMicWarning">, setBussinessParams: import("@reduxjs/toolkit").ActionCreatorWithPayload<Partial<Record<string, any>>, "gimiMenu/setBussinessParams"
|
|
95
|
+
}, "gimiMenu/setShowMicWarning">, setBussinessParams: import("@reduxjs/toolkit").ActionCreatorWithPayload<Partial<Record<string, any>>, "gimiMenu/setBussinessParams">, setInitMsg: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
96
|
+
initMsg: string;
|
|
97
|
+
}, "gimiMenu/setInitMsg">, setAutoLoadConversation: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
98
|
+
autoLoadConversation: boolean;
|
|
99
|
+
}, "gimiMenu/setAutoLoadConversation">;
|
|
95
100
|
declare const reducer: Reducer<GimiMenuState>;
|
|
96
101
|
export default reducer;
|
|
@@ -20,6 +20,7 @@ var initialState = {
|
|
|
20
20
|
token: '',
|
|
21
21
|
baseUrl: '',
|
|
22
22
|
conversationId: null,
|
|
23
|
+
autoLoadConversation: true,
|
|
23
24
|
messageList: [],
|
|
24
25
|
isMsgRecieving: false,
|
|
25
26
|
currentMessageId: null,
|
|
@@ -206,6 +207,9 @@ var gimiMenuSlice = createSlice({
|
|
|
206
207
|
},
|
|
207
208
|
setInitMsg: function setInitMsg(state, action) {
|
|
208
209
|
state.initMsg = action.payload.initMsg;
|
|
210
|
+
},
|
|
211
|
+
setAutoLoadConversation: function setAutoLoadConversation(state, action) {
|
|
212
|
+
state.autoLoadConversation = action.payload.autoLoadConversation;
|
|
209
213
|
}
|
|
210
214
|
},
|
|
211
215
|
extraReducers: function extraReducers(builder) {
|
|
@@ -255,7 +259,9 @@ var _gimiMenuSlice$action = gimiMenuSlice.actions,
|
|
|
255
259
|
setQuoteProductList = _gimiMenuSlice$action.setQuoteProductList,
|
|
256
260
|
setQuoteTeachModelList = _gimiMenuSlice$action.setQuoteTeachModelList,
|
|
257
261
|
setShowMicWarning = _gimiMenuSlice$action.setShowMicWarning,
|
|
258
|
-
setBussinessParams = _gimiMenuSlice$action.setBussinessParams
|
|
259
|
-
|
|
262
|
+
setBussinessParams = _gimiMenuSlice$action.setBussinessParams,
|
|
263
|
+
setInitMsg = _gimiMenuSlice$action.setInitMsg,
|
|
264
|
+
setAutoLoadConversation = _gimiMenuSlice$action.setAutoLoadConversation;
|
|
265
|
+
export { setAgentDetail, setConversationId, setIsMsgRecieving, setBaseUrl, setToken, setPlatform, updateState, setMessageList, setFileList, setCurrentMessageId, updateParams, setShowKonwledgeTrace, setShowSidebarFileList, setSidebarFileList, setKonwledgeTraceState, setFilePreviewState, setQuoteProductList, setQuoteTeachModelList, setShowMicWarning, setBussinessParams, setInitMsg, setAutoLoadConversation };
|
|
260
266
|
var reducer = gimiMenuSlice.reducer;
|
|
261
267
|
export default reducer;
|