@myun/gimi-chat 0.3.2 → 0.3.4

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.
@@ -62,7 +62,22 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
62
62
  playTTSByText = _useChatVoice.playTTSByText,
63
63
  stopTTSByText = _useChatVoice.stopTTSByText,
64
64
  isPlaying = _useChatVoice.isPlaying;
65
- var _useCommonChatAPI = useCommonChatAPI(containerRef, platform, stopTTSByText, isPlaying, agentId, props.reloadAgentKey, props.resetKey, props.interruptKey, props.chatInputConfig, props.initSendValue),
65
+ var hookParams = React.useMemo(function () {
66
+ return {
67
+ containerRef: containerRef,
68
+ platform: platform,
69
+ stopTTSByText: stopTTSByText,
70
+ isPlaying: isPlaying,
71
+ agentId: agentId,
72
+ reloadAgentKey: props.reloadAgentKey,
73
+ resetKey: props.resetKey,
74
+ interruptKey: props.interruptKey,
75
+ chatInputConfig: chatInputConfig,
76
+ initSendValue: props.initSendValue,
77
+ initAttachments: props.initAttachments
78
+ };
79
+ }, [containerRef, platform, stopTTSByText, isPlaying, agentId, props]);
80
+ var _useCommonChatAPI = useCommonChatAPI(hookParams),
66
81
  headerValue = _useCommonChatAPI.headerValue,
67
82
  msgLoading = _useCommonChatAPI.msgLoading,
68
83
  onSucessExcel = _useCommonChatAPI.onSucessExcel,
@@ -1,8 +1,9 @@
1
+ import { FileItem } from '../types/file';
1
2
  /**
2
3
  * 管理聊天消息的创建和格式化
3
4
  */
4
5
  export declare const useChatMessage: () => {
5
- createUserChat: (val: string, conversationId: string) => {
6
+ createUserChat: (val: string, conversationId: string, attachments?: FileItem[]) => {
6
7
  quoteProductList?: {
7
8
  productId: number;
8
9
  productName: string;
@@ -22,7 +23,7 @@ export declare const useChatMessage: () => {
22
23
  role: number;
23
24
  sectionId: string;
24
25
  type: number;
25
- messageFiles: import("../types/file").FileItem | null;
26
+ messageFiles: FileItem | null;
26
27
  };
27
28
  createAiChat: (result: any) => {
28
29
  role: number;
@@ -29,8 +29,12 @@ export var useChatMessage = function useChatMessage() {
29
29
  /**
30
30
  * 创建用户消息对象
31
31
  */
32
- var createUserChat = React.useCallback(function (val, conversationId) {
33
- var _fileListRef$current, _quoteTeachModelListR, _quoteProductListRef$;
32
+ var createUserChat = React.useCallback(function (val, conversationId, attachments) {
33
+ var _quoteTeachModelListR, _quoteProductListRef$;
34
+ var messageFiles = fileListRef.current || [];
35
+ if (attachments && attachments.length > 0) {
36
+ messageFiles = attachments;
37
+ }
34
38
  return _objectSpread(_objectSpread({
35
39
  id: +new Date(),
36
40
  content: val,
@@ -42,7 +46,7 @@ export var useChatMessage = function useChatMessage() {
42
46
  role: 0,
43
47
  sectionId: '1',
44
48
  type: 0,
45
- messageFiles: ((_fileListRef$current = fileListRef.current) === null || _fileListRef$current === void 0 ? void 0 : _fileListRef$current.length) > 0 ? fileListRef.current[0] : null
49
+ messageFiles: messageFiles.length > 0 ? messageFiles[0] : null
46
50
  }, ((_quoteTeachModelListR = quoteTeachModelListRef.current) === null || _quoteTeachModelListR === void 0 ? void 0 : _quoteTeachModelListR.length) > 0 && {
47
51
  quoteTeachModelList: quoteTeachModelListRef.current
48
52
  }), ((_quoteProductListRef$ = quoteProductListRef.current) === null || _quoteProductListRef$ === void 0 ? void 0 : _quoteProductListRef$.length) > 0 && {
@@ -1,6 +1,20 @@
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, initSendValue?: string) => {
3
+ import { FileItem } from "../types/file";
4
+ interface IHookProps {
5
+ containerRef: React.RefObject<HTMLDivElement>;
6
+ platform: string;
7
+ stopTTSByText?: () => void;
8
+ isPlaying?: boolean;
9
+ agentId?: number;
10
+ reloadAgentKey?: string;
11
+ resetKey?: string;
12
+ interruptKey?: string;
13
+ chatInputConfig?: IAIInputProps;
14
+ initSendValue?: string;
15
+ initAttachments?: FileItem[];
16
+ }
17
+ declare const useCommonChatAPI: (props: IHookProps) => {
4
18
  headerValue: string;
5
19
  getHeaderValue: (conversationId: number) => Promise<void>;
6
20
  msgLoading: boolean;
@@ -32,7 +32,18 @@ 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, initSendValue) {
35
+ var useCommonChatAPI = function useCommonChatAPI(props) {
36
+ var containerRef = props.containerRef,
37
+ platform = props.platform,
38
+ stopTTSByText = props.stopTTSByText,
39
+ isPlaying = props.isPlaying,
40
+ agentId = props.agentId,
41
+ reloadAgentKey = props.reloadAgentKey,
42
+ resetKey = props.resetKey,
43
+ interruptKey = props.interruptKey,
44
+ chatInputConfig = props.chatInputConfig,
45
+ initSendValue = props.initSendValue,
46
+ initAttachments = props.initAttachments;
36
47
  var _useApi = useApi(),
37
48
  getMessageTitle = _useApi.getMessageTitle,
38
49
  stopStreamOut = _useApi.stopStreamOut,
@@ -41,7 +52,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
41
52
  deleteConversationById = _useApi.deleteConversationById,
42
53
  getAiCorrection = _useApi.getAiCorrection,
43
54
  checkRetry = _useApi.checkRetry;
44
- var _ref = chatInputConfig || {},
55
+ var _ref = props.chatInputConfig || {},
45
56
  onFirstSendSuccess = _ref.onFirstSendSuccess,
46
57
  onSendSuccess = _ref.onSendSuccess,
47
58
  onSendEnd = _ref.onSendEnd,
@@ -141,6 +152,8 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
141
152
  var resetKeyRef = useRef(resetKey || '');
142
153
  // 中断key ref
143
154
  var interruptKeyRef = useRef(interruptKey || '');
155
+ // onFirstSendSuccess 是否已经执行过
156
+ var onFirstSendSuccessCalledRef = useRef(false);
144
157
 
145
158
  // 更细Ref的值
146
159
  messageListRef.current = messageList;
@@ -937,7 +950,10 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
937
950
  case 24:
938
951
  responseMsg = _context13.sent;
939
952
  // 执行使用方定义的回调函数
940
- onFirstSendSuccess === null || onFirstSendSuccess === void 0 || onFirstSendSuccess();
953
+ if (!onFirstSendSuccessCalledRef.current) {
954
+ onFirstSendSuccess === null || onFirstSendSuccess === void 0 || onFirstSendSuccess();
955
+ onFirstSendSuccessCalledRef.current = true;
956
+ }
941
957
  onSendSuccess === null || onSendSuccess === void 0 || onSendSuccess();
942
958
 
943
959
  // 清空发送时的引用
@@ -1190,7 +1206,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1190
1206
  }
1191
1207
  valueRef.current = '';
1192
1208
  cleanVal = filterPropmptFromUserInput(agent.defaultPrompt, val);
1193
- userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current));
1209
+ userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current), initAttachments);
1194
1210
  vipLevelRef.current = null;
1195
1211
 
1196
1212
  // 根据isSystemAuto决定是否添加用户消息到列表
@@ -1224,7 +1240,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1224
1240
  return function (_x26) {
1225
1241
  return _ref17.apply(this, arguments);
1226
1242
  };
1227
- }(), [dispatch, startChat, chatInputConfig === null || chatInputConfig === void 0 ? void 0 : chatInputConfig.onBeforeSend]);
1243
+ }(), [dispatch, startChat, chatInputConfig === null || chatInputConfig === void 0 ? void 0 : chatInputConfig.onBeforeSend, initAttachments]);
1228
1244
  var handleSendFile = React.useCallback(function (messageList) {
1229
1245
  if (!navigator.onLine) {
1230
1246
  Toast.error('无法连接到网络');
@@ -7,6 +7,20 @@ export interface ChatInputRef {
7
7
  blur: () => void;
8
8
  }
9
9
 
10
+ export type FileItem = {
11
+ uid: string;
12
+ name: string;
13
+ size: string;
14
+ status: FileStatus;
15
+ fileUrl?: string;
16
+ fileName?: string; // 后端返回的文件名(可选)
17
+ fileSize?: number; // 后端返回的文件大小(可选)
18
+ fileType?: string; // 后端返回的文件类型(可选)
19
+ fileId?: string; // 后端返回的文件ID(可选)
20
+ fileToken?: string; // 关键!后端返回的文件标识,用于SSE调用
21
+ content?: string; // SSE返回的内容
22
+ }
23
+
10
24
  export interface CommonChatRef {
11
25
  messageList: IChatMessageItem[];
12
26
  agentDetail?: AgentConfig;
@@ -99,6 +113,7 @@ export interface CommonChatProps {
99
113
  token?: string;
100
114
  showHeader?: boolean;
101
115
  initSendValue?: string;
116
+ initAttachments?: FileItem[];
102
117
  chatInputConfig?: IAIInputProps;
103
118
  platform?: 'myun' | 'preview' | 'damai';
104
119
  businessType: 'correction' | 'chat';