@myun/gimi-chat 0.4.7 → 0.5.0

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.
@@ -55,12 +55,6 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
55
55
  var agentObj = useAppSelector(function (state) {
56
56
  return state.gimiMenu.agentObj;
57
57
  });
58
- var storedBaseUrl = useAppSelector(function (state) {
59
- return state.gimiMenu.baseUrl;
60
- });
61
- var storedToken = useAppSelector(function (state) {
62
- return state.gimiMenu.token;
63
- });
64
58
  var chatUI = useChatUI();
65
59
  var _useChatVoice = useChatVoice(),
66
60
  isRecording = _useChatVoice.isRecording,
@@ -83,7 +77,8 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
83
77
  interruptKey: props.interruptKey,
84
78
  chatInputConfig: chatInputConfig,
85
79
  autoSendValue: props.autoSendValue,
86
- initAttachments: props.initAttachments
80
+ initAttachments: props.initAttachments,
81
+ initSendValue: props.initSendValue
87
82
  };
88
83
  }, [containerRef, platform, stopTTSByText, isPlaying, agentId, props]);
89
84
  var _useCommonChatAPI = useCommonChatAPI(hookParams),
@@ -169,11 +164,6 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
169
164
  }
170
165
  handleSend(val, agent, isSystemAuto);
171
166
  }, [handleSend, startConversationAndChat]);
172
- React.useEffect(function () {
173
- if (props.initSendValue && storedBaseUrl && storedToken) {
174
- handleInputSend(props.initSendValue);
175
- }
176
- }, [props.initSendValue, handleInputSend, storedBaseUrl, storedToken]);
177
167
 
178
168
  // 输入框开头Agent名称
179
169
  var showTitleSlot = React.useMemo(function () {
@@ -3,6 +3,8 @@ import { store } from "../../store";
3
3
  import CommonChat from "./CommonChat";
4
4
  import React from 'react';
5
5
  import { Provider } from 'react-redux';
6
+ import ChatContext from "./chatContext";
7
+ import useApi from "../../apis/useApi";
6
8
  var GimiChatComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
7
9
  var commonChatRef = React.useRef(null);
8
10
  React.useImperativeHandle(ref, function () {
@@ -29,10 +31,15 @@ var GimiChatComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
29
31
  }
30
32
  };
31
33
  });
34
+ var apiService = useApi(props.baseUrl, props.token);
32
35
  return /*#__PURE__*/React.createElement(Provider, {
33
36
  store: store
37
+ }, /*#__PURE__*/React.createElement(ChatContext.Provider, {
38
+ value: {
39
+ apiService: apiService
40
+ }
34
41
  }, /*#__PURE__*/React.createElement(CommonChat, _extends({}, props, {
35
42
  ref: commonChatRef
36
- })));
43
+ }))));
37
44
  });
38
45
  export default GimiChatComponent;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { IUseApi } from '../../apis/useApi';
3
+ declare const ChatContext: import("react").Context<{
4
+ apiService: IUseApi | null;
5
+ }>;
6
+ export default ChatContext;
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+ var ChatContext = /*#__PURE__*/createContext({
3
+ apiService: null
4
+ });
5
+ export default ChatContext;
@@ -20,14 +20,17 @@ import { useAppSelector, useAppDispatch } from "../store/hooks";
20
20
  import { setMessageList } from "../store/slices/gimiMenuSlice";
21
21
  import { processString } from "../utils/tools";
22
22
  import { debounce } from "../utils/chatInputUtil";
23
- import useApi from "../apis/useApi";
23
+ import ChatContext from "../components/templates/chatContext";
24
+ import { useContext } from 'react';
24
25
  var updateLastMessage = function updateLastMessage(chatList, updater) {
25
26
  if (chatList.length === 0) return chatList;
26
27
  return [].concat(_toConsumableArray(chatList.slice(0, -1)), [updater(chatList[chatList.length - 1])]);
27
28
  };
28
29
  export var usePureChatActions = function usePureChatActions() {
29
- var _useApi = useApi(),
30
- handleMark = _useApi.handleMark;
30
+ var _useContext = useContext(ChatContext),
31
+ apiService = _useContext.apiService;
32
+ var _ref = apiService,
33
+ handleMark = _ref.handleMark;
31
34
  var baseUrl = useAppSelector(function (state) {
32
35
  return state.gimiMenu.baseUrl;
33
36
  });
@@ -48,7 +51,7 @@ export var usePureChatActions = function usePureChatActions() {
48
51
  timeout: 10000
49
52
  });
50
53
  var copyToClipboard = React.useCallback( /*#__PURE__*/function () {
51
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
54
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
52
55
  var replaceTags,
53
56
  text,
54
57
  _value$moduleInfo,
@@ -91,14 +94,14 @@ export var usePureChatActions = function usePureChatActions() {
91
94
  }, _callee, null, [[4, 10]]);
92
95
  }));
93
96
  return function (_x) {
94
- return _ref.apply(this, arguments);
97
+ return _ref2.apply(this, arguments);
95
98
  };
96
99
  }(), []);
97
100
  /**
98
101
  * 点赞/点踩
99
102
  */
100
103
  var handleUnlove = React.useCallback( /*#__PURE__*/function () {
101
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item, type) {
104
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item, type) {
102
105
  var mark, params, newMessageList, res;
103
106
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
104
107
  while (1) switch (_context2.prev = _context2.next) {
@@ -144,7 +147,7 @@ export var usePureChatActions = function usePureChatActions() {
144
147
  }, _callee2, null, [[3, 13]]);
145
148
  }));
146
149
  return function (_x2, _x3) {
147
- return _ref2.apply(this, arguments);
150
+ return _ref3.apply(this, arguments);
148
151
  };
149
152
  }(), []);
150
153
  return {
@@ -20,7 +20,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
20
  import React, { useCallback, useEffect, useRef, useLayoutEffect } from 'react';
21
21
  import { useAppDispatch, useAppSelector } from "../store/hooks";
22
22
  import { setMessageList } from "../store/slices/gimiMenuSlice";
23
- import useApi from "../apis/useApi";
23
+ import { useContext } from 'react';
24
+ import ChatContext from "../components/templates/chatContext";
24
25
  import { formatFields, updatedSkillResult } from "../utils/tools";
25
26
  import { useChatRecommend } from "./useChatRecommend";
26
27
  import { Toast } from '@douyinfe/semi-ui';
@@ -57,8 +58,10 @@ var useChatHistory = function useChatHistory(checkUnfinishedMessage, scrollBotto
57
58
  _React$useState4 = _slicedToArray(_React$useState3, 2),
58
59
  param = _React$useState4[0],
59
60
  setParam = _React$useState4[1];
60
- var _useApi = useApi(),
61
- getMessageList = _useApi.getMessageList;
61
+ var _useContext = useContext(ChatContext),
62
+ apiService = _useContext.apiService;
63
+ var _ref = apiService,
64
+ getMessageList = _ref.getMessageList;
62
65
 
63
66
  // 使用 ref 存储最新的值,避免闭包陷阱
64
67
  var messageListRef = useRef(messageList);
@@ -15,21 +15,24 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
15
15
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
16
16
  import React from 'react';
17
17
  import { Toast } from '@douyinfe/semi-ui';
18
- import useApi from "../apis/useApi";
18
+ import { useContext } from 'react';
19
+ import ChatContext from "../components/templates/chatContext";
19
20
  import { useAppDispatch } from "../store/hooks";
20
21
  import { setMessageList } from "../store/slices/gimiMenuSlice";
21
22
  /**
22
23
  * 管理推荐列表相关逻辑
23
24
  */
24
25
  export var useChatRecommend = function useChatRecommend() {
25
- var _useApi = useApi(),
26
- getProbeList = _useApi.getProbeList;
26
+ var _useContext = useContext(ChatContext),
27
+ apiService = _useContext.apiService;
28
+ var _ref = apiService,
29
+ getProbeList = _ref.getProbeList;
27
30
  var dispatch = useAppDispatch();
28
31
  /**
29
32
  * 获取推荐列表
30
33
  */
31
34
  var getRecommendList = React.useCallback( /*#__PURE__*/function () {
32
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chatList, msgId, chatStatus) {
35
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chatList, msgId, chatStatus) {
33
36
  var issueRecommendList, _yield$getProbeList, result, status, newMessageList;
34
37
  return _regeneratorRuntime().wrap(function _callee$(_context) {
35
38
  while (1) switch (_context.prev = _context.next) {
@@ -69,7 +72,7 @@ export var useChatRecommend = function useChatRecommend() {
69
72
  }, _callee, null, [[1, 11]]);
70
73
  }));
71
74
  return function (_x, _x2, _x3) {
72
- return _ref.apply(this, arguments);
75
+ return _ref2.apply(this, arguments);
73
76
  };
74
77
  }(), [dispatch]);
75
78
 
@@ -77,7 +80,7 @@ export var useChatRecommend = function useChatRecommend() {
77
80
  * 重写历史记录中的推荐列表
78
81
  */
79
82
  var rewriteRecommendListFormHistory = React.useCallback( /*#__PURE__*/function () {
80
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(chatList, msgId) {
83
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(chatList, msgId) {
81
84
  var _yield$getProbeList2, result, status, issueRecommendList, newMessageList;
82
85
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
83
86
  while (1) switch (_context2.prev = _context2.next) {
@@ -116,7 +119,7 @@ export var useChatRecommend = function useChatRecommend() {
116
119
  }, _callee2, null, [[0, 11]]);
117
120
  }));
118
121
  return function (_x4, _x5) {
119
- return _ref2.apply(this, arguments);
122
+ return _ref3.apply(this, arguments);
120
123
  };
121
124
  }(), []);
122
125
  return {
@@ -13,6 +13,7 @@ interface IHookProps {
13
13
  chatInputConfig?: IAIInputProps;
14
14
  autoSendValue?: string;
15
15
  initAttachments?: FileItem[];
16
+ initSendValue?: string;
16
17
  }
17
18
  declare const useCommonChatAPI: (props: IHookProps) => {
18
19
  headerValue: string;
@@ -17,7 +17,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
17
17
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
18
18
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
19
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
- import useApi from "../apis/useApi";
20
+ import { useContext } from 'react';
21
+ import ChatContext from "../components/templates/chatContext";
21
22
  import React, { useRef } from 'react';
22
23
  import { Toast } from "@douyinfe/semi-ui";
23
24
  import { useAppDispatch, useAppSelector } from "../store/hooks";
@@ -43,19 +44,22 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
43
44
  interruptKey = props.interruptKey,
44
45
  chatInputConfig = props.chatInputConfig,
45
46
  autoSendValue = props.autoSendValue,
46
- initAttachments = props.initAttachments;
47
- var _useApi = useApi(),
48
- getMessageTitle = _useApi.getMessageTitle,
49
- stopStreamOut = _useApi.stopStreamOut,
50
- createRoomId = _useApi.createRoomId,
51
- getAgentDetail = _useApi.getAgentDetail,
52
- deleteConversationById = _useApi.deleteConversationById,
53
- checkRetry = _useApi.checkRetry;
54
- var _ref = props.chatInputConfig || {},
55
- onFirstSendSuccess = _ref.onFirstSendSuccess,
56
- onSendSuccess = _ref.onSendSuccess,
57
- onSendEnd = _ref.onSendEnd,
58
- onConversationCreated = _ref.onConversationCreated;
47
+ initAttachments = props.initAttachments,
48
+ initSendValue = props.initSendValue;
49
+ var _useContext = useContext(ChatContext),
50
+ apiService = _useContext.apiService;
51
+ var _ref = apiService,
52
+ getMessageTitle = _ref.getMessageTitle,
53
+ stopStreamOut = _ref.stopStreamOut,
54
+ createRoomId = _ref.createRoomId,
55
+ getAgentDetail = _ref.getAgentDetail,
56
+ deleteConversationById = _ref.deleteConversationById,
57
+ checkRetry = _ref.checkRetry;
58
+ var _ref2 = props.chatInputConfig || {},
59
+ onFirstSendSuccess = _ref2.onFirstSendSuccess,
60
+ onSendSuccess = _ref2.onSendSuccess,
61
+ onSendEnd = _ref2.onSendEnd,
62
+ onConversationCreated = _ref2.onConversationCreated;
59
63
  var dispatch = useAppDispatch();
60
64
  var _React$useState = React.useState(''),
61
65
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -154,6 +158,10 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
154
158
  var interruptKeyRef = useRef(interruptKey || '');
155
159
  // onFirstSendSuccess 是否已经执行过
156
160
  var onFirstSendSuccessCalledRef = useRef(false);
161
+ // autoSendValue ref
162
+ var autoSendValueRef = useRef('');
163
+ // initSendValue ref
164
+ var initSendValueRef = useRef('');
157
165
 
158
166
  // 更细Ref的值
159
167
  messageListRef.current = messageList;
@@ -331,7 +339,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
331
339
 
332
340
  // 发起会话 - 使用新的hook简化逻辑
333
341
  var fetchChatStream = React.useCallback( /*#__PURE__*/function () {
334
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(id, reSumeInfo, _onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
342
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(id, reSumeInfo, _onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
335
343
  var fullResponse, reasoningResponse;
336
344
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
337
345
  while (1) switch (_context3.prev = _context3.next) {
@@ -381,13 +389,13 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
381
389
  }, _callee3);
382
390
  }));
383
391
  return function (_x, _x2, _x3, _x4, _x5, _x6) {
384
- return _ref4.apply(this, arguments);
392
+ return _ref5.apply(this, arguments);
385
393
  };
386
394
  }(), [fetchChatStreamHook, setIgnoreOnMessage, removeLastEventId, handleMCPToolsStreamRs]);
387
395
 
388
396
  // 流式输出开始
389
397
  var streamChat = React.useCallback( /*#__PURE__*/function () {
390
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lastId, again) {
398
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lastId, again) {
391
399
  var reSumeInfo,
392
400
  agentInfo,
393
401
  _args5 = arguments;
@@ -429,7 +437,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
429
437
  messageList: newMessageList
430
438
  }));
431
439
  }, /*#__PURE__*/function () {
432
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(Response, type, reasoningResponse) {
440
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(Response, type, reasoningResponse) {
433
441
  var currentMessageList, newMessageList, agentDetail;
434
442
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
435
443
  while (1) switch (_context4.prev = _context4.next) {
@@ -471,7 +479,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
471
479
  }, _callee4);
472
480
  }));
473
481
  return function (_x9, _x10, _x11) {
474
- return _ref6.apply(this, arguments);
482
+ return _ref7.apply(this, arguments);
475
483
  };
476
484
  }(), function () {
477
485
  setIgnoreOnMessage(true);
@@ -502,7 +510,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
502
510
  }, _callee5);
503
511
  }));
504
512
  return function (_x7, _x8) {
505
- return _ref5.apply(this, arguments);
513
+ return _ref6.apply(this, arguments);
506
514
  };
507
515
  }(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList, onSendEnd]);
508
516
  var regenerate = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
@@ -552,7 +560,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
552
560
 
553
561
  // 单独的断点续传
554
562
  var checkUnfinishedMessage = React.useCallback( /*#__PURE__*/function () {
555
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(chatList) {
563
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(chatList) {
556
564
  var lastMessage, newMessageList, _agentObjRef$current, lastUserRequestMessage;
557
565
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
558
566
  while (1) switch (_context7.prev = _context7.next) {
@@ -594,7 +602,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
594
602
  }, _callee7);
595
603
  }));
596
604
  return function (_x12) {
597
- return _ref8.apply(this, arguments);
605
+ return _ref9.apply(this, arguments);
598
606
  };
599
607
  }(), [dispatch, streamChat, removeLastEventId, rewriteRecommendListFormHistory]);
600
608
  var _useChatHistory = useChatHistory(checkUnfinishedMessage, scrollBottomForce, containerRef),
@@ -613,7 +621,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
613
621
 
614
622
  // 开始会话
615
623
  var startChat = React.useCallback( /*#__PURE__*/function () {
616
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(messageList) {
624
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(messageList) {
617
625
  var _reverse$find;
618
626
  var isSystemAuto,
619
627
  conversationId,
@@ -760,7 +768,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
760
768
  }, _callee8, null, [[10, 31]]);
761
769
  }));
762
770
  return function (_x13) {
763
- return _ref9.apply(this, arguments);
771
+ return _ref10.apply(this, arguments);
764
772
  };
765
773
  }(), [dispatch]);
766
774
  var fillInputModel = React.useCallback(function (value, messageList) {
@@ -775,7 +783,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
775
783
  }
776
784
  }, []);
777
785
  var handleSend = React.useCallback( /*#__PURE__*/function () {
778
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(val) {
786
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(val) {
779
787
  var _chatInputConfig$onBe;
780
788
  var agent,
781
789
  isSystemAuto,
@@ -866,13 +874,13 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
866
874
  }, _callee9);
867
875
  }));
868
876
  return function (_x14) {
869
- return _ref10.apply(this, arguments);
877
+ return _ref11.apply(this, arguments);
870
878
  };
871
879
  }(), [dispatch, startChat, chatInputConfig, createUserChat, fillInputModel, isPlaying, status, stopTTSByText]);
872
880
 
873
881
  // 获取对话标题
874
882
  var getHeaderValue = React.useCallback( /*#__PURE__*/function () {
875
- var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(conversationId) {
883
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(conversationId) {
876
884
  var res, _res$result;
877
885
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
878
886
  while (1) switch (_context10.prev = _context10.next) {
@@ -904,7 +912,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
904
912
  }, _callee10, null, [[2, 9]]);
905
913
  }));
906
914
  return function (_x15) {
907
- return _ref11.apply(this, arguments);
915
+ return _ref12.apply(this, arguments);
908
916
  };
909
917
  }(), []);
910
918
  React.useEffect(function () {
@@ -917,7 +925,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
917
925
  getHeaderValue(conversationId);
918
926
  getContentMessageList();
919
927
  }
920
- if (autoSendValue) {
928
+ if (autoSendValue && autoSendValueRef.current !== autoSendValue) {
929
+ autoSendValueRef.current = autoSendValue;
921
930
  getHeaderValue(conversationId);
922
931
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
923
932
  handleSend(autoSendValue);
@@ -939,7 +948,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
939
948
  };
940
949
  }, [conversationId, dispatch, clearQuotesFromRedux, streamEsAbortRef]);
941
950
  var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
942
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(agentId) {
951
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(agentId) {
943
952
  var res;
944
953
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
945
954
  while (1) switch (_context11.prev = _context11.next) {
@@ -975,11 +984,11 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
975
984
  }, _callee11, null, [[0, 13]]);
976
985
  }));
977
986
  return function (_x16) {
978
- return _ref12.apply(this, arguments);
987
+ return _ref13.apply(this, arguments);
979
988
  };
980
989
  }(), []);
981
990
  var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
982
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(value) {
991
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(value) {
983
992
  var _agentObjRef$current3;
984
993
  var currentBussinessParams, params, res;
985
994
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
@@ -1039,7 +1048,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1039
1048
  }, _callee12, null, [[6, 14]]);
1040
1049
  }));
1041
1050
  return function (_x17) {
1042
- return _ref13.apply(this, arguments);
1051
+ return _ref14.apply(this, arguments);
1043
1052
  };
1044
1053
  }(), [handleSend, platform, dispatch, createRoomId, onConversationCreated, getHeaderValue]);
1045
1054
  React.useEffect(function () {
@@ -1047,6 +1056,12 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1047
1056
  fetchAgentDetail(agentId);
1048
1057
  }
1049
1058
  }, [agentId, reloadAgentKey, baseUrl, fetchAgentDetail]);
1059
+ React.useEffect(function () {
1060
+ if (initSendValue && initSendValueRef.current !== initSendValue && agentObj !== null && agentObj !== void 0 && agentObj.agentId) {
1061
+ initSendValueRef.current = initSendValue;
1062
+ startConversationAndChat(initSendValue);
1063
+ }
1064
+ }, [initSendValue, startConversationAndChat, agentObj === null || agentObj === void 0 ? void 0 : agentObj.agentId]);
1050
1065
  React.useEffect(function () {
1051
1066
  if (resetKey && resetKey !== resetKeyRef.current) {
1052
1067
  var _controllerRef$curren, _streamEsAbortRef$cur;
@@ -8,7 +8,7 @@ interface IProps {
8
8
  }[];
9
9
  qutoType?: 'teachModel' | 'product';
10
10
  }
11
- declare const useKnowledgeService: (props: IProps[]) => {
11
+ declare const useKnowledgeService: (props: IProps[], isMsgRecieving: boolean) => {
12
12
  isLoading: boolean;
13
13
  documentList: ITeachingModuleResource[];
14
14
  videoSliceList: IVideoResource[];
@@ -14,12 +14,15 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
14
14
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
  import React from "react";
17
- import useApi from "../apis/useApi";
18
- var useKnowledgeService = function useKnowledgeService(props) {
19
- var _useApi = useApi(),
20
- getProductList = _useApi.getProductList,
21
- getFileResourceList = _useApi.getFileResourceList,
22
- getVideoSliceList = _useApi.getVideoSliceList;
17
+ import { useContext } from 'react';
18
+ import ChatContext from "../components/templates/chatContext";
19
+ var useKnowledgeService = function useKnowledgeService(props, isMsgRecieving) {
20
+ var _useContext = useContext(ChatContext),
21
+ apiService = _useContext.apiService;
22
+ var _ref = apiService,
23
+ getProductList = _ref.getProductList,
24
+ getFileResourceList = _ref.getFileResourceList,
25
+ getVideoSliceList = _ref.getVideoSliceList;
23
26
  var _React$useState = React.useState(false),
24
27
  _React$useState2 = _slicedToArray(_React$useState, 2),
25
28
  isLoading = _React$useState2[0],
@@ -37,7 +40,7 @@ var useKnowledgeService = function useKnowledgeService(props) {
37
40
  videoSliceList = _React$useState8[0],
38
41
  setVideoSliceList = _React$useState8[1];
39
42
  var getProducts = /*#__PURE__*/function () {
40
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item) {
43
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item) {
41
44
  var ids, res, _res$result;
42
45
  return _regeneratorRuntime().wrap(function _callee$(_context) {
43
46
  while (1) switch (_context.prev = _context.next) {
@@ -74,11 +77,11 @@ var useKnowledgeService = function useKnowledgeService(props) {
74
77
  }, _callee, null, [[0, 8]]);
75
78
  }));
76
79
  return function getProducts(_x) {
77
- return _ref.apply(this, arguments);
80
+ return _ref2.apply(this, arguments);
78
81
  };
79
82
  }();
80
83
  var getDocuments = /*#__PURE__*/function () {
81
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
84
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
82
85
  var ids, res, _res$result2;
83
86
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
84
87
  while (1) switch (_context2.prev = _context2.next) {
@@ -115,11 +118,11 @@ var useKnowledgeService = function useKnowledgeService(props) {
115
118
  }, _callee2, null, [[0, 8]]);
116
119
  }));
117
120
  return function getDocuments(_x2) {
118
- return _ref2.apply(this, arguments);
121
+ return _ref3.apply(this, arguments);
119
122
  };
120
123
  }();
121
124
  var getVideos = /*#__PURE__*/function () {
122
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
125
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
123
126
  var params, res, _res$result3;
124
127
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
125
128
  while (1) switch (_context3.prev = _context3.next) {
@@ -160,13 +163,13 @@ var useKnowledgeService = function useKnowledgeService(props) {
160
163
  }, _callee3, null, [[0, 8]]);
161
164
  }));
162
165
  return function getVideos(_x3) {
163
- return _ref3.apply(this, arguments);
166
+ return _ref4.apply(this, arguments);
164
167
  };
165
168
  }();
166
169
  React.useEffect(function () {
167
- if ((props === null || props === void 0 ? void 0 : props.length) === 0) return;
170
+ if ((props === null || props === void 0 ? void 0 : props.length) === 0 || isMsgRecieving) return;
168
171
  var queryKnowledgeTraceList = /*#__PURE__*/function () {
169
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
172
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
170
173
  var promiseList;
171
174
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
172
175
  while (1) switch (_context4.prev = _context4.next) {
@@ -195,11 +198,11 @@ var useKnowledgeService = function useKnowledgeService(props) {
195
198
  }, _callee4, null, [[1, 9]]);
196
199
  }));
197
200
  return function queryKnowledgeTraceList() {
198
- return _ref4.apply(this, arguments);
201
+ return _ref5.apply(this, arguments);
199
202
  };
200
203
  }();
201
204
  queryKnowledgeTraceList();
202
- }, [props]);
205
+ }, [props, isMsgRecieving]);
203
206
  return {
204
207
  isLoading: isLoading,
205
208
  documentList: documentList,
@@ -9,11 +9,14 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import React from 'react';
12
- import useApi from "../apis/useApi";
12
+ import ChatContext from "../components/templates/chatContext";
13
+ import { useContext } from 'react';
13
14
  import { Toast } from '@douyinfe/semi-ui';
14
15
  export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatus, maxPolltime, requestId) {
15
- var _useApi = useApi(),
16
- getSkillData = _useApi.getSkillData;
16
+ var _useContext = useContext(ChatContext),
17
+ apiService = _useContext.apiService;
18
+ var _ref = apiService,
19
+ getSkillData = _ref.getSkillData;
17
20
  // 存储定时器实例
18
21
  var intervalRef = React.useRef(undefined);
19
22
  // 存储轮询开始时间
@@ -24,7 +27,7 @@ export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatu
24
27
  pollResult = _React$useState2[0],
25
28
  setPollResult = _React$useState2[1];
26
29
  var onPoll = React.useCallback( /*#__PURE__*/function () {
27
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestId) {
30
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestId) {
28
31
  var res;
29
32
  return _regeneratorRuntime().wrap(function _callee$(_context) {
30
33
  while (1) switch (_context.prev = _context.next) {
@@ -47,14 +50,14 @@ export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatu
47
50
  }, _callee, null, [[0, 7]]);
48
51
  }));
49
52
  return function (_x) {
50
- return _ref.apply(this, arguments);
53
+ return _ref2.apply(this, arguments);
51
54
  };
52
55
  }(), []);
53
56
  React.useEffect(function () {
54
57
  // 记录轮询开始时间
55
58
  startTimeRef.current = Date.now();
56
59
  var handlePoll = /*#__PURE__*/function () {
57
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
60
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
58
61
  var elapsedTime, result, shouldStopPolling;
59
62
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
60
63
  while (1) switch (_context2.prev = _context2.next) {
@@ -91,7 +94,7 @@ export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatu
91
94
  }, _callee2);
92
95
  }));
93
96
  return function handlePoll() {
94
- return _ref2.apply(this, arguments);
97
+ return _ref3.apply(this, arguments);
95
98
  };
96
99
  }();
97
100