@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.
@@ -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 _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(chatList) {
717
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(chatList) {
681
718
  var lastMessage, newMessageList, _agentObjRef$current, lastUserRequestMessage;
682
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
683
- while (1) switch (_context10.prev = _context10.next) {
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
- _context10.next = 8;
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
- _context10.next = 8;
747
+ _context11.next = 8;
711
748
  break;
712
749
  }
713
- _context10.next = 8;
750
+ _context11.next = 8;
714
751
  return rewriteRecommendListFormHistory(chatList, "".concat(lastUserRequestMessage.chatId));
715
752
  case 8:
716
753
  case "end":
717
- return _context10.stop();
754
+ return _context11.stop();
718
755
  }
719
- }, _callee10);
756
+ }, _callee11);
720
757
  }));
721
758
  return function (_x21) {
722
- return _ref10.apply(this, arguments);
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 _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(conversationId) {
778
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(conversationId) {
742
779
  var res, _res$result3;
743
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
744
- while (1) switch (_context11.prev = _context11.next) {
780
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
781
+ while (1) switch (_context12.prev = _context12.next) {
745
782
  case 0:
746
783
  if (conversationId) {
747
- _context11.next = 2;
784
+ _context12.next = 2;
748
785
  break;
749
786
  }
750
- return _context11.abrupt("return");
787
+ return _context12.abrupt("return");
751
788
  case 2:
752
- _context11.prev = 2;
753
- _context11.next = 5;
789
+ _context12.prev = 2;
790
+ _context12.next = 5;
754
791
  return getMessageTitle("".concat(conversationId));
755
792
  case 5:
756
- res = _context11.sent;
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
- _context11.next = 12;
797
+ _context12.next = 12;
761
798
  break;
762
799
  case 9:
763
- _context11.prev = 9;
764
- _context11.t0 = _context11["catch"](2);
800
+ _context12.prev = 9;
801
+ _context12.t0 = _context12["catch"](2);
765
802
  Toast.error('网络异常');
766
803
  case 12:
767
804
  case "end":
768
- return _context11.stop();
805
+ return _context12.stop();
769
806
  }
770
- }, _callee11, null, [[2, 9]]);
807
+ }, _callee12, null, [[2, 9]]);
771
808
  }));
772
809
  return function getHeaderValue(_x22) {
773
- return _ref11.apply(this, arguments);
810
+ return _ref12.apply(this, arguments);
774
811
  };
775
812
  }();
776
813
  React.useEffect(function () {
777
- if (conversationId && !isNewConversationRef.current) {
778
- getContentMessageList();
779
- getHeaderValue(conversationId);
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 _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(messageList) {
786
- var _reverse$find2, _bussinessParamsRef$c;
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
- _args12 = arguments;
803
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
804
- while (1) switch (_context12.prev = _context12.next) {
842
+ _args13 = arguments;
843
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
844
+ while (1) switch (_context13.prev = _context13.next) {
805
845
  case 0:
806
- isSystemAuto = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
807
- conversationId = _args12.length > 2 ? _args12[2] : undefined;
808
- isAskFileSend = _args12.length > 3 ? _args12[3] : undefined;
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$find2 = _toConsumableArray(messageList).reverse().find(function (item) {
850
+ val = isAskFileSend ? '' : (_reverse$find = _toConsumableArray(messageList).reverse().find(function (item) {
811
851
  return item.role === 0;
812
- })) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.content;
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
- _context12.prev = 10;
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
- _context12.next = 20;
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 = _context12.sent;
904
+ _response = _context13.sent;
865
905
  if (!_response.ok) {
866
- _context12.next = 27;
906
+ _context13.next = 27;
867
907
  break;
868
908
  }
869
- _context12.next = 24;
909
+ _context13.next = 24;
870
910
  return _response.json();
871
911
  case 24:
872
- responseMsg = _context12.sent;
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, isSystemAuto);
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
- _context12.next = 32;
937
+ _context13.next = 32;
898
938
  break;
899
939
  case 29:
900
- _context12.prev = 29;
901
- _context12.t0 = _context12["catch"](10);
902
- if (_context12.t0.name === 'AbortError') {
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 _context12.stop();
960
+ return _context13.stop();
921
961
  }
922
- }, _callee12, null, [[10, 29]]);
962
+ }, _callee13, null, [[10, 29]]);
923
963
  }));
924
964
  return function (_x23) {
925
- return _ref12.apply(this, arguments);
965
+ return _ref13.apply(this, arguments);
926
966
  };
927
967
  }(), [dispatch]);
928
968
  var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
929
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(agentId) {
969
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(agentId) {
930
970
  var res;
931
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
932
- while (1) switch (_context13.prev = _context13.next) {
971
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
972
+ while (1) switch (_context14.prev = _context14.next) {
933
973
  case 0:
934
- _context13.prev = 0;
935
- _context13.next = 3;
974
+ _context14.prev = 0;
975
+ _context14.next = 3;
936
976
  return getAgentDetail(agentId);
937
977
  case 3:
938
- res = _context13.sent;
978
+ res = _context14.sent;
939
979
  if (!(res.status === 0)) {
940
- _context13.next = 9;
980
+ _context14.next = 9;
941
981
  break;
942
982
  }
943
983
  dispatch(setAgentDetail({
944
984
  agentDetail: res.result
945
985
  }));
946
- return _context13.abrupt("return", res.result);
986
+ return _context14.abrupt("return", res.result);
947
987
  case 9:
948
988
  Toast.error(res.message);
949
- return _context13.abrupt("return", null);
989
+ return _context14.abrupt("return", null);
950
990
  case 11:
951
- _context13.next = 17;
991
+ _context14.next = 17;
952
992
  break;
953
993
  case 13:
954
- _context13.prev = 13;
955
- _context13.t0 = _context13["catch"](0);
956
- console.log('error', _context13.t0);
957
- return _context13.abrupt("return", null);
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 _context13.stop();
1000
+ return _context14.stop();
961
1001
  }
962
- }, _callee13, null, [[0, 13]]);
1002
+ }, _callee14, null, [[0, 13]]);
963
1003
  }));
964
1004
  return function (_x24) {
965
- return _ref13.apply(this, arguments);
1005
+ return _ref14.apply(this, arguments);
966
1006
  };
967
1007
  }(), []);
968
1008
  var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
969
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(value) {
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 _callee14$(_context14) {
973
- while (1) switch (_context14.prev = _context14.next) {
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
- _context14.next = 2;
1016
+ _context15.next = 2;
977
1017
  break;
978
1018
  }
979
- return _context14.abrupt("return", Toast.error('请先关联智能体'));
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
- isNewConversationRef.current = true;
989
- _context14.prev = 5;
1027
+ }, currentBussinessParams); // 手动创建会话,不自动加载历史消息
1028
+ dispatch(setAutoLoadConversation({
1029
+ autoLoadConversation: false
1030
+ }));
1031
+ _context15.prev = 5;
990
1032
  setMsgLoading(true);
991
- _context14.next = 9;
1033
+ _context15.next = 9;
992
1034
  return createRoomId(params);
993
1035
  case 9:
994
- res = _context14.sent;
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
- _context14.next = 18;
1053
+ _context15.next = 18;
1007
1054
  break;
1008
1055
  case 13:
1009
- _context14.prev = 13;
1010
- _context14.t0 = _context14["catch"](5);
1056
+ _context15.prev = 13;
1057
+ _context15.t0 = _context15["catch"](5);
1011
1058
  Toast.error('创建会话失败');
1012
- console.log('error', _context14.t0);
1059
+ console.log('error', _context15.t0);
1013
1060
  setMsgLoading(false);
1014
1061
  case 18:
1015
1062
  case "end":
1016
- return _context14.stop();
1063
+ return _context15.stop();
1017
1064
  }
1018
- }, _callee14, null, [[5, 13]]);
1065
+ }, _callee15, null, [[5, 13]]);
1019
1066
  }));
1020
1067
  return function (_x25) {
1021
- return _ref14.apply(this, arguments);
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 _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(val) {
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
- _args15 = arguments;
1057
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1058
- while (1) switch (_context15.prev = _context15.next) {
1104
+ _args16 = arguments;
1105
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1106
+ while (1) switch (_context16.prev = _context16.next) {
1059
1107
  case 0:
1060
- agent = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : agentObjRef.current;
1061
- isSystemAuto = _args15.length > 2 && _args15[2] !== undefined ? _args15[2] : false;
1062
- conversationId = _args15.length > 3 ? _args15[3] : undefined;
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
- _context15.next = 6;
1113
+ _context16.next = 6;
1066
1114
  break;
1067
1115
  }
1068
- return _context15.abrupt("return");
1116
+ return _context16.abrupt("return");
1069
1117
  case 6:
1070
1118
  if (navigator.onLine) {
1071
- _context15.next = 9;
1119
+ _context16.next = 9;
1072
1120
  break;
1073
1121
  }
1074
1122
  Toast.error('无法连接到网络');
1075
- return _context15.abrupt("return");
1123
+ return _context16.abrupt("return");
1076
1124
  case 9:
1077
1125
  if (!(status === 2 || isMsgRecievingRef.current)) {
1078
- _context15.next = 12;
1126
+ _context16.next = 12;
1079
1127
  break;
1080
1128
  }
1081
1129
  Toast.error('AI正在输出中,请稍后');
1082
- return _context15.abrupt("return");
1130
+ return _context16.abrupt("return");
1083
1131
  case 12:
1084
1132
  fileValidationMsg = fileValidation(fileListRef.current);
1085
1133
  if (!fileValidationMsg) {
1086
- _context15.next = 16;
1134
+ _context16.next = 16;
1087
1135
  break;
1088
1136
  }
1089
1137
  Toast.error(fileValidationMsg);
1090
- return _context15.abrupt("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 _context15.stop();
1173
+ return _context16.stop();
1126
1174
  }
1127
- }, _callee15);
1175
+ }, _callee16);
1128
1176
  }));
1129
1177
  return function (_x26) {
1130
- return _ref15.apply(this, arguments);
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$find3, _messageListRef$curre;
1169
- var moduleInfo = (_reverse$find3 = _toConsumableArray(messageList).reverse().find(function (v) {
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$find3 === void 0 ? void 0 : _reverse$find3.moduleInfo;
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
- export { setAgentDetail, setConversationId, setIsMsgRecieving, setBaseUrl, setToken, setPlatform, updateState, setMessageList, setFileList, setCurrentMessageId, updateParams, setShowKonwledgeTrace, setShowSidebarFileList, setSidebarFileList, setKonwledgeTraceState, setFilePreviewState, setQuoteProductList, setQuoteTeachModelList, setShowMicWarning, setBussinessParams };
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;