@myun/gimi-chat 0.1.5 → 0.1.6

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.
@@ -12,5 +12,5 @@ interface AiExplainProps {
12
12
  setSpeech: (value: boolean) => void;
13
13
  handleHangUp?: () => void;
14
14
  }
15
- declare const AiExplain: React.ForwardRefExoticComponent<AiExplainProps & React.RefAttributes<unknown>>;
15
+ declare const AiExplain: ({ paper, setSpeech, handleHangUp }: AiExplainProps) => React.ReactPortal;
16
16
  export default AiExplain;
@@ -18,7 +18,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
18
18
  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; }
19
19
  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; } }
20
20
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
- import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
21
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
22
22
  import LottieImg from "../lottie-img";
23
23
  import styles from "./index.module.css";
24
24
  import classNames from 'classnames';
@@ -37,7 +37,7 @@ import { useDispatch } from 'react-redux';
37
37
 
38
38
  // 2. 定义组件完整的 Props 接口
39
39
 
40
- var AiExplain = /*#__PURE__*/forwardRef(function (_ref) {
40
+ var AiExplain = function AiExplain(_ref) {
41
41
  var paper = _ref.paper,
42
42
  setSpeech = _ref.setSpeech,
43
43
  _ref$handleHangUp = _ref.handleHangUp,
@@ -1052,5 +1052,5 @@ var AiExplain = /*#__PURE__*/forwardRef(function (_ref) {
1052
1052
  type: "icon-a-mti-guaduanshi",
1053
1053
  size: 34
1054
1054
  }))))))))), document.body);
1055
- });
1055
+ };
1056
1056
  export default AiExplain;
@@ -166,7 +166,7 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
166
166
  return Toast.info('最多上传一个文件哦');
167
167
  };
