@myun/gimi-chat 0.3.2 → 0.3.3
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.
- package/dist/components/templates/CommonChat.js +16 -1
- package/dist/hooks/useChatMessage.d.ts +3 -2
- package/dist/hooks/useChatMessage.js +7 -3
- package/dist/hooks/useCommonChatAPI.d.ts +15 -1
- package/dist/hooks/useCommonChatAPI.js +20 -4
- package/dist/types/chat.d.ts +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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:
|
|
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
|
|
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:
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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决定是否添加用户消息到列表
|
package/dist/types/chat.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export interface CommonChatProps {
|
|
|
99
99
|
token?: string;
|
|
100
100
|
showHeader?: boolean;
|
|
101
101
|
initSendValue?: string;
|
|
102
|
+
initAttachments?: FileItem[];
|
|
102
103
|
chatInputConfig?: IAIInputProps;
|
|
103
104
|
platform?: 'myun' | 'preview' | 'damai';
|
|
104
105
|
businessType: 'correction' | 'chat';
|