@myun/gimi-chat 0.4.3 → 0.4.5

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.
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import type { FileItem } from "../../types/file";
2
3
  export interface ChatInputRef {
3
4
  getValue: () => string;
4
5
  setValue: (value: string) => void;
@@ -38,6 +39,7 @@ interface IAIInputProps {
38
39
  type?: string;
39
40
  duration: number;
40
41
  };
42
+ onFileUploaded?: (file: FileItem) => void;
41
43
  }
42
44
  declare const ChatInput: React.ForwardRefExoticComponent<IAIInputProps & React.RefAttributes<ChatInputRef>>;
43
45
  export default ChatInput;
@@ -171,7 +171,8 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
171
171
  return /*#__PURE__*/React.createElement(FileUpload, {
172
172
  ref: uploadFileRef,
173
173
  accept: props.accept,
174
- disabled: props.disabled || (fileList === null || fileList === void 0 ? void 0 : fileList.length) > 0
174
+ disabled: props.disabled || (fileList === null || fileList === void 0 ? void 0 : fileList.length) > 0,
175
+ onFileUploaded: props.onFileUploaded
175
176
  }, /*#__PURE__*/React.createElement(Tooltip, {
176
177
  content: '上传文件'
177
178
  }, (fileList === null || fileList === void 0 ? void 0 : fileList.length) === 0 ? /*#__PURE__*/React.createElement("div", {
@@ -6,6 +6,7 @@ interface IProps {
6
6
  accept?: string[];
7
7
  disabled?: boolean;
8
8
  children?: React.ReactNode;
9
+ onFileUploaded?: (file: FileItem) => void;
9
10
  }
10
11
  export interface IFileUploadRef {
11
12
  abortUpload: () => void;
@@ -41,7 +41,7 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
41
41
  return s.gimiMenu.token;
42
42
  });
43
43
  var uploadUrl = "https://".concat(baseUrl, "/mfilesvc/agentMessage/uploadFile");
44
- var _useGimiFileUpload = useGimiFileUpload(),
44
+ var _useGimiFileUpload = useGimiFileUpload(props.onFileUploaded),
45
45
  handleSSEFileAnalyize = _useGimiFileUpload.handleSSEFileAnalyize,
46
46
  fileUploadAbortRef = _useGimiFileUpload.fileUploadAbortRef;
47
47
 
@@ -6,13 +6,27 @@ import { Provider } from 'react-redux';
6
6
  var GimiChatComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
7
7
  var commonChatRef = React.useRef(null);
8
8
  React.useImperativeHandle(ref, function () {
9
- var _commonChatRef$curren, _commonChatRef$curren2, _commonChatRef$curren3, _commonChatRef$curren4, _commonChatRef$curren5;
10
9
  return {
11
- messageList: ((_commonChatRef$curren = commonChatRef.current) === null || _commonChatRef$curren === void 0 ? void 0 : _commonChatRef$curren.messageList) || [],
12
- agentDetail: ((_commonChatRef$curren2 = commonChatRef.current) === null || _commonChatRef$curren2 === void 0 ? void 0 : _commonChatRef$curren2.agentDetail) || {},
13
- conversationId: ((_commonChatRef$curren3 = commonChatRef.current) === null || _commonChatRef$curren3 === void 0 ? void 0 : _commonChatRef$curren3.conversationId) || null,
14
- inputEditor: ((_commonChatRef$curren4 = commonChatRef.current) === null || _commonChatRef$curren4 === void 0 ? void 0 : _commonChatRef$curren4.inputEditor) || null,
15
- uploadFileList: ((_commonChatRef$curren5 = commonChatRef.current) === null || _commonChatRef$curren5 === void 0 ? void 0 : _commonChatRef$curren5.uploadFileList) || []
10
+ get messageList() {
11
+ var _commonChatRef$curren;
12
+ return ((_commonChatRef$curren = commonChatRef.current) === null || _commonChatRef$curren === void 0 ? void 0 : _commonChatRef$curren.messageList) || [];
13
+ },
14
+ get agentDetail() {
15
+ var _commonChatRef$curren2;
16
+ return ((_commonChatRef$curren2 = commonChatRef.current) === null || _commonChatRef$curren2 === void 0 ? void 0 : _commonChatRef$curren2.agentDetail) || {};
17
+ },
18
+ get conversationId() {
19
+ var _commonChatRef$curren3;
20
+ return ((_commonChatRef$curren3 = commonChatRef.current) === null || _commonChatRef$curren3 === void 0 ? void 0 : _commonChatRef$curren3.conversationId) || null;
21
+ },
22
+ get inputEditor() {
23
+ var _commonChatRef$curren4;
24
+ return ((_commonChatRef$curren4 = commonChatRef.current) === null || _commonChatRef$curren4 === void 0 ? void 0 : _commonChatRef$curren4.inputEditor) || null;
25
+ },
26
+ get uploadFileList() {
27
+ var _commonChatRef$curren5;
28
+ return ((_commonChatRef$curren5 = commonChatRef.current) === null || _commonChatRef$curren5 === void 0 ? void 0 : _commonChatRef$curren5.uploadFileList) || [];
29
+ }
16
30
  };
17
31
  });
18
32
  return /*#__PURE__*/React.createElement(Provider, {
@@ -6,7 +6,7 @@ export declare const retryWithExponentialBackoff: <T>(fn: () => Promise<T>, opti
6
6
  factor: number;
7
7
  onRetry?: ((attempt: number) => void) | undefined;
8
8
  }) => Promise<T | undefined>;
9
- export declare const useGimiFileUpload: () => {
9
+ export declare const useGimiFileUpload: (onFileUploaded?: ((file: FileItem) => void) | undefined) => {
10
10
  fileUploadAbortRef: import("react").MutableRefObject<AbortController | null>;
11
11
  handleSSEFileAnalyize: (file: FileItem, autoRetry?: boolean) => void;
12
12
  fileUpload: (file: any, autoRetry?: boolean) => void;
@@ -82,7 +82,7 @@ var parseStrToObj = function parseStrToObj(value) {
82
82
  }
83
83
  return result;
84
84
  };
85
- export var useGimiFileUpload = function useGimiFileUpload() {
85
+ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
86
86
  var abortControllerRef = useRef(null);
87
87
  var token = useSelector(function (state) {
88
88
  return state.gimiMenu.token;
@@ -155,6 +155,13 @@ export var useGimiFileUpload = function useGimiFileUpload() {
155
155
  dispatch(setFileList({
156
156
  fileList: newFileList
157
157
  }));
158
+ // 解析成功后调用回调函数
159
+ if (onFileUploaded && data.statusCode === 'Success') {
160
+ onFileUploaded(_objectSpread(_objectSpread({}, file), {}, {
161
+ status: data.statusCode === 'Success' ? FileStatus.ANALYSE_SUCCESS : FileStatus.PADDING,
162
+ content: data.statusCode === 'Success' ? data.mdContent : ''
163
+ }));
164
+ }
158
165
  if (data.statusCode === 'Success') {
159
166
  resolve();
160
167
  }
@@ -41,6 +41,7 @@ export interface IAIInputProps {
41
41
  onConversationCreated?: (conversationId: number) => void;
42
42
  onSendEnd?: (message: IChatMessageItem) => void;
43
43
  onMicHangUp?: () => void;
44
+ onFileUploaded?: (file: FileItem) => void;
44
45
  enableVoiceRecord?: boolean;
45
46
  enableVoiceChat?: boolean;
46
47
  enableFileUpload?: boolean;