@myun/gimi-chat 0.5.0 → 0.5.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.
- package/dist/components/chat-input/index.d.ts +1 -0
- package/dist/components/chat-input/index.js +3 -1
- package/dist/components/templates/CommonChat.js +9 -4
- package/dist/hooks/useCommonChatAPI.d.ts +1 -0
- package/dist/hooks/useCommonChatAPI.js +17 -18
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -40,6 +40,7 @@ interface IAIInputProps {
|
|
|
40
40
|
duration: number;
|
|
41
41
|
};
|
|
42
42
|
onFileUploaded?: (file: FileItem) => void;
|
|
43
|
+
onValueChange?: (value: string) => void;
|
|
43
44
|
}
|
|
44
45
|
declare const ChatInput: React.ForwardRefExoticComponent<IAIInputProps & React.RefAttributes<ChatInputRef>>;
|
|
45
46
|
export default ChatInput;
|
|
@@ -128,6 +128,7 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
128
128
|
};
|
|
129
129
|
});
|
|
130
130
|
var onContentChange = React.useCallback(function (content) {
|
|
131
|
+
var _props$onValueChange;
|
|
131
132
|
var value = extractText(content);
|
|
132
133
|
if (value.length > 10000) {
|
|
133
134
|
var _inputRef$current4;
|
|
@@ -137,7 +138,8 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
137
138
|
}
|
|
138
139
|
setHasContent(value.trim().length > 0);
|
|
139
140
|
preInputValueRef.current = value;
|
|
140
|
-
|
|
141
|
+
(_props$onValueChange = props.onValueChange) === null || _props$onValueChange === void 0 || _props$onValueChange.call(props, value);
|
|
142
|
+
}, [props]);
|
|
141
143
|
React.useEffect(function () {
|
|
142
144
|
var element = inputWrapRef.current;
|
|
143
145
|
if (!element) return;
|
|
@@ -56,6 +56,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
56
56
|
return state.gimiMenu.agentObj;
|
|
57
57
|
});
|
|
58
58
|
var chatUI = useChatUI();
|
|
59
|
+
var inputValueRef = React.useRef('');
|
|
59
60
|
var _useChatVoice = useChatVoice(),
|
|
60
61
|
isRecording = _useChatVoice.isRecording,
|
|
61
62
|
recordingCount = _useChatVoice.recordingCount,
|
|
@@ -78,7 +79,8 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
78
79
|
chatInputConfig: chatInputConfig,
|
|
79
80
|
autoSendValue: props.autoSendValue,
|
|
80
81
|
initAttachments: props.initAttachments,
|
|
81
|
-
initSendValue: props.initSendValue
|
|
82
|
+
initSendValue: props.initSendValue,
|
|
83
|
+
inputValue: inputValueRef.current
|
|
82
84
|
};
|
|
83
85
|
}, [containerRef, platform, stopTTSByText, isPlaying, agentId, props]);
|
|
84
86
|
var _useCommonChatAPI = useCommonChatAPI(hookParams),
|
|
@@ -156,6 +158,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
156
158
|
};
|
|
157
159
|
var handleInputSend = React.useCallback(function (val, agent, isSystemAuto) {
|
|
158
160
|
var _chatInputRef$current;
|
|
161
|
+
// 清空输入框
|
|
159
162
|
(_chatInputRef$current = chatInputRef.current) === null || _chatInputRef$current === void 0 || _chatInputRef$current.setValue('');
|
|
160
163
|
var conversationId = store.getState().gimiMenu.conversationId;
|
|
161
164
|
if (!conversationId) {
|
|
@@ -169,6 +172,9 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
169
172
|
var showTitleSlot = React.useMemo(function () {
|
|
170
173
|
return messageList.length > 0 || (agentObj === null || agentObj === void 0 ? void 0 : agentObj.showNameStatus) !== 1 ? '' : (agentObj === null || agentObj === void 0 ? void 0 : agentObj.showName) || '';
|
|
171
174
|
}, [messageList, agentObj]);
|
|
175
|
+
var onInputValueChange = React.useCallback(function (value) {
|
|
176
|
+
inputValueRef.current = value;
|
|
177
|
+
}, []);
|
|
172
178
|
return /*#__PURE__*/React.createElement("div", {
|
|
173
179
|
className: styles.main,
|
|
174
180
|
id: "myun_gimi_design_chat"
|
|
@@ -218,9 +224,8 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
218
224
|
placeholder: (agentObj === null || agentObj === void 0 ? void 0 : agentObj.inputPrompt) || '',
|
|
219
225
|
defaultPrompt: messageList.length > 0 ? '' : (agentObj === null || agentObj === void 0 ? void 0 : agentObj.defaultPrompt) || '',
|
|
220
226
|
titleSlot: showTitleSlot,
|
|
221
|
-
showDefaultPrompt: messageList.length === 0
|
|
222
|
-
|
|
223
|
-
,
|
|
227
|
+
showDefaultPrompt: messageList.length === 0,
|
|
228
|
+
onValueChange: onInputValueChange,
|
|
224
229
|
onInterrupt: handleInterrupt,
|
|
225
230
|
isRecording: isRecording,
|
|
226
231
|
isVoiceGetting: isExecuting,
|
|
@@ -45,7 +45,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
45
45
|
chatInputConfig = props.chatInputConfig,
|
|
46
46
|
autoSendValue = props.autoSendValue,
|
|
47
47
|
initAttachments = props.initAttachments,
|
|
48
|
-
initSendValue = props.initSendValue
|
|
48
|
+
initSendValue = props.initSendValue,
|
|
49
|
+
inputValue = props.inputValue;
|
|
49
50
|
var _useContext = useContext(ChatContext),
|
|
50
51
|
apiService = _useContext.apiService;
|
|
51
52
|
var _ref = apiService,
|
|
@@ -78,7 +79,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
78
79
|
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
79
80
|
status = _React$useState8[0],
|
|
80
81
|
setStatus = _React$useState8[1]; // 0 没输入内容 1 正在输入 2 ai正在回复 3 ai即将回复
|
|
81
|
-
|
|
82
|
+
|
|
82
83
|
var vipLevelRef = React.useRef(null);
|
|
83
84
|
var step = React.useRef(0); // 接口请求step
|
|
84
85
|
var controllerRef = React.useRef(null); // 发起对话接口controller
|
|
@@ -306,7 +307,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
306
307
|
});
|
|
307
308
|
setIgnoreOnMessage(true);
|
|
308
309
|
removeLastEventId("".concat(messageList[messageList.length - 1].chatId));
|
|
309
|
-
if (
|
|
310
|
+
if (inputValue) {
|
|
310
311
|
setStatus(1);
|
|
311
312
|
} else {
|
|
312
313
|
setStatus(0);
|
|
@@ -413,7 +414,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
413
414
|
timer: null
|
|
414
415
|
};
|
|
415
416
|
} else {
|
|
416
|
-
if (
|
|
417
|
+
if (inputValue) {
|
|
417
418
|
setStatus(1);
|
|
418
419
|
} else {
|
|
419
420
|
setStatus(0);
|
|
@@ -454,18 +455,18 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
454
455
|
if (type === 'ask' || type === 'skill') {
|
|
455
456
|
scrollBottomForce();
|
|
456
457
|
}
|
|
457
|
-
setMsgLoading(true);
|
|
458
458
|
|
|
459
459
|
// 获取最新的agent详情,防止redux异步更新
|
|
460
|
-
agentDetail = agentInfo || agentObjRef.current;
|
|
460
|
+
agentDetail = agentInfo || agentObjRef.current; // 获取推荐追问
|
|
461
461
|
if (!((agentDetail === null || agentDetail === void 0 ? void 0 : agentDetail.isEnableRelated) === 1 && (type === 'end' || type === 'COMPLETED'))) {
|
|
462
462
|
_context4.next = 10;
|
|
463
463
|
break;
|
|
464
464
|
}
|
|
465
|
+
setMsgLoading(true);
|
|
465
466
|
_context4.next = 10;
|
|
466
467
|
return getRecommendList(newMessageList, lastId, statusRef.current);
|
|
467
468
|
case 10:
|
|
468
|
-
if (
|
|
469
|
+
if (inputValue) {
|
|
469
470
|
setStatus(1);
|
|
470
471
|
} else {
|
|
471
472
|
setStatus(0);
|
|
@@ -495,7 +496,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
495
496
|
dispatch(setMessageList({
|
|
496
497
|
messageList: newMessageList
|
|
497
498
|
}));
|
|
498
|
-
if (
|
|
499
|
+
if (inputValue) {
|
|
499
500
|
setStatus(1);
|
|
500
501
|
} else {
|
|
501
502
|
setStatus(0);
|
|
@@ -512,7 +513,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
512
513
|
return function (_x7, _x8) {
|
|
513
514
|
return _ref6.apply(this, arguments);
|
|
514
515
|
};
|
|
515
|
-
}(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList, onSendEnd]);
|
|
516
|
+
}(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList, onSendEnd, inputValue]);
|
|
516
517
|
var regenerate = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
517
518
|
var res, retryId, newMessageList;
|
|
518
519
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
@@ -733,7 +734,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
733
734
|
} else {
|
|
734
735
|
Toast.error(responseMsg.message);
|
|
735
736
|
setMsgLoading(false);
|
|
736
|
-
if (
|
|
737
|
+
if (inputValue) {
|
|
737
738
|
setStatus(1);
|
|
738
739
|
} else {
|
|
739
740
|
setStatus(0);
|
|
@@ -747,7 +748,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
747
748
|
_context8.t0 = _context8["catch"](10);
|
|
748
749
|
if (_context8.t0.name === 'AbortError') {
|
|
749
750
|
setMsgLoading(false);
|
|
750
|
-
if (
|
|
751
|
+
if (inputValue) {
|
|
751
752
|
setStatus(1);
|
|
752
753
|
} else {
|
|
753
754
|
setStatus(0);
|
|
@@ -755,7 +756,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
755
756
|
} else {
|
|
756
757
|
Toast.error('网络异常');
|
|
757
758
|
setMsgLoading(false);
|
|
758
|
-
if (
|
|
759
|
+
if (inputValue) {
|
|
759
760
|
setStatus(1);
|
|
760
761
|
} else {
|
|
761
762
|
setStatus(0);
|
|
@@ -840,7 +841,6 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
840
841
|
// 点击发送按钮时,先停止播放
|
|
841
842
|
stopTTSByText === null || stopTTSByText === void 0 || stopTTSByText();
|
|
842
843
|
}
|
|
843
|
-
valueRef.current = '';
|
|
844
844
|
cleanVal = filterPropmptFromUserInput(agent.defaultPrompt, val);
|
|
845
845
|
userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current), initAttachmentsRef.current);
|
|
846
846
|
vipLevelRef.current = null;
|
|
@@ -867,7 +867,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
867
867
|
// 系统自动上传,直接开始会话,不更新列表
|
|
868
868
|
startChat([].concat(_toConsumableArray(prevChatList), [userChat]), isSystemAuto, conversationId);
|
|
869
869
|
}
|
|
870
|
-
case
|
|
870
|
+
case 24:
|
|
871
871
|
case "end":
|
|
872
872
|
return _context9.stop();
|
|
873
873
|
}
|
|
@@ -1086,7 +1086,6 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
1086
1086
|
Toast.error('AI正在输出中,请稍后');
|
|
1087
1087
|
return;
|
|
1088
1088
|
}
|
|
1089
|
-
valueRef.current = '';
|
|
1090
1089
|
setMsgLoading(true);
|
|
1091
1090
|
startChat(messageList, false, undefined, true);
|
|
1092
1091
|
}, [startChat, status, msgLoading]);
|
|
@@ -1167,9 +1166,9 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
1167
1166
|
} else if (chatItem.mcp && !chatItem.content && !chatItem.reasoningContent) {
|
|
1168
1167
|
// mcp工具调用中,但没有end输出时,不能被终止
|
|
1169
1168
|
setDisableSend(true);
|
|
1170
|
-
} else {
|
|
1171
|
-
setDisableSend(false);
|
|
1172
1169
|
}
|
|
1170
|
+
} else {
|
|
1171
|
+
setDisableSend(false);
|
|
1173
1172
|
}
|
|
1174
1173
|
if ((messageList === null || messageList === void 0 ? void 0 : messageList.length) > 0) {
|
|
1175
1174
|
var _chatItem$moduleInfo3;
|
|
@@ -1230,7 +1229,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
1230
1229
|
} else {
|
|
1231
1230
|
var _controllerRef$curren2;
|
|
1232
1231
|
(_controllerRef$curren2 = controllerRef.current) === null || _controllerRef$curren2 === void 0 || _controllerRef$curren2.abort();
|
|
1233
|
-
if (
|
|
1232
|
+
if (inputValue) {
|
|
1234
1233
|
setStatus(1);
|
|
1235
1234
|
} else {
|
|
1236
1235
|
setStatus(0);
|