@myun/gimi-chat 0.3.0 → 0.3.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.
@@ -314,10 +314,9 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
314
314
  })), renderProps.menuItem);
315
315
  }, [VoiceTools, UploadFileTool, props.enableSourceQuote]);
316
316
  var onMessageSend = React.useCallback(function (content) {
317
- var _props$onBeforeSend, _props$onSend;
317
+ var _props$onSend;
318
318
  var inputContents = content.inputContents || [];
319
319
  var text = extractText(inputContents);
320
- (_props$onBeforeSend = props.onBeforeSend) === null || _props$onBeforeSend === void 0 || _props$onBeforeSend.call(props, text);
321
320
  (_props$onSend = props.onSend) === null || _props$onSend === void 0 || _props$onSend.call(props, text);
322
321
  }, []);
323
322
  var renderConfigureArea = React.useCallback(function () {
@@ -227,9 +227,15 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
227
227
  customRequest: customRequest,
228
228
  action: "",
229
229
  limit: limit,
230
+ onExceed: function onExceed() {
231
+ Toast.warning("\u6700\u591A\u53EA\u80FD\u4E0A\u4F20".concat(limit, "\u4E2A\u6587\u4EF6"));
232
+ },
230
233
  multiple: limit > 1,
231
234
  accept: (accept === null || accept === void 0 ? void 0 : accept.join(',')) || DEFAULT_ACCEPT,
232
235
  maxSize: maxSize * 1024,
236
+ onSizeError: function onSizeError() {
237
+ Toast.warning('文件大小超出限制');
238
+ },
233
239
  disabled: disabled,
234
240
  showUploadList: false,
235
241
  fileList: transformFileItem(fileList || [])
@@ -17,9 +17,7 @@ import FileCardSideBar from "../file-card/fileCardSidebar";
17
17
  import OfficeFilePreviewPanel from "../file-preview";
18
18
  import AiLoading from "../ai-loading";
19
19
  var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
20
- var _props$businessType = props.businessType,
21
- businessType = _props$businessType === void 0 ? 'chat' : _props$businessType,
22
- _props$showInput = props.showInput,
20
+ var _props$showInput = props.showInput,
23
21
  showInput = _props$showInput === void 0 ? true : _props$showInput,
24
22
  baseUrl = props.baseUrl,
25
23
  token = props.token,
@@ -54,12 +52,6 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
54
52
  var agentObj = useAppSelector(function (state) {
55
53
  return state.gimiMenu.agentObj;
56
54
  });
57
- var storedBaseUrl = useAppSelector(function (state) {
58
- return state.gimiMenu.baseUrl;
59
- });
60
- var storedToken = useAppSelector(function (state) {
61
- return state.gimiMenu.token;
62
- });
63
55
  var chatUI = useChatUI();
64
56
  var _useChatVoice = useChatVoice(),
65
57
  isRecording = _useChatVoice.isRecording,
@@ -70,7 +62,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
70
62
  playTTSByText = _useChatVoice.playTTSByText,
71
63
  stopTTSByText = _useChatVoice.stopTTSByText,
72
64
  isPlaying = _useChatVoice.isPlaying;
73
- 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 === null || props === void 0 ? void 0 : props.interruptKey, props.chatInputConfig),
65
+ var _useCommonChatAPI = useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, props.reloadAgentKey, props.resetKey, props.interruptKey, props.chatInputConfig, props.initSendValue),
74
66
  headerValue = _useCommonChatAPI.headerValue,
75
67
  msgLoading = _useCommonChatAPI.msgLoading,
76
68
  onSucessExcel = _useCommonChatAPI.onSucessExcel,
@@ -87,8 +79,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
87
79
  scrollBottomForce = _useCommonChatAPI.scrollBottomForce,
88
80
  showBackBottom = _useCommonChatAPI.showBackBottom,
89
81
  isScrolling = _useCommonChatAPI.isScrolling,
90
- regenerate = _useCommonChatAPI.regenerate,
91
- startAICorrection = _useCommonChatAPI.startAICorrection;
82
+ regenerate = _useCommonChatAPI.regenerate;
92
83
  React.useImperativeHandle(ref, function () {
93
84
  return {
94
85
  messageList: messageList,
@@ -124,11 +115,6 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
124
115
  React.useEffect(function () {
125
116
  dispatch(setBussinessParams(bussinessParams || {}));
126
117
  }, [bussinessParams]);
127
- React.useEffect(function () {
128
- if (bussinessParams !== null && bussinessParams !== void 0 && bussinessParams.QUESTION_ID && bussinessParams !== null && bussinessParams !== void 0 && bussinessParams.ANSWER_ID && businessType === 'correction' && storedBaseUrl && storedToken) {
129
- startAICorrection(bussinessParams.ANSWER_ID, bussinessParams.QUESTION_ID);
130
- }
131
- }, [bussinessParams, storedBaseUrl, storedToken, businessType]);
132
118
  var disableVoiceCommunication = React.useMemo(function () {
133
119
  var lastedMessage = messageList[messageList.length - 1];
134
120
  var content = (lastedMessage === null || lastedMessage === void 0 ? void 0 : lastedMessage.content) || '';
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { IAIInputProps } from "../types/chat";
3
- declare const useCommonChatAPI: (containerRef: React.RefObject<HTMLDivElement>, platform: string, stopTTSByText?: () => void, isPlaying?: boolean, agentId?: number, reloadAgentKey?: string, resetKey?: string, interruptKey?: string, chatInputConfig?: IAIInputProps) => {
3
+ declare const useCommonChatAPI: (containerRef: React.RefObject<HTMLDivElement>, platform: string, stopTTSByText?: () => void, isPlaying?: boolean, agentId?: number, reloadAgentKey?: string, resetKey?: string, interruptKey?: string, chatInputConfig?: IAIInputProps, initSendValue?: string) => {
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, resetKey, interruptKey, chatInputConfig) {
35
+ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, reloadAgentKey, resetKey, interruptKey, chatInputConfig, initSendValue) {
36
36
  var _useApi = useApi(),
37
37
  getMessageTitle = _useApi.getMessageTitle,
38
38
  stopStreamOut = _useApi.stopStreamOut,
@@ -819,12 +819,18 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
819
819
  React.useEffect(function () {
820
820
  if (conversationId && conversationIdRef.current !== conversationId) {
821
821
  conversationIdRef.current = conversationId;
822
- if (autoLoadConversation) {
822
+ // 如果有初始化发送值,不自动加载历史消息,而是直接发送初始化发送值
823
+ if (autoLoadConversation && !initSendValue) {
823
824
  getHeaderValue(conversationId);
824
825
  getContentMessageList();
825
826
  }
827
+ if (initSendValue) {
828
+ getHeaderValue(conversationId);
829
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
830
+ handleSend(initSendValue);
831
+ }
826
832
  }
827
- }, [conversationId, autoLoadConversation]);
833
+ }, [conversationId, autoLoadConversation, initSendValue]);
828
834
  React.useEffect(function () {
829
835
  var idAtEffectTime = conversationId;
830
836
  return function () {
@@ -1126,6 +1132,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1126
1132
  }, []);
1127
1133
  var handleSend = React.useCallback( /*#__PURE__*/function () {
1128
1134
  var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(val) {
1135
+ var _chatInputConfig$onBe;
1129
1136
  var agent,
1130
1137
  isSystemAuto,
1131
1138
  conversationId,
@@ -1165,16 +1172,18 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1165
1172
  Toast.error('AI正在输出中,请稍后');
1166
1173
  return _context16.abrupt("return");
1167
1174
  case 12:
1175
+ chatInputConfig === null || chatInputConfig === void 0 || (_chatInputConfig$onBe = chatInputConfig.onBeforeSend) === null || _chatInputConfig$onBe === void 0 || _chatInputConfig$onBe.call(chatInputConfig, value);
1176
+
1168
1177
  // 设置inputModel
1169
1178
  fillInputModel(value, messageListRef.current);
1170
1179
  fileValidationMsg = fileValidation(fileListRef.current);
1171
1180
  if (!fileValidationMsg) {
1172
- _context16.next = 17;
1181
+ _context16.next = 18;
1173
1182
  break;
1174
1183
  }
1175
1184
  Toast.error(fileValidationMsg);
1176
1185
  return _context16.abrupt("return");
1177
- case 17:
1186
+ case 18:
1178
1187
  if (isPlaying) {
1179
1188
  // 点击发送按钮时,先停止播放
1180
1189
  stopTTSByText === null || stopTTSByText === void 0 || stopTTSByText();
@@ -1206,7 +1215,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1206
1215
  // 系统自动上传,直接开始会话,不更新列表
1207
1216
  startChat([].concat(_toConsumableArray(prevChatList), [userChat]), isSystemAuto, conversationId);
1208
1217
  }
1209
- case 24:
1218
+ case 25:
1210
1219
  case "end":
1211
1220
  return _context16.stop();
1212
1221
  }
@@ -1215,7 +1224,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1215
1224
  return function (_x26) {
1216
1225
  return _ref17.apply(this, arguments);
1217
1226
  };
1218
- }(), [dispatch, startChat]);
1227
+ }(), [dispatch, startChat, chatInputConfig === null || chatInputConfig === void 0 ? void 0 : chatInputConfig.onBeforeSend]);
1219
1228
  var handleSendFile = React.useCallback(function (messageList) {
1220
1229
  if (!navigator.onLine) {
1221
1230
  Toast.error('无法连接到网络');
@@ -98,6 +98,7 @@ export interface CommonChatProps {
98
98
  baseUrl?: string;
99
99
  token?: string;
100
100
  showHeader?: boolean;
101
+ initSendValue?: string;
101
102
  chatInputConfig?: IAIInputProps;
102
103
  platform?: 'myun' | 'preview' | 'damai';
103
104
  businessType: 'correction' | 'chat';