168
168
  var UploadFileTool = React.useMemo(function () {
169
- if (!props.enableFileUpload || messageList.length > 0) {
169
+ if (!props.enableFileUpload || messageList.length > 0 || (agentObj === null || agentObj === void 0 ? void 0 : agentObj.openUploadFile) === 0) {
170
170
  return null;
171
171
  }
172
172
  return /*#__PURE__*/React.createElement(FileUpload, {
@@ -393,14 +393,19 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
393
393
  };
394
394
  React.useEffect(function () {
395
395
  if (messageList.length === 0 && !conversationIdRef.current) {
396
- var _inputRef$current7;
397
396
  var defaultContent = transformToInputSlots(props.defaultPrompt || '', props.titleSlot || '');
398
- (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 || _inputRef$current7.setContent(defaultContent);
397
+ // 解决 Semi UI AIChatInput setContent useEffect 中触发 flushSync 警告的问题
398
+ Promise.resolve().then(function () {
399
+ var _inputRef$current7;
400
+ (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 || _inputRef$current7.setContent(defaultContent);
401
+ });
399
402
  setHasContent(!!props.defaultPrompt);
400
403
  preInputValueRef.current = props.defaultPrompt || '';
401
404
  } else {
402
- var _inputRef$current8;
403
- (_inputRef$current8 = inputRef.current) === null || _inputRef$current8 === void 0 || _inputRef$current8.setContent('');
405
+ Promise.resolve().then(function () {
406
+ var _inputRef$current8;
407
+ (_inputRef$current8 = inputRef.current) === null || _inputRef$current8 === void 0 || _inputRef$current8.setContent('');
408
+ });
404
409
  setHasContent(false);
405
410
  }
406
411
  }, [props.defaultPrompt, messageList.length, props.titleSlot]);
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  import React from 'react';
3
3
  import { store } from "../../store";
4
4
  import { useAppDispatch, useAppSelector } from "../../store/hooks";
5
- import { setBaseUrl, setToken, setPlatform, setConversationId, setAgentDetail, setBussinessParams, setMessageList } from "../../store/slices/gimiMenuSlice";
5
+ import { setBaseUrl, setToken, setPlatform, setConversationId, setAgentDetail, setBussinessParams } from "../../store/slices/gimiMenuSlice";
6
6
  import useCommonChatAPI from "../../hooks/useCommonChatAPI";
7
7
  import { replaceBraces } from "../../utils/tools";
8
8
  import styles from "./index.module.css";
@@ -49,7 +49,6 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
49
49
  var dispatch = useAppDispatch();
50
50
  var containerRef = React.useRef(null);
51
51
  var chatInputRef = React.useRef(null);
52
- var resetKeyRef = React.useRef('');
53
52
  var messageList = useAppSelector(function (state) {
54
53
  return state.gimiMenu.messageList;
55
54
  });
@@ -72,7 +71,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
72
71
  playTTSByText = _useChatVoice.playTTSByText,
73
72
  stopTTSByText = _useChatVoice.stopTTSByText,
74
73
  isPlaying = _useChatVoice.isPlaying;
75
- var _useCommonChatAPI = useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, props === null || props === void 0 ? void 0 : props.reloadAgentKey, (_props$chatInputConfi2 = props.chatInputConfig) === null || _props$chatInputConfi2 === void 0 ? void 0 : _props$chatInputConfi2.onConversationCreated, (_props$chatInputConfi3 = props.chatInputConfig) === null || _props$chatInputConfi3 === void 0 ? void 0 : _props$chatInputConfi3.onSendEnd),
74
+ var _useCommonChatAPI = useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, props === null || props === void 0 ? void 0 : props.reloadAgentKey, props === null || props === void 0 ? void 0 : props.resetKey, (_props$chatInputConfi2 = props.chatInputConfig) === null || _props$chatInputConfi2 === void 0 ? void 0 : _props$chatInputConfi2.onConversationCreated, (_props$chatInputConfi3 = props.chatInputConfig) === null || _props$chatInputConfi3 === void 0 ? void 0 : _props$chatInputConfi3.onSendEnd),
76
75
  headerValue = _useCommonChatAPI.headerValue,
77
76
  msgLoading = _useCommonChatAPI.msgLoading,
78
77
  onSucessExcel = _useCommonChatAPI.onSucessExcel,
@@ -110,27 +109,22 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
110
109
  dispatch(setPlatform({
111
110
  platform: platform
112
111
  }));
112
+ }, [baseUrl, token, platform]);
113
+ React.useEffect(function () {
113
114
  dispatch(setConversationId({
114
115
  conversationId: conversationId || null
115
116
  }));
117
+ }, [conversationId]);
118
+ React.useEffect(function () {
116
119
  dispatch(setAgentDetail({
117
120
  agentDetail: agentDetail || {}
118
121
  }));
122
+ }, [agentDetail]);
123
+ React.useEffect(function () {
119
124
  dispatch(setBussinessParams({
120
125
  bussinessParams: bussinessParams || {}
121
126
  }));
122
- }, [baseUrl, token, agentDetail, platform, conversationId, bussinessParams]);
123
- React.useEffect(function () {
124
- if (props.resetKey !== resetKeyRef.current) {
125
- resetKeyRef.current = props.resetKey || '';
126
- dispatch(setConversationId({
127
- conversationId: null
128
- }));
129
- dispatch(setMessageList({
130
- messageList: []
131
- }));
132
- }
133
- }, [props.resetKey]);
127
+ }, [bussinessParams]);
134
128
  React.useEffect(function () {
135
129
  if (bussinessParams !== null && bussinessParams !== void 0 && bussinessParams.QUESTION_ID && bussinessParams !== null && bussinessParams !== void 0 && bussinessParams.ANSWER_ID && businessType === 'correction' && storedBaseUrl && storedToken) {
136
130
  startAICorrection(bussinessParams.ANSWER_ID, bussinessParams.QUESTION_ID);
@@ -151,20 +145,16 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
151
145
  var _chatInputRef$current;
152
146
  (_chatInputRef$current = chatInputRef.current) === null || _chatInputRef$current === void 0 || _chatInputRef$current.setValue(content);
153
147
  }, []);
154
-
155
- // const onInputValueChange = React.useCallback((content: string) => {
156
- // setInputValue(content);
157
- // }, []);
158
-
159
148
  var handleInputSend = React.useCallback(function (val, agent, isSystemAuto) {
160
149
  var _chatInputRef$current2;
161
150
  (_chatInputRef$current2 = chatInputRef.current) === null || _chatInputRef$current2 === void 0 || _chatInputRef$current2.setValue('');
151
+ var conversationId = store.getState().gimiMenu.conversationId;
162
152
  if (!conversationId) {
163
153
  startConversationAndChat(val);
164
154
  return;
165
155
  }
166
156
  handleSend(val, agent, isSystemAuto);
167
- }, [handleSend, startConversationAndChat, conversationId]);
157
+ }, [handleSend, startConversationAndChat]);
168
158
  return /*#__PURE__*/React.createElement("div", {
169
159
  className: styles.main,
170
160
  id: "myun_gimi_design_chat"
@@ -227,7 +217,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
227
217
  disableVoiceCommunication: disableVoiceCommunication,
228
218
  onHistoryReload: onHistoryReload,
229
219
  platform: platform
230
- }, props.chatInputConfig)), showPrologue && messageList.length === 0 && !isMoreLoading && quickQuestionListPosition === 'bottom' && /*#__PURE__*/React.createElement(PresetAgentContent, {
220
+ })), showPrologue && messageList.length === 0 && !isMoreLoading && quickQuestionListPosition === 'bottom' && /*#__PURE__*/React.createElement(PresetAgentContent, {
231
221
  prologue: '',
232
222
  questionList: (agentObj === null || agentObj === void 0 ? void 0 : agentObj.questionList) || [],
233
223
  setInputValue: setInputValue,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { IChatMessageItem } from "../interfaces/chatMessage";
3
- declare const useCommonChatAPI: (containerRef: React.RefObject<HTMLDivElement>, platform: string, stopTTSByText?: () => void, isPlaying?: boolean, agentId?: number, reloadAgentKey?: string, onConversationCreated?: ((conversationId: number) => void) | undefined, onSendEnd?: ((message: IChatMessageItem) => void) | undefined) => {
3
+ declare const useCommonChatAPI: (containerRef: React.RefObject<HTMLDivElement>, platform: string, stopTTSByText?: () => void, isPlaying?: boolean, agentId?: number, reloadAgentKey?: string, resetKey?: string, onConversationCreated?: ((conversationId: number) => void) | undefined, onSendEnd?: ((message: IChatMessageItem) => void) | undefined) => {
4
4
  headerValue: string;
5
5
  getHeaderValue: (conversationId: number) => Promise<void>;
6
6
  msgLoading: boolean;
@@ -32,7 +32,7 @@ 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, onConversationCreated, onSendEnd) {
35
+ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, reloadAgentKey, resetKey, onConversationCreated, onSendEnd) {
36
36
  var _useApi = useApi(),
37
37
  getMessageTitle = _useApi.getMessageTitle,
38
38
  stopStreamOut = _useApi.stopStreamOut,
@@ -129,6 +129,8 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
129
129
  var historyListRef = useRef(historyList || []);
130
130
  var baseUrlRef = useRef(baseUrl || '');
131
131
  var tokenRef = useRef(token || '');
132
+ // 重置key ref
133
+ var resetKeyRef = useRef(resetKey || '');
132
134
 
133
135
  // 更细Ref的值
134
136
  messageListRef.current = messageList;
@@ -328,7 +330,8 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
328
330
  }
329
331
  setMsgLoading(false);
330
332
  step.current = 0; // 重置步骤状态
331
- case 16:
333
+ onSendEnd === null || onSendEnd === void 0 || onSendEnd(messageList[messageList.length - 1]);
334
+ case 17:
332
335
  case "end":
333
336
  return _context3.stop();
334
337
  }
@@ -607,7 +610,6 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
607
610
  dispatch(setMessageList({
608
611
  messageList: newMessageList
609
612
  }));
610
- onSendEnd === null || onSendEnd === void 0 || onSendEnd(newMessageList[newMessageList.length - 1]);
611
613
  if (type === 'ask' || type === 'skill') {
612
614
  scrollBottomForce();
613
615
  }
@@ -616,18 +618,19 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
616
618
  // 获取最新的agent详情,防止redux异步更新
617
619
  agentDetail = agentInfo || agentObjRef.current;
618
620
  if (!((agentDetail === null || agentDetail === void 0 ? void 0 : agentDetail.isEnableRelated) === 1 && (type === 'end' || type === 'COMPLETED'))) {
619
- _context8.next = 11;
621
+ _context8.next = 10;
620
622
  break;
621
623
  }
622
- _context8.next = 11;
624
+ _context8.next = 10;
623
625
  return getRecommendList(newMessageList, lastId, statusRef.current);
624
- case 11:
626
+ case 10:
625
627
  if (valueRef.current) {
626
628
  setStatus(1);
627
629
  } else {
628
630
  setStatus(0);
629
631
  }
630
632
  setMsgLoading(false);
633
+ onSendEnd === null || onSendEnd === void 0 || onSendEnd(newMessageList[newMessageList.length - 1]);
631
634
  case 13:
632
635
  case "end":
633
636
  return _context8.stop();
@@ -657,6 +660,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
657
660
  setStatus(0);
658
661
  }
659
662
  setMsgLoading(false);
663
+ onSendEnd === null || onSendEnd === void 0 || onSendEnd(newMessageList[newMessageList.length - 1]);
660
664
  });
661
665
  case 5:
662
666
  case "end":
@@ -996,14 +1000,15 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
996
1000
  } else {
997
1001
  Toast.error(res.message);
998
1002
  }
999
- _context14.next = 17;
1003
+ _context14.next = 18;
1000
1004
  break;
1001
1005
  case 13:
1002
1006
  _context14.prev = 13;
1003
1007
  _context14.t0 = _context14["catch"](5);
1008
+ Toast.error('创建会话失败');
1004
1009
  console.log('error', _context14.t0);
1005
1010
  setMsgLoading(false);
1006
- case 17:
1011
+ case 18:
1007
1012
  case "end":
1008
1013
  return _context14.stop();
1009
1014
  }
@@ -1012,12 +1017,26 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1012
1017
  return function (_x25) {
1013
1018
  return _ref14.apply(this, arguments);
1014
1019
  };
1015
- }(), [fetchAgentDetail]);
1020
+ }(), []);
1016
1021
  React.useEffect(function () {
1017
1022
  if (agentId && baseUrl) {
1018
1023
  fetchAgentDetail(agentId);
1019
1024
  }
1020
1025
  }, [agentId, reloadAgentKey, baseUrl]);
1026
+ React.useEffect(function () {
1027
+ if (resetKey !== resetKeyRef.current) {
1028
+ var _controllerRef$curren, _streamEsAbortRef$cur;
1029
+ resetKeyRef.current = resetKey || '';
1030
+ (_controllerRef$curren = controllerRef.current) === null || _controllerRef$curren === void 0 || _controllerRef$curren.abort();
1031
+ (_streamEsAbortRef$cur = streamEsAbortRef.current) === null || _streamEsAbortRef$cur === void 0 || _streamEsAbortRef$cur.abort();
1032
+ dispatch(setConversationId({
1033
+ conversationId: null
1034
+ }));
1035
+ dispatch(setMessageList({
1036
+ messageList: []
1037
+ }));
1038
+ }
1039
+ }, [resetKey]);
1021
1040
  var handleSend = React.useCallback( /*#__PURE__*/function () {
1022
1041
  var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(val) {
1023
1042
  var agent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myun/gimi-chat",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "ISC",