@myun/gimi-chat 0.2.0 → 0.2.2

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, updateState } 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";
@@ -32,14 +32,20 @@ import { useChatRecommend } from "./useChatRecommend";
32
32
  import { set, cloneDeep } from 'lodash';
33
33
  import { FileStatus } from "../interfaces/fileInterface";
34
34
  import useChatHistory from "./useChatHistory";
35
- var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, reloadAgentKey, resetKey, interruptKey, onConversationCreated, onSendEnd) {
35
+ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, reloadAgentKey, resetKey, interruptKey, chatInputConfig) {
36
36
  var _useApi = useApi(),
37
37
  getMessageTitle = _useApi.getMessageTitle,
38
38
  stopStreamOut = _useApi.stopStreamOut,
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;
44
+ var _ref = chatInputConfig || {},
45
+ onFirstSendSuccess = _ref.onFirstSendSuccess,
46
+ onSendSuccess = _ref.onSendSuccess,
47
+ onSendEnd = _ref.onSendEnd,
48
+ onConversationCreated = _ref.onConversationCreated;
43
49
  var dispatch = useAppDispatch();
44
50
  var _React$useState = React.useState(''),
45
51
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -60,7 +66,6 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
60
66
  setStatus = _React$useState8[1]; // 0 没输入内容 1 正在输入 2 ai正在回复 3 ai即将回复
61
67
  var valueRef = React.useRef(''); // 输入框的值
62
68
  var vipLevelRef = React.useRef(null);
63
- var isNewConversationRef = React.useRef(false);
64
69
  var step = React.useRef(0); // 接口请求step
65
70
  var controllerRef = React.useRef(null); // 发起对话接口controller
66
71
  var inputModelRef = React.useRef(null);
@@ -115,6 +120,9 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
115
120
  var token = useAppSelector(function (state) {
116
121
  return state.gimiMenu.token;
117
122
  });
123
+ var autoLoadConversation = useAppSelector(function (state) {
124
+ return state.gimiMenu.autoLoadConversation;
125
+ });
118
126
 
119
127
  // 使用 ref 存储最新的值,避免闭包陷阱
120
128
  var messageListRef = useRef(messageList || []);
@@ -140,7 +148,6 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
140
148
  agentObjRef.current = agentObj;
141
149
  isMsgRecievingRef.current = isMsgRecieving;
142
150
  fileListRef.current = fileList;
143
- conversationIdRef.current = conversationId;
144
151
  bussinessParamsRef.current = bussinessParams;
145
152
  quoteProductListRef.current = quoteProductList;
146
153
  quoteTeachModelListRef.current = quoteTeachModelList;
@@ -155,29 +162,28 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
155
162
  });
156
163
 
157
164
  // 重置与当前回话关联的Redux状态
158
- // const clearQuotesFromRedux = () => {
159
- // dispatch(updateState({
160
- // fileList: [],
161
- // showKonwledgeTrace: false,
162
- // showSidebarFileList: false,
163
- // filePreviewState: {
164
- // show: false,
165
- // url: '',
166
- // filename: '',
167
- // },
168
- // // quoteProductList: [],
169
- // // quoteTeachModelList: [],
170
- // konwledgeTraceState: {
171
- // type: 'video',
172
- // resources: [],
173
- // messageId: null,
174
- // },
175
- // }))
176
- // };
177
-
165
+ var clearQuotesFromRedux = React.useCallback(function () {
166
+ dispatch(updateState({
167
+ fileList: [],
168
+ showKonwledgeTrace: false,
169
+ showSidebarFileList: false,
170
+ filePreviewState: {
171
+ show: false,
172
+ url: '',
173
+ filename: ''
174
+ },
175
+ // quoteProductList: [],
176
+ // quoteTeachModelList: [],
177
+ konwledgeTraceState: {
178
+ type: 'video',
179
+ resources: [],
180
+ messageId: null
181
+ }
182
+ }));
183
+ }, [dispatch]);
178
184
  var startAICorrection = React.useCallback( /*#__PURE__*/function () {
179
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(answerId, questionId) {
180
- var res, _res$result, _res$result2, _message, aiChat;
185
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(answerId, questionId) {
186
+ var res, _res$result, _res$result2, message, aiChat;
181
187
  return _regeneratorRuntime().wrap(function _callee$(_context) {
182
188
  while (1) switch (_context.prev = _context.next) {
183
189
  case 0:
@@ -189,10 +195,10 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
189
195
  case 2:
190
196
  res = _context.sent;
191
197
  if (res.status === 0) {
192
- _message = createUserChat((_res$result = res.result) === null || _res$result === void 0 ? void 0 : _res$result.title, '');
198
+ message = createUserChat((_res$result = res.result) === null || _res$result === void 0 ? void 0 : _res$result.title, '');
193
199
  aiChat = createAiChat({});
194
200
  dispatch(setMessageList({
195
- messageList: [_message, aiChat]
201
+ messageList: [message, aiChat]
196
202
  }));
197
203
  dispatch(setAgentDetail({
198
204
  agentDetail: {
@@ -211,17 +217,9 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
211
217
  }, _callee);
212
218
  }));
213
219
  return function (_x, _x2) {
214
- return _ref.apply(this, arguments);
220
+ return _ref2.apply(this, arguments);
215
221
  };
216
222
  }(), [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
223
  var deleteConversation = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
226
224
  var res;
227
225
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -257,7 +255,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
257
255
 
258
256
  // 打断ai输出
259
257
  var handleInterrupt = /*#__PURE__*/function () {
260
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
258
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
261
259
  var uid, messageList, _item, newMessageList, _newMessageList;
262
260
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
263
261
  while (1) switch (_context3.prev = _context3.next) {
@@ -340,7 +338,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
340
338
  }, _callee3);
341
339
  }));
342
340
  return function handleInterrupt() {
343
- return _ref3.apply(this, arguments);
341
+ return _ref4.apply(this, arguments);
344
342
  };
345
343
  }();
346
344
  var handleMCPToolsStreamRs = React.useCallback(function (dataObj) {
@@ -362,7 +360,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
362
360
 
363
361
  // 发起会话 - 使用新的hook简化逻辑
364
362
  var fetchAICorrectionChatStream = React.useCallback( /*#__PURE__*/function () {
365
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
363
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
366
364
  var fullResponse, reasoningResponse;
367
365
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
368
366
  while (1) switch (_context4.prev = _context4.next) {
@@ -411,13 +409,13 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
411
409
  }, _callee4);
412
410
  }));
413
411
  return function (_x3, _x4, _x5, _x6) {
414
- return _ref4.apply(this, arguments);
412
+ return _ref5.apply(this, arguments);
415
413
  };
416
414
  }(), [fetchChatStreamHook, setIgnoreOnMessage, dispatch, removeLastEventId, handleMCPToolsStreamRs]);
417
415
 
418
416
  // 发起会话 - 使用新的hook简化逻辑
419
417
  var fetchChatStream = React.useCallback( /*#__PURE__*/function () {
420
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id, reSumeInfo, _onSseOpen2, _onDataReceived2, _onComplete2, _onErrorComplete2) {
418
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id, reSumeInfo, _onSseOpen2, _onDataReceived2, _onComplete2, _onErrorComplete2) {
421
419
  var fullResponse, reasoningResponse;
422
420
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
423
421
  while (1) switch (_context5.prev = _context5.next) {
@@ -467,7 +465,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
467
465
  }, _callee5);
468
466
  }));
469
467
  return function (_x7, _x8, _x9, _x10, _x11, _x12) {
470
- return _ref5.apply(this, arguments);
468
+ return _ref6.apply(this, arguments);
471
469
  };
472
470
  }(), [fetchChatStreamHook, setIgnoreOnMessage, dispatch, removeLastEventId, handleMCPToolsStreamRs]);
473
471
 
@@ -498,7 +496,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
498
496
  messageList: newMessageList
499
497
  }));
500
498
  }, /*#__PURE__*/function () {
501
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(Response, type, reasoningResponse) {
499
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(Response, type, reasoningResponse) {
502
500
  var currentMessageList, newMessageList;
503
501
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
504
502
  while (1) switch (_context6.prev = _context6.next) {
@@ -524,7 +522,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
524
522
  }, _callee6);
525
523
  }));
526
524
  return function (_x13, _x14, _x15) {
527
- return _ref7.apply(this, arguments);
525
+ return _ref8.apply(this, arguments);
528
526
  };
529
527
  }(), function () {
530
528
  setIgnoreOnMessage(true);
@@ -556,7 +554,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
556
554
 
557
555
  // 流式输出开始
558
556
  var streamChat = React.useCallback( /*#__PURE__*/function () {
559
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(lastId, again) {
557
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(lastId, again) {
560
558
  var reSumeInfo,
561
559
  agentInfo,
562
560
  _args9 = arguments;
@@ -598,7 +596,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
598
596
  messageList: newMessageList
599
597
  }));
600
598
  }, /*#__PURE__*/function () {
601
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(Response, type, reasoningResponse) {
599
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(Response, type, reasoningResponse) {
602
600
  var currentMessageList, newMessageList, agentDetail;
603
601
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
604
602
  while (1) switch (_context8.prev = _context8.next) {
@@ -640,7 +638,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
640
638
  }, _callee8);
641
639
  }));
642
640
  return function (_x18, _x19, _x20) {
643
- return _ref9.apply(this, arguments);
641
+ return _ref10.apply(this, arguments);
644
642
  };
645
643
  }(), function () {
646
644
  setIgnoreOnMessage(true);
@@ -671,16 +669,59 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
671
669
  }, _callee9);
672
670
  }));
673
671
  return function (_x16, _x17) {
674
- return _ref8.apply(this, arguments);
672
+ return _ref9.apply(this, arguments);
675
673
  };
676
674
  }(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList]);
675
+ var regenerate = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
676
+ var res, retryId, newMessageList;
677
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
678
+ while (1) switch (_context10.prev = _context10.next) {
679
+ case 0:
680
+ _context10.prev = 0;
681
+ _context10.next = 3;
682
+ return checkRetry({
683
+ conversationId: conversationIdRef.current
684
+ });
685
+ case 3:
686
+ res = _context10.sent;
687
+ if (res.status === 0 && res.result) {
688
+ retryId = res.result;
689
+ setMsgLoading(true);
690
+ newMessageList = [].concat(_toConsumableArray(messageListRef.current.slice(0, -1)), [_objectSpread(_objectSpread({}, messageListRef.current[messageListRef.current.length - 1]), {}, {
691
+ content: '',
692
+ reasoningResponse: '',
693
+ relatedResourceList: [],
694
+ loading: false,
695
+ reasoningLoading: false,
696
+ stop: 0
697
+ })]);
698
+ dispatch(setMessageList({
699
+ messageList: newMessageList
700
+ }));
701
+ // 继续流式处理聊天
702
+ streamChat(retryId, false);
703
+ } else {
704
+ Toast.error(res.message || '不可进行重试');
705
+ }
706
+ _context10.next = 10;
707
+ break;
708
+ case 7:
709
+ _context10.prev = 7;
710
+ _context10.t0 = _context10["catch"](0);
711
+ Toast.error('重试失败');
712
+ case 10:
713
+ case "end":
714
+ return _context10.stop();
715
+ }
716
+ }, _callee10, null, [[0, 7]]);
717
+ })), [streamChat]);
677
718
 
678
719
  // 单独的断点续传
679
720
  var checkUnfinishedMessage = React.useCallback( /*#__PURE__*/function () {
680
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(chatList) {
721
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(chatList) {
681
722
  var lastMessage, newMessageList, _agentObjRef$current, lastUserRequestMessage;
682
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
683
- while (1) switch (_context10.prev = _context10.next) {
723
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
724
+ while (1) switch (_context11.prev = _context11.next) {
684
725
  case 0:
685
726
  lastMessage = chatList[chatList.length - 1]; // 检查最后一条消息是否为未完成的AI消息
686
727
  if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 0 && lastMessage.chatId) {
@@ -698,7 +739,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
698
739
  }, agentObjRef.current); // 调用续传接口
699
740
  }
700
741
  if (!((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 1)) {
701
- _context10.next = 8;
742
+ _context11.next = 8;
702
743
  break;
703
744
  }
704
745
  removeLastEventId("".concat(lastMessage.chatId));
@@ -707,19 +748,19 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
707
748
  return item.role === 0;
708
749
  }).slice(-1)[0];
709
750
  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;
751
+ _context11.next = 8;
711
752
  break;
712
753
  }
713
- _context10.next = 8;
754
+ _context11.next = 8;
714
755
  return rewriteRecommendListFormHistory(chatList, "".concat(lastUserRequestMessage.chatId));
715
756
  case 8:
716
757
  case "end":
717
- return _context10.stop();
758
+ return _context11.stop();
718
759
  }
719
- }, _callee10);
760
+ }, _callee11);
720
761
  }));
721
762
  return function (_x21) {
722
- return _ref10.apply(this, arguments);
763
+ return _ref12.apply(this, arguments);
723
764
  };
724
765
  }(), [dispatch, streamChat, removeLastEventId, rewriteRecommendListFormHistory]);
725
766
  var _useChatHistory = useChatHistory(checkUnfinishedMessage, scrollBottomForce, containerRef),
@@ -738,52 +779,62 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
738
779
 
739
780
  // 获取对话标题
740
781
  var getHeaderValue = /*#__PURE__*/function () {
741
- var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(conversationId) {
782
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(conversationId) {
742
783
  var res, _res$result3;
743
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
744
- while (1) switch (_context11.prev = _context11.next) {
784
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
785
+ while (1) switch (_context12.prev = _context12.next) {
745
786
  case 0:
746
787
  if (conversationId) {
747
- _context11.next = 2;
788
+ _context12.next = 2;
748
789
  break;
749
790
  }
750
- return _context11.abrupt("return");
791
+ return _context12.abrupt("return");
751
792
  case 2:
752
- _context11.prev = 2;
753
- _context11.next = 5;
793
+ _context12.prev = 2;
794
+ _context12.next = 5;
754
795
  return getMessageTitle("".concat(conversationId));
755
796
  case 5:
756
- res = _context11.sent;
797
+ res = _context12.sent;
757
798
  if ((res === null || res === void 0 ? void 0 : res.status) === 0) {
758
799
  setHeaderValue(res === null || res === void 0 || (_res$result3 = res.result) === null || _res$result3 === void 0 ? void 0 : _res$result3.title);
759
800
  }
760
- _context11.next = 12;
801
+ _context12.next = 12;
761
802
  break;
762
803
  case 9:
763
- _context11.prev = 9;
764
- _context11.t0 = _context11["catch"](2);
804
+ _context12.prev = 9;
805
+ _context12.t0 = _context12["catch"](2);
765
806
  Toast.error('网络异常');
766
807
  case 12:
767
808
  case "end":
768
- return _context11.stop();
809
+ return _context12.stop();
769
810
  }
770
- }, _callee11, null, [[2, 9]]);
811
+ }, _callee12, null, [[2, 9]]);
771
812
  }));
772
813
  return function getHeaderValue(_x22) {
773
- return _ref11.apply(this, arguments);
814
+ return _ref13.apply(this, arguments);
774
815
  };
775
816
  }();
776
817
  React.useEffect(function () {
777
- if (conversationId && !isNewConversationRef.current) {
778
- getContentMessageList();
779
- getHeaderValue(conversationId);
818
+ if (conversationId && conversationIdRef.current !== conversationId) {
819
+ conversationIdRef.current = conversationId;
820
+ if (controllerRef.current) {
821
+ controllerRef.current.abort();
822
+ }
823
+ if (streamEsAbortRef.current) {
824
+ streamEsAbortRef.current.abort();
825
+ }
826
+ clearQuotesFromRedux();
827
+ if (autoLoadConversation) {
828
+ getHeaderValue(conversationId);
829
+ getContentMessageList();
830
+ }
780
831
  }
781
- }, [conversationId]);
832
+ }, [conversationId, autoLoadConversation]);
782
833
 
783
834
  // 开始会话
784
835
  var startChat = React.useCallback( /*#__PURE__*/function () {
785
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(messageList) {
786
- var _reverse$find2, _bussinessParamsRef$c;
836
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(messageList) {
837
+ var _reverse$find;
787
838
  var isSystemAuto,
788
839
  conversationId,
789
840
  isAskFileSend,
@@ -799,17 +850,17 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
799
850
  responseMsg,
800
851
  result,
801
852
  aiChat,
802
- _args12 = arguments;
803
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
804
- while (1) switch (_context12.prev = _context12.next) {
853
+ _args13 = arguments;
854
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
855
+ while (1) switch (_context13.prev = _context13.next) {
805
856
  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;
857
+ isSystemAuto = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
858
+ conversationId = _args13.length > 2 ? _args13[2] : undefined;
859
+ isAskFileSend = _args13.length > 3 ? _args13[3] : undefined;
809
860
  // 如果是ask卡片的file上传,发送content为''
810
- val = isAskFileSend ? '' : (_reverse$find2 = _toConsumableArray(messageList).reverse().find(function (item) {
861
+ val = isAskFileSend ? '' : (_reverse$find = _toConsumableArray(messageList).reverse().find(function (item) {
811
862
  return item.role === 0;
812
- })) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.content;
863
+ })) === null || _reverse$find === void 0 ? void 0 : _reverse$find.content;
813
864
  if (controllerRef.current) {
814
865
  controllerRef.current.abort();
815
866
  }
@@ -819,8 +870,8 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
819
870
  controllerRef.current = new AbortController();
820
871
  signal = controllerRef.current.signal;
821
872
  step.current = 1;
822
- currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c = bussinessParamsRef.current) === null || _bussinessParamsRef$c === void 0 ? void 0 : _bussinessParamsRef$c.bussinessParams) || {});
823
- _context12.prev = 10;
873
+ currentBussinessParams = _objectSpread({}, bussinessParamsRef.current || {});
874
+ _context13.prev = 10;
824
875
  params = _objectSpread({
825
876
  content: val,
826
877
  conversationId: conversationId || conversationIdRef.current,
@@ -850,7 +901,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
850
901
  if (isSystemAuto) {
851
902
  params.isSystemAuto = 1;
852
903
  }
853
- _context12.next = 20;
904
+ _context13.next = 20;
854
905
  return fetch("https://".concat(baseUrlRef.current, "/mbot/web/agent-message"), {
855
906
  method: 'POST',
856
907
  headers: {
@@ -861,15 +912,19 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
861
912
  body: JSON.stringify(params)
862
913
  });
863
914
  case 20:
864
- _response = _context12.sent;
915
+ _response = _context13.sent;
865
916
  if (!_response.ok) {
866
- _context12.next = 27;
917
+ _context13.next = 29;
867
918
  break;
868
919
  }
869
- _context12.next = 24;
920
+ _context13.next = 24;
870
921
  return _response.json();
871
922
  case 24:
872
- responseMsg = _context12.sent;
923
+ responseMsg = _context13.sent;
924
+ // 执行使用方定义的回调函数
925
+ onFirstSendSuccess === null || onFirstSendSuccess === void 0 || onFirstSendSuccess();
926
+ onSendSuccess === null || onSendSuccess === void 0 || onSendSuccess();
927
+
873
928
  // 清空发送时的引用
874
929
  dispatch(setFileList({
875
930
  fileList: []
@@ -883,7 +938,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
883
938
  }));
884
939
  // }
885
940
  // 继续流式处理聊天
886
- streamChat(result.id, false, isSystemAuto);
941
+ streamChat(result.id, false);
887
942
  } else {
888
943
  Toast.error(responseMsg.message);
889
944
  setMsgLoading(false);
@@ -893,13 +948,13 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
893
948
  setStatus(0);
894
949
  }
895
950
  }
896
- case 27:
897
- _context12.next = 32;
898
- break;
899
951
  case 29:
900
- _context12.prev = 29;
901
- _context12.t0 = _context12["catch"](10);
902
- if (_context12.t0.name === 'AbortError') {
952
+ _context13.next = 34;
953
+ break;
954
+ case 31:
955
+ _context13.prev = 31;
956
+ _context13.t0 = _context13["catch"](10);
957
+ if (_context13.t0.name === 'AbortError') {
903
958
  setMsgLoading(false);
904
959
  if (valueRef.current) {
905
960
  setStatus(1);
@@ -915,83 +970,86 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
915
970
  setStatus(0);
916
971
  }
917
972
  }
918
- case 32:
973
+ case 34:
919
974
  case "end":
920
- return _context12.stop();
975
+ return _context13.stop();
921
976
  }
922
- }, _callee12, null, [[10, 29]]);
977
+ }, _callee13, null, [[10, 31]]);
923
978
  }));
924
979
  return function (_x23) {
925
- return _ref12.apply(this, arguments);
980
+ return _ref14.apply(this, arguments);
926
981
  };
927
982
  }(), [dispatch]);
928
983
  var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
929
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(agentId) {
984
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(agentId) {
930
985
  var res;
931
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
932
- while (1) switch (_context13.prev = _context13.next) {
986
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
987
+ while (1) switch (_context14.prev = _context14.next) {
933
988
  case 0:
934
- _context13.prev = 0;
935
- _context13.next = 3;
989
+ _context14.prev = 0;
990
+ _context14.next = 3;
936
991
  return getAgentDetail(agentId);
937
992
  case 3:
938
- res = _context13.sent;
993
+ res = _context14.sent;
939
994
  if (!(res.status === 0)) {
940
- _context13.next = 9;
995
+ _context14.next = 9;
941
996
  break;
942
997
  }
943
998
  dispatch(setAgentDetail({
944
999
  agentDetail: res.result
945
1000
  }));
946
- return _context13.abrupt("return", res.result);
1001
+ return _context14.abrupt("return", res.result);
947
1002
  case 9:
948
1003
  Toast.error(res.message);
949
- return _context13.abrupt("return", null);
1004
+ return _context14.abrupt("return", null);
950
1005
  case 11:
951
- _context13.next = 17;
1006
+ _context14.next = 17;
952
1007
  break;
953
1008
  case 13:
954
- _context13.prev = 13;
955
- _context13.t0 = _context13["catch"](0);
956
- console.log('error', _context13.t0);
957
- return _context13.abrupt("return", null);
1009
+ _context14.prev = 13;
1010
+ _context14.t0 = _context14["catch"](0);
1011
+ console.log('error', _context14.t0);
1012
+ return _context14.abrupt("return", null);
958
1013
  case 17:
959
1014
  case "end":
960
- return _context13.stop();
1015
+ return _context14.stop();
961
1016
  }
962
- }, _callee13, null, [[0, 13]]);
1017
+ }, _callee14, null, [[0, 13]]);
963
1018
  }));
964
1019
  return function (_x24) {
965
- return _ref13.apply(this, arguments);
1020
+ return _ref15.apply(this, arguments);
966
1021
  };
967
1022
  }(), []);
968
1023
  var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
969
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(value) {
970
- var _agentObjRef$current3, _bussinessParamsRef$c2;
1024
+ var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(value) {
1025
+ var _agentObjRef$current3;
971
1026
  var currentBussinessParams, params, res;
972
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
973
- while (1) switch (_context14.prev = _context14.next) {
1027
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1028
+ while (1) switch (_context15.prev = _context15.next) {
974
1029
  case 0:
975
1030
  if ((_agentObjRef$current3 = agentObjRef.current) !== null && _agentObjRef$current3 !== void 0 && _agentObjRef$current3.agentId) {
976
- _context14.next = 2;
1031
+ _context15.next = 3;
977
1032
  break;
978
1033
  }
979
- return _context14.abrupt("return", Toast.error('请先关联智能体'));
980
- case 2:
981
- currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c2 = bussinessParamsRef.current) === null || _bussinessParamsRef$c2 === void 0 ? void 0 : _bussinessParamsRef$c2.bussinessParams) || {});
1034
+ Toast.error('请先关联智能体');
1035
+ return _context15.abrupt("return");
1036
+ case 3:
1037
+ currentBussinessParams = _objectSpread({}, bussinessParamsRef.current || {});
982
1038
  params = _objectSpread({
983
1039
  content: value,
984
1040
  conversationType: agentObjRef.current.conversationType,
985
1041
  botId: agentObjRef.current.botId,
986
1042
  preview: platform === 'preview' ? 1 : 0
987
- }, currentBussinessParams);
988
- isNewConversationRef.current = true;
989
- _context14.prev = 5;
1043
+ }, currentBussinessParams); // 手动创建会话,不自动加载历史消息
1044
+ dispatch(setAutoLoadConversation({
1045
+ autoLoadConversation: false
1046
+ }));
1047
+ _context15.prev = 6;
990
1048
  setMsgLoading(true);
991
- _context14.next = 9;
1049
+ _context15.next = 10;
992
1050
  return createRoomId(params);
993
- case 9:
994
- res = _context14.sent;
1051
+ case 10:
1052
+ res = _context15.sent;
995
1053
  if (res.status === 0) {
996
1054
  dispatch(setConversationId({
997
1055
  conversationId: res.result
@@ -1000,25 +1058,30 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1000
1058
  getHeaderValue(res.result);
1001
1059
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
1002
1060
  handleSend(value, agentObjRef.current, false, res.result);
1061
+ setTimeout(function () {
1062
+ dispatch(setAutoLoadConversation({
1063
+ autoLoadConversation: true
1064
+ }));
1065
+ }, 3000);
1003
1066
  } else {
1004
1067
  Toast.error(res.message);
1005
1068
  }
1006
- _context14.next = 18;
1069
+ _context15.next = 19;
1007
1070
  break;
1008
- case 13:
1009
- _context14.prev = 13;
1010
- _context14.t0 = _context14["catch"](5);
1071
+ case 14:
1072
+ _context15.prev = 14;
1073
+ _context15.t0 = _context15["catch"](6);
1011
1074
  Toast.error('创建会话失败');
1012
- console.log('error', _context14.t0);
1075
+ console.log('error', _context15.t0);
1013
1076
  setMsgLoading(false);
1014
- case 18:
1077
+ case 19:
1015
1078
  case "end":
1016
- return _context14.stop();
1079
+ return _context15.stop();
1017
1080
  }
1018
- }, _callee14, null, [[5, 13]]);
1081
+ }, _callee15, null, [[6, 14]]);
1019
1082
  }));
1020
1083
  return function (_x25) {
1021
- return _ref14.apply(this, arguments);
1084
+ return _ref16.apply(this, arguments);
1022
1085
  };
1023
1086
  }(), []);
1024
1087
  React.useEffect(function () {
@@ -1038,10 +1101,11 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1038
1101
  dispatch(setMessageList({
1039
1102
  messageList: []
1040
1103
  }));
1104
+ setHeaderValue('');
1041
1105
  }
1042
1106
  }, [resetKey]);
1043
1107
  var handleSend = React.useCallback( /*#__PURE__*/function () {
1044
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(val) {
1108
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(val) {
1045
1109
  var agent,
1046
1110
  isSystemAuto,
1047
1111
  conversationId,
@@ -1053,41 +1117,41 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1053
1117
  _prevChatList,
1054
1118
  lastItem,
1055
1119
  newChatList,
1056
- _args15 = arguments;
1057
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1058
- while (1) switch (_context15.prev = _context15.next) {
1120
+ _args16 = arguments;
1121
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1122
+ while (1) switch (_context16.prev = _context16.next) {
1059
1123
  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;
1124
+ agent = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : agentObjRef.current;
1125
+ isSystemAuto = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : false;
1126
+ conversationId = _args16.length > 3 ? _args16[3] : undefined;
1063
1127
  value = val.trim();
1064
1128
  if (!(!value && !isSystemAuto)) {
1065
- _context15.next = 6;
1129
+ _context16.next = 6;
1066
1130
  break;
1067
1131
  }
1068
- return _context15.abrupt("return");
1132
+ return _context16.abrupt("return");
1069
1133
  case 6:
1070
1134
  if (navigator.onLine) {
1071
- _context15.next = 9;
1135
+ _context16.next = 9;
1072
1136
  break;
1073
1137
  }
1074
1138
  Toast.error('无法连接到网络');
1075
- return _context15.abrupt("return");
1139
+ return _context16.abrupt("return");
1076
1140
  case 9:
1077
1141
  if (!(status === 2 || isMsgRecievingRef.current)) {
1078
- _context15.next = 12;
1142
+ _context16.next = 12;
1079
1143
  break;
1080
1144
  }
1081
1145
  Toast.error('AI正在输出中,请稍后');
1082
- return _context15.abrupt("return");
1146
+ return _context16.abrupt("return");
1083
1147
  case 12:
1084
1148
  fileValidationMsg = fileValidation(fileListRef.current);
1085
1149
  if (!fileValidationMsg) {
1086
- _context15.next = 16;
1150
+ _context16.next = 16;
1087
1151
  break;
1088
1152
  }
1089
1153
  Toast.error(fileValidationMsg);
1090
- return _context15.abrupt("return");
1154
+ return _context16.abrupt("return");
1091
1155
  case 16:
1092
1156
  if (isPlaying) {
1093
1157
  // 点击发送按钮时,先停止播放
@@ -1122,12 +1186,12 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1122
1186
  }
1123
1187
  case 23:
1124
1188
  case "end":
1125
- return _context15.stop();
1189
+ return _context16.stop();
1126
1190
  }
1127
- }, _callee15);
1191
+ }, _callee16);
1128
1192
  }));
1129
1193
  return function (_x26) {
1130
- return _ref15.apply(this, arguments);
1194
+ return _ref17.apply(this, arguments);
1131
1195
  };
1132
1196
  }(), [dispatch, startChat]);
1133
1197
  var handleSendFile = React.useCallback(function (messageList) {
@@ -1165,10 +1229,10 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1165
1229
  }));
1166
1230
  // 当有文件内容时处理请求
1167
1231
  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) {
1232
+ var _reverse$find2, _messageListRef$curre;
1233
+ var moduleInfo = (_reverse$find2 = _toConsumableArray(messageList).reverse().find(function (v) {
1170
1234
  return v.moduleType === 'ask';
1171
- })) === null || _reverse$find3 === void 0 ? void 0 : _reverse$find3.moduleInfo;
1235
+ })) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.moduleInfo;
1172
1236
  var _inputModel = _defineProperty({}, "".concat(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.id, ".input"), '');
1173
1237
  inputModelRef.current = _inputModel;
1174
1238
  if (((_messageListRef$curre = messageListRef.current) === null || _messageListRef$curre === void 0 ? void 0 : _messageListRef$curre.length) > 0) {