@myun/gimi-chat 0.3.1 → 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/chat-input/index.js +1 -2
- 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 +27 -8
- package/dist/types/chat.d.ts +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -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$
|
|
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 () {
|
|
@@ -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
|
// 清空发送时的引用
|
|
@@ -1132,6 +1148,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1132
1148
|
}, []);
|
|
1133
1149
|
var handleSend = React.useCallback( /*#__PURE__*/function () {
|
|
1134
1150
|
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(val) {
|
|
1151
|
+
var _chatInputConfig$onBe;
|
|
1135
1152
|
var agent,
|
|
1136
1153
|
isSystemAuto,
|
|
1137
1154
|
conversationId,
|
|
@@ -1171,23 +1188,25 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1171
1188
|
Toast.error('AI正在输出中,请稍后');
|
|
1172
1189
|
return _context16.abrupt("return");
|
|
1173
1190
|
case 12:
|
|
1191
|
+
chatInputConfig === null || chatInputConfig === void 0 || (_chatInputConfig$onBe = chatInputConfig.onBeforeSend) === null || _chatInputConfig$onBe === void 0 || _chatInputConfig$onBe.call(chatInputConfig, value);
|
|
1192
|
+
|
|
1174
1193
|
// 设置inputModel
|
|
1175
1194
|
fillInputModel(value, messageListRef.current);
|
|
1176
1195
|
fileValidationMsg = fileValidation(fileListRef.current);
|
|
1177
1196
|
if (!fileValidationMsg) {
|
|
1178
|
-
_context16.next =
|
|
1197
|
+
_context16.next = 18;
|
|
1179
1198
|
break;
|
|
1180
1199
|
}
|
|
1181
1200
|
Toast.error(fileValidationMsg);
|
|
1182
1201
|
return _context16.abrupt("return");
|
|
1183
|
-
case
|
|
1202
|
+
case 18:
|
|
1184
1203
|
if (isPlaying) {
|
|
1185
1204
|
// 点击发送按钮时,先停止播放
|
|
1186
1205
|
stopTTSByText === null || stopTTSByText === void 0 || stopTTSByText();
|
|
1187
1206
|
}
|
|
1188
1207
|
valueRef.current = '';
|
|
1189
1208
|
cleanVal = filterPropmptFromUserInput(agent.defaultPrompt, val);
|
|
1190
|
-
userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current));
|
|
1209
|
+
userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current), initAttachments);
|
|
1191
1210
|
vipLevelRef.current = null;
|
|
1192
1211
|
|
|
1193
1212
|
// 根据isSystemAuto决定是否添加用户消息到列表
|
|
@@ -1212,7 +1231,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1212
1231
|
// 系统自动上传,直接开始会话,不更新列表
|
|
1213
1232
|
startChat([].concat(_toConsumableArray(prevChatList), [userChat]), isSystemAuto, conversationId);
|
|
1214
1233
|
}
|
|
1215
|
-
case
|
|
1234
|
+
case 25:
|
|
1216
1235
|
case "end":
|
|
1217
1236
|
return _context16.stop();
|
|
1218
1237
|
}
|
|
@@ -1221,7 +1240,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
|
|
|
1221
1240
|
return function (_x26) {
|
|
1222
1241
|
return _ref17.apply(this, arguments);
|
|
1223
1242
|
};
|
|
1224
|
-
}(), [dispatch, startChat]);
|
|
1243
|
+
}(), [dispatch, startChat, chatInputConfig === null || chatInputConfig === void 0 ? void 0 : chatInputConfig.onBeforeSend]);
|
|
1225
1244
|
var handleSendFile = React.useCallback(function (messageList) {
|
|
1226
1245
|
if (!navigator.onLine) {
|
|
1227
1246
|
Toast.error('无法连接到网络');
|
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';
|