@myun/gimi-chat 0.2.0 → 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/hooks/useCommonChatAPI.d.ts +1 -1
- package/dist/hooks/useCommonChatAPI.js +166 -118
- 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,7 +61,6 @@ 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);
|
|
@@ -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,7 +860,7 @@ 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,
|
|
@@ -850,7 +890,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
850
890
|
if (isSystemAuto) {
|
|
851
891
|
params.isSystemAuto = 1;
|
|
852
892
|
}
|
|
853
|
-
|
|
893
|
+
_context13.next = 20;
|
|
854
894
|
return fetch("https://".concat(baseUrlRef.current, "/mbot/web/agent-message"), {
|
|
855
895
|
method: 'POST',
|
|
856
896
|
headers: {
|
|
@@ -861,15 +901,15 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
861
901
|
body: JSON.stringify(params)
|
|
862
902
|
});
|
|
863
903
|
case 20:
|
|
864
|
-
_response =
|
|
904
|
+
_response = _context13.sent;
|
|
865
905
|
if (!_response.ok) {
|
|
866
|
-
|
|
906
|
+
_context13.next = 27;
|
|
867
907
|
break;
|
|
868
908
|
}
|
|
869
|
-
|
|
909
|
+
_context13.next = 24;
|
|
870
910
|
return _response.json();
|
|
871
911
|
case 24:
|
|
872
|
-
responseMsg =
|
|
912
|
+
responseMsg = _context13.sent;
|
|
873
913
|
// 清空发送时的引用
|
|
874
914
|
dispatch(setFileList({
|
|
875
915
|
fileList: []
|
|
@@ -883,7 +923,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
883
923
|
}));
|
|
884
924
|
// }
|
|
885
925
|
// 继续流式处理聊天
|
|
886
|
-
streamChat(result.id, false
|
|
926
|
+
streamChat(result.id, false);
|
|
887
927
|
} else {
|
|
888
928
|
Toast.error(responseMsg.message);
|
|
889
929
|
setMsgLoading(false);
|
|
@@ -894,12 +934,12 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
894
934
|
}
|
|
895
935
|
}
|
|
896
936
|
case 27:
|
|
897
|
-
|
|
937
|
+
_context13.next = 32;
|
|
898
938
|
break;
|
|
899
939
|
case 29:
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (
|
|
940
|
+
_context13.prev = 29;
|
|
941
|
+
_context13.t0 = _context13["catch"](10);
|
|
942
|
+
if (_context13.t0.name === 'AbortError') {
|
|
903
943
|
setMsgLoading(false);
|
|
904
944
|
if (valueRef.current) {
|
|
905
945
|
setStatus(1);
|
|
@@ -917,66 +957,66 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
917
957
|
}
|
|
918
958
|
case 32:
|
|
919
959
|
case "end":
|
|
920
|
-
return
|
|
960
|
+
return _context13.stop();
|
|
921
961
|
}
|
|
922
|
-
},
|
|
962
|
+
}, _callee13, null, [[10, 29]]);
|
|
923
963
|
}));
|
|
924
964
|
return function (_x23) {
|
|
925
|
-
return
|
|
965
|
+
return _ref13.apply(this, arguments);
|
|
926
966
|
};
|
|
927
967
|
}(), [dispatch]);
|
|
928
968
|
var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
|
|
929
|
-
var
|
|
969
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(agentId) {
|
|
930
970
|
var res;
|
|
931
|
-
return _regeneratorRuntime().wrap(function
|
|
932
|
-
while (1) switch (
|
|
971
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
972
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
933
973
|
case 0:
|
|
934
|
-
|
|
935
|
-
|
|
974
|
+
_context14.prev = 0;
|
|
975
|
+
_context14.next = 3;
|
|
936
976
|
return getAgentDetail(agentId);
|
|
937
977
|
case 3:
|
|
938
|
-
res =
|
|
978
|
+
res = _context14.sent;
|
|
939
979
|
if (!(res.status === 0)) {
|
|
940
|
-
|
|
980
|
+
_context14.next = 9;
|
|
941
981
|
break;
|
|
942
982
|
}
|
|
943
983
|
dispatch(setAgentDetail({
|
|
944
984
|
agentDetail: res.result
|
|
945
985
|
}));
|
|
946
|
-
return
|
|
986
|
+
return _context14.abrupt("return", res.result);
|
|
947
987
|
case 9:
|
|
948
988
|
Toast.error(res.message);
|
|
949
|
-
return
|
|
989
|
+
return _context14.abrupt("return", null);
|
|
950
990
|
case 11:
|
|
951
|
-
|
|
991
|
+
_context14.next = 17;
|
|
952
992
|
break;
|
|
953
993
|
case 13:
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
console.log('error',
|
|
957
|
-
return
|
|
994
|
+
_context14.prev = 13;
|
|
995
|
+
_context14.t0 = _context14["catch"](0);
|
|
996
|
+
console.log('error', _context14.t0);
|
|
997
|
+
return _context14.abrupt("return", null);
|
|
958
998
|
case 17:
|
|
959
999
|
case "end":
|
|
960
|
-
return
|
|
1000
|
+
return _context14.stop();
|
|
961
1001
|
}
|
|
962
|
-
},
|
|
1002
|
+
}, _callee14, null, [[0, 13]]);
|
|
963
1003
|
}));
|
|
964
1004
|
return function (_x24) {
|
|
965
|
-
return
|
|
1005
|
+
return _ref14.apply(this, arguments);
|
|
966
1006
|
};
|
|
967
1007
|
}(), []);
|
|
968
1008
|
var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
|
|
969
|
-
var
|
|
1009
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(value) {
|
|
970
1010
|
var _agentObjRef$current3, _bussinessParamsRef$c2;
|
|
971
1011
|
var currentBussinessParams, params, res;
|
|
972
|
-
return _regeneratorRuntime().wrap(function
|
|
973
|
-
while (1) switch (
|
|
1012
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1013
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
974
1014
|
case 0:
|
|
975
1015
|
if ((_agentObjRef$current3 = agentObjRef.current) !== null && _agentObjRef$current3 !== void 0 && _agentObjRef$current3.agentId) {
|
|
976
|
-
|
|
1016
|
+
_context15.next = 2;
|
|
977
1017
|
break;
|
|
978
1018
|
}
|
|
979
|
-
return
|
|
1019
|
+
return _context15.abrupt("return", Toast.error('请先关联智能体'));
|
|
980
1020
|
case 2:
|
|
981
1021
|
currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c2 = bussinessParamsRef.current) === null || _bussinessParamsRef$c2 === void 0 ? void 0 : _bussinessParamsRef$c2.bussinessParams) || {});
|
|
982
1022
|
params = _objectSpread({
|
|
@@ -984,14 +1024,16 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
984
1024
|
conversationType: agentObjRef.current.conversationType,
|
|
985
1025
|
botId: agentObjRef.current.botId,
|
|
986
1026
|
preview: platform === 'preview' ? 1 : 0
|
|
987
|
-
}, currentBussinessParams);
|
|
988
|
-
|
|
989
|
-
|
|
1027
|
+
}, currentBussinessParams); // 手动创建会话,不自动加载历史消息
|
|
1028
|
+
dispatch(setAutoLoadConversation({
|
|
1029
|
+
autoLoadConversation: false
|
|
1030
|
+
}));
|
|
1031
|
+
_context15.prev = 5;
|
|
990
1032
|
setMsgLoading(true);
|
|
991
|
-
|
|
1033
|
+
_context15.next = 9;
|
|
992
1034
|
return createRoomId(params);
|
|
993
1035
|
case 9:
|
|
994
|
-
res =
|
|
1036
|
+
res = _context15.sent;
|
|
995
1037
|
if (res.status === 0) {
|
|
996
1038
|
dispatch(setConversationId({
|
|
997
1039
|
conversationId: res.result
|
|
@@ -1000,25 +1042,30 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1000
1042
|
getHeaderValue(res.result);
|
|
1001
1043
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
1002
1044
|
handleSend(value, agentObjRef.current, false, res.result);
|
|
1045
|
+
setTimeout(function () {
|
|
1046
|
+
dispatch(setAutoLoadConversation({
|
|
1047
|
+
autoLoadConversation: true
|
|
1048
|
+
}));
|
|
1049
|
+
}, 3000);
|
|
1003
1050
|
} else {
|
|
1004
1051
|
Toast.error(res.message);
|
|
1005
1052
|
}
|
|
1006
|
-
|
|
1053
|
+
_context15.next = 18;
|
|
1007
1054
|
break;
|
|
1008
1055
|
case 13:
|
|
1009
|
-
|
|
1010
|
-
|
|
1056
|
+
_context15.prev = 13;
|
|
1057
|
+
_context15.t0 = _context15["catch"](5);
|
|
1011
1058
|
Toast.error('创建会话失败');
|
|
1012
|
-
console.log('error',
|
|
1059
|
+
console.log('error', _context15.t0);
|
|
1013
1060
|
setMsgLoading(false);
|
|
1014
1061
|
case 18:
|
|
1015
1062
|
case "end":
|
|
1016
|
-
return
|
|
1063
|
+
return _context15.stop();
|
|
1017
1064
|
}
|
|
1018
|
-
},
|
|
1065
|
+
}, _callee15, null, [[5, 13]]);
|
|
1019
1066
|
}));
|
|
1020
1067
|
return function (_x25) {
|
|
1021
|
-
return
|
|
1068
|
+
return _ref15.apply(this, arguments);
|
|
1022
1069
|
};
|
|
1023
1070
|
}(), []);
|
|
1024
1071
|
React.useEffect(function () {
|
|
@@ -1038,10 +1085,11 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1038
1085
|
dispatch(setMessageList({
|
|
1039
1086
|
messageList: []
|
|
1040
1087
|
}));
|
|
1088
|
+
setHeaderValue('');
|
|
1041
1089
|
}
|
|
1042
1090
|
}, [resetKey]);
|
|
1043
1091
|
var handleSend = React.useCallback( /*#__PURE__*/function () {
|
|
1044
|
-
var
|
|
1092
|
+
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(val) {
|
|
1045
1093
|
var agent,
|
|
1046
1094
|
isSystemAuto,
|
|
1047
1095
|
conversationId,
|
|
@@ -1053,41 +1101,41 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1053
1101
|
_prevChatList,
|
|
1054
1102
|
lastItem,
|
|
1055
1103
|
newChatList,
|
|
1056
|
-
|
|
1057
|
-
return _regeneratorRuntime().wrap(function
|
|
1058
|
-
while (1) switch (
|
|
1104
|
+
_args16 = arguments;
|
|
1105
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1106
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1059
1107
|
case 0:
|
|
1060
|
-
agent =
|
|
1061
|
-
isSystemAuto =
|
|
1062
|
-
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;
|
|
1063
1111
|
value = val.trim();
|
|
1064
1112
|
if (!(!value && !isSystemAuto)) {
|
|
1065
|
-
|
|
1113
|
+
_context16.next = 6;
|
|
1066
1114
|
break;
|
|
1067
1115
|
}
|
|
1068
|
-
return
|
|
1116
|
+
return _context16.abrupt("return");
|
|
1069
1117
|
case 6:
|
|
1070
1118
|
if (navigator.onLine) {
|
|
1071
|
-
|
|
1119
|
+
_context16.next = 9;
|
|
1072
1120
|
break;
|
|
1073
1121
|
}
|
|
1074
1122
|
Toast.error('无法连接到网络');
|
|
1075
|
-
return
|
|
1123
|
+
return _context16.abrupt("return");
|
|
1076
1124
|
case 9:
|
|
1077
1125
|
if (!(status === 2 || isMsgRecievingRef.current)) {
|
|
1078
|
-
|
|
1126
|
+
_context16.next = 12;
|
|
1079
1127
|
break;
|
|
1080
1128
|
}
|
|
1081
1129
|
Toast.error('AI正在输出中,请稍后');
|
|
1082
|
-
return
|
|
1130
|
+
return _context16.abrupt("return");
|
|
1083
1131
|
case 12:
|
|
1084
1132
|
fileValidationMsg = fileValidation(fileListRef.current);
|
|
1085
1133
|
if (!fileValidationMsg) {
|
|
1086
|
-
|
|
1134
|
+
_context16.next = 16;
|
|
1087
1135
|
break;
|
|
1088
1136
|
}
|
|
1089
1137
|
Toast.error(fileValidationMsg);
|
|
1090
|
-
return
|
|
1138
|
+
return _context16.abrupt("return");
|
|
1091
1139
|
case 16:
|
|
1092
1140
|
if (isPlaying) {
|
|
1093
1141
|
// 点击发送按钮时,先停止播放
|
|
@@ -1122,12 +1170,12 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1122
1170
|
}
|
|
1123
1171
|
case 23:
|
|
1124
1172
|
case "end":
|
|
1125
|
-
return
|
|
1173
|
+
return _context16.stop();
|
|
1126
1174
|
}
|
|
1127
|
-
},
|
|
1175
|
+
}, _callee16);
|
|
1128
1176
|
}));
|
|
1129
1177
|
return function (_x26) {
|
|
1130
|
-
return
|
|
1178
|
+
return _ref16.apply(this, arguments);
|
|
1131
1179
|
};
|
|
1132
1180
|
}(), [dispatch, startChat]);
|
|
1133
1181
|
var handleSendFile = React.useCallback(function (messageList) {
|
|
@@ -1165,10 +1213,10 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1165
1213
|
}));
|
|
1166
1214
|
// 当有文件内容时处理请求
|
|
1167
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') {
|
|
1168
|
-
var _reverse$
|
|
1169
|
-
var moduleInfo = (_reverse$
|
|
1216
|
+
var _reverse$find2, _messageListRef$curre;
|
|
1217
|
+
var moduleInfo = (_reverse$find2 = _toConsumableArray(messageList).reverse().find(function (v) {
|
|
1170
1218
|
return v.moduleType === 'ask';
|
|
1171
|
-
})) === null || _reverse$
|
|
1219
|
+
})) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.moduleInfo;
|
|
1172
1220
|
var _inputModel = _defineProperty({}, "".concat(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.id, ".input"), '');
|
|
1173
1221
|
inputModelRef.current = _inputModel;
|
|
1174
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;
|