@myun/gimi-chat 0.9.76 → 0.9.78
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/answer-item/component/tool-list/index.js +39 -8
- package/dist/components/answer-item/component/tool-list/index.module.css +0 -3
- package/dist/components/answer-item/index.js +5 -2
- package/dist/components/chat-input/index.js +3 -2
- package/dist/hooks/useChatStream.js +2 -1
- package/dist/hooks/useCommonChatAPI.js +56 -28
- package/dist/i18n/locales/en-US.d.ts +1 -0
- package/dist/i18n/locales/en-US.js +1 -0
- package/dist/i18n/locales/zh-CN.d.ts +1 -0
- package/dist/i18n/locales/zh-CN.js +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -8,13 +8,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
8
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
9
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
-
import React, { useEffect, useMemo, useState } from "react";
|
|
11
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
12
12
|
import { MMarkdown } from '@myun/gimi-design';
|
|
13
13
|
import IconFont from "../../../iconfont-com";
|
|
14
14
|
import FileUpload from "../../../file-upload";
|
|
15
15
|
import styles from "./index.module.css";
|
|
16
16
|
import classNames from "classnames";
|
|
17
17
|
import { useTranslation } from "react-i18next";
|
|
18
|
+
import { useAppSelector } from "../../../../store/hooks";
|
|
19
|
+
import useScroll from "../../../../hooks/useScroll";
|
|
18
20
|
|
|
19
21
|
// 思考工具项组件
|
|
20
22
|
var ThinkingToolItem = function ThinkingToolItem(_ref) {
|
|
@@ -28,12 +30,22 @@ var ThinkingToolItem = function ThinkingToolItem(_ref) {
|
|
|
28
30
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
29
31
|
manual = _useState4[0],
|
|
30
32
|
setManual = _useState4[1]; // 用户是否手动操作过,手动后不再被状态覆盖
|
|
31
|
-
|
|
33
|
+
var contentRef = useRef(null);
|
|
34
|
+
var _useScroll = useScroll(contentRef),
|
|
35
|
+
_useScroll2 = _slicedToArray(_useScroll, 1),
|
|
36
|
+
throttledScrollToBottom = _useScroll2[0];
|
|
32
37
|
useEffect(function () {
|
|
33
38
|
if (!manual) {
|
|
34
39
|
setShowContent(item.status !== "COMPLETED");
|
|
35
40
|
}
|
|
36
41
|
}, [item.status, manual]);
|
|
42
|
+
|
|
43
|
+
// 内容更新 / 展开时滚动到底部
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
if (showContent) {
|
|
46
|
+
throttledScrollToBottom();
|
|
47
|
+
}
|
|
48
|
+
}, [item.content, showContent]);
|
|
37
49
|
var handleToggle = function handleToggle() {
|
|
38
50
|
setManual(true);
|
|
39
51
|
setShowContent(function (v) {
|
|
@@ -60,7 +72,8 @@ var ThinkingToolItem = function ThinkingToolItem(_ref) {
|
|
|
60
72
|
color: !showContent ? "var(--theme-neutral, #626262)" : "var(--theme-mediumNeutral, #B3B2B2)"
|
|
61
73
|
}
|
|
62
74
|
})), item.content && showContent && /*#__PURE__*/React.createElement("div", {
|
|
63
|
-
className: styles.toolItemContent
|
|
75
|
+
className: styles.toolItemContent,
|
|
76
|
+
ref: contentRef
|
|
64
77
|
}, /*#__PURE__*/React.createElement(MMarkdown, {
|
|
65
78
|
content: item.content,
|
|
66
79
|
customRender: customRender,
|
|
@@ -162,8 +175,15 @@ var AskToolItem = function AskToolItem(_ref4) {
|
|
|
162
175
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
163
176
|
showContent = _useState8[0],
|
|
164
177
|
setShowContent = _useState8[1];
|
|
178
|
+
var _useState9 = useState(false),
|
|
179
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
180
|
+
uploadDisabled = _useState10[0],
|
|
181
|
+
setUploadDisabled = _useState10[1];
|
|
165
182
|
var _useTranslation = useTranslation(),
|
|
166
183
|
t = _useTranslation.t;
|
|
184
|
+
var fileList = useAppSelector(function (state) {
|
|
185
|
+
return state.gimiMenu.fileList;
|
|
186
|
+
});
|
|
167
187
|
var askTextMap = {
|
|
168
188
|
RUNNING: "等待人工确认",
|
|
169
189
|
COMPLETED: "用户已确认"
|
|
@@ -190,10 +210,15 @@ var AskToolItem = function AskToolItem(_ref4) {
|
|
|
190
210
|
detailInfo = _React$useMemo.detailInfo,
|
|
191
211
|
optionsList = _React$useMemo.optionsList,
|
|
192
212
|
questionContent = _React$useMemo.questionContent;
|
|
193
|
-
|
|
213
|
+
useEffect(function () {
|
|
194
214
|
var isAnswered = item.status === 'ANSWERED' || item.confirmStatus === 'CONFIRMED';
|
|
195
215
|
setDisabled(Boolean(isAnswered));
|
|
196
216
|
}, [item.confirmStatus, item.status]);
|
|
217
|
+
useEffect(function () {
|
|
218
|
+
setUploadDisabled((fileList === null || fileList === void 0 ? void 0 : fileList.findIndex(function (v) {
|
|
219
|
+
return (v === null || v === void 0 ? void 0 : v.status) === "uploading" || (v === null || v === void 0 ? void 0 : v.status) === "padding";
|
|
220
|
+
})) !== -1);
|
|
221
|
+
}, [fileList]);
|
|
197
222
|
var onAskItemClick = function onAskItemClick(key, value) {
|
|
198
223
|
if (disabled) return;
|
|
199
224
|
setDisabled(true);
|
|
@@ -238,13 +263,19 @@ var AskToolItem = function AskToolItem(_ref4) {
|
|
|
238
263
|
}, optionRender(v));
|
|
239
264
|
})), detailInfo.uploadFile && detailInfo.answerType === 0 && /*#__PURE__*/React.createElement("div", {
|
|
240
265
|
className: classNames(styles.showUpload)
|
|
241
|
-
}, /*#__PURE__*/React.createElement(FileUpload,
|
|
242
|
-
|
|
266
|
+
}, /*#__PURE__*/React.createElement(FileUpload, {
|
|
267
|
+
disabled: uploadDisabled
|
|
268
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
269
|
+
className: classNames(styles.uploadIcon, uploadDisabled ? styles.disableFile : '')
|
|
243
270
|
}, /*#__PURE__*/React.createElement(IconFont, {
|
|
244
271
|
type: "icon-shurukuang-webtianjia",
|
|
245
272
|
size: 26,
|
|
246
|
-
color: 'var(--theme-deepNeutral, #2E394C)'
|
|
247
|
-
}), /*#__PURE__*/React.createElement("span",
|
|
273
|
+
color: uploadDisabled ? 'var(--theme-softNeutral, #D9DCE5)' : 'var(--theme-deepNeutral, #2E394C)'
|
|
274
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
275
|
+
style: uploadDisabled ? {
|
|
276
|
+
color: "var(--theme-softNeutral, #D9DCE5)"
|
|
277
|
+
} : {}
|
|
278
|
+
}, uploadDisabled ? t('askCard.uploading') : t('askCard.fileUpload')))))) : item.content && showContent && /*#__PURE__*/React.createElement("div", {
|
|
248
279
|
className: styles.toolItemContent
|
|
249
280
|
}, /*#__PURE__*/React.createElement(MMarkdown, {
|
|
250
281
|
content: item.content
|
|
@@ -171,12 +171,9 @@
|
|
|
171
171
|
}
|
|
172
172
|
.showUpload .disableFile {
|
|
173
173
|
border-radius: 22px;
|
|
174
|
-
border: 1px solid var(--theme-softNeutral, #D9DCE5);
|
|
175
174
|
background: #fff;
|
|
176
175
|
color: #ced3d9;
|
|
177
|
-
font-family: "PingFang SC";
|
|
178
176
|
font-size: 14px;
|
|
179
|
-
font-style: normal;
|
|
180
177
|
font-weight: 600;
|
|
181
178
|
line-height: normal;
|
|
182
179
|
}
|
|
@@ -204,9 +204,9 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
204
204
|
return {
|
|
205
205
|
id: "thinking-".concat(item.id),
|
|
206
206
|
moduleType: 'thinking',
|
|
207
|
-
toolName: getToolNameByStatus('thinking', item.reasoningStatus === 1 ? 'RUNNING' : item.reasoningStatus === 2 ? 'COMPLETED' : '
|
|
207
|
+
toolName: getToolNameByStatus('thinking', item.reasoningStatus === 1 ? 'RUNNING' : item.reasoningStatus === 2 ? 'COMPLETED' : 'CANCELLED'),
|
|
208
208
|
content: item.reasoningContent,
|
|
209
|
-
status: item.reasoningStatus === 1 ? 'RUNNING' : item.reasoningStatus === 2 ? 'COMPLETED' : '
|
|
209
|
+
status: item.reasoningStatus === 1 ? 'RUNNING' : item.reasoningStatus === 2 ? 'COMPLETED' : 'CANCELLED'
|
|
210
210
|
};
|
|
211
211
|
}, [item.reasoningContent, item.reasoningStatus, item.vipLevel, item.id]);
|
|
212
212
|
|
|
@@ -300,6 +300,9 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
300
300
|
var options = (_eventData2 = eventData) === null || _eventData2 === void 0 || (_eventData2 = _eventData2.data) === null || _eventData2 === void 0 || (_eventData2 = _eventData2.results) === null || _eventData2 === void 0 || (_eventData2 = _eventData2.askShowInfo) === null || _eventData2 === void 0 ? void 0 : _eventData2.options;
|
|
301
301
|
if (clickedOptionId && options && options[clickedOptionId]) {
|
|
302
302
|
askContent = options[clickedOptionId];
|
|
303
|
+
} else {
|
|
304
|
+
var _eventData3;
|
|
305
|
+
askContent = ((_eventData3 = eventData) === null || _eventData3 === void 0 || (_eventData3 = _eventData3.data) === null || _eventData3 === void 0 ? void 0 : _eventData3.results["".concat(eventData.id, ".USER_RESPONSE")]) || '';
|
|
303
306
|
}
|
|
304
307
|
} catch (error) {}
|
|
305
308
|
newItem.content = askContent;
|
|
@@ -199,8 +199,9 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
199
199
|
// 如果有正在进行的请求,复用该 Promise
|
|
200
200
|
if (thinkingCacheRef.current.agentId === agentId && thinkingCacheRef.current.promise) {
|
|
201
201
|
thinkingCacheRef.current.promise.then(function (result) {
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
var data = result || {};
|
|
203
|
+
setDeepThinkDisabled(data.thinking !== 1);
|
|
204
|
+
setDeepThinkActive(data.thinkingEnable === 1);
|
|
204
205
|
}).catch(function (e) {
|
|
205
206
|
console.error('[deepThink] getThinkingEffective error:', e);
|
|
206
207
|
setDeepThinkDisabled(false);
|
|
@@ -34,7 +34,6 @@ import useScroll from "./useScroll";
|
|
|
34
34
|
// 获取推荐课程
|
|
35
35
|
import { useChatRecommend } from "./useChatRecommend";
|
|
36
36
|
import { set, cloneDeep } from 'lodash';
|
|
37
|
-
import { FileStatus } from "../interfaces/fileInterface";
|
|
38
37
|
import useChatHistory from "./useChatHistory";
|
|
39
38
|
var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
40
39
|
var _useTranslation = useTranslation(),
|
|
@@ -1345,46 +1344,75 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
1345
1344
|
return;
|
|
1346
1345
|
}
|
|
1347
1346
|
setMsgLoading(true);
|
|
1348
|
-
startChat(messageList, false, undefined, true);
|
|
1347
|
+
startChat(messageList, false, undefined, true, true);
|
|
1349
1348
|
}, [startChat, status]);
|
|
1350
1349
|
React.useEffect(function () {
|
|
1351
1350
|
var hasValidFile = (fileList === null || fileList === void 0 ? void 0 : fileList.length) > 0;
|
|
1352
1351
|
var messageList = messageListRef.current || [];
|
|
1353
1352
|
var lastMessage = messageList[messageList.length - 1];
|
|
1354
|
-
|
|
1353
|
+
// const targetMessage = messageList[messageList.length - 2];
|
|
1355
1354
|
if (hasValidFile && lastMessage) {
|
|
1356
|
-
setDisableSend(
|
|
1355
|
+
setDisableSend(hasValidFile);
|
|
1357
1356
|
var uploadFile = fileList[0];
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
var
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1357
|
+
|
|
1358
|
+
// 当有文件内容时处理请求
|
|
1359
|
+
if (uploadFile !== null && uploadFile !== void 0 && uploadFile.content && (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'ask') {
|
|
1360
|
+
var _lastMessage$toolList, _messageListRef$curre;
|
|
1361
|
+
var moduleInfo = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleInfo;
|
|
1362
|
+
var updatedToolList = (_lastMessage$toolList = lastMessage.toolList) === null || _lastMessage$toolList === void 0 ? void 0 : _lastMessage$toolList.map(function (tool) {
|
|
1363
|
+
return tool.status === 'RUNNING' ? _objectSpread(_objectSpread({}, tool), {}, {
|
|
1364
|
+
moduleType: "ask",
|
|
1365
|
+
status: 'COMPLETED',
|
|
1366
|
+
confirmStatus: "CONFIRMED",
|
|
1367
|
+
content: uploadFile.content
|
|
1368
|
+
}) : tool;
|
|
1369
|
+
});
|
|
1370
|
+
var updatedMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, lastMessage), {}, {
|
|
1371
|
+
toolList: updatedToolList
|
|
1365
1372
|
})]);
|
|
1366
1373
|
dispatch(setMessageList({
|
|
1367
|
-
messageList:
|
|
1374
|
+
messageList: updatedMessageList
|
|
1368
1375
|
}));
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
var _inputModel = _defineProperty({}, "".concat(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.id, ".input"), '');
|
|
1374
|
-
inputModelRef.current = _inputModel;
|
|
1375
|
-
if (((_messageListRef$curre = messageListRef.current) === null || _messageListRef$curre === void 0 ? void 0 : _messageListRef$curre.length) > 0) {
|
|
1376
|
-
handleSendFile(newMessageList);
|
|
1377
|
-
}
|
|
1376
|
+
var _inputModel = _defineProperty({}, "".concat(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.id, ".input"), '');
|
|
1377
|
+
inputModelRef.current = _inputModel;
|
|
1378
|
+
if (((_messageListRef$curre = messageListRef.current) === null || _messageListRef$curre === void 0 ? void 0 : _messageListRef$curre.length) > 0) {
|
|
1379
|
+
handleSendFile(updatedMessageList);
|
|
1378
1380
|
}
|
|
1379
|
-
} else {
|
|
1380
|
-
var _newMessageList2 = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
|
|
1381
|
-
disableUploadFile: true
|
|
1382
|
-
}), createUserChat('', "".concat(conversationIdRef.current))]);
|
|
1383
|
-
dispatch(setMessageList({
|
|
1384
|
-
messageList: _newMessageList2
|
|
1385
|
-
}));
|
|
1386
1381
|
}
|
|
1387
1382
|
}
|
|
1383
|
+
// if (hasValidFile && lastMessage) {
|
|
1384
|
+
// setDisableSend(true);
|
|
1385
|
+
// const uploadFile = fileList[0];
|
|
1386
|
+
// const isLastMessageEmptyUserChat = lastMessage?.moduleType === 'ask'; // 空内容
|
|
1387
|
+
// if (!isLastMessageEmptyUserChat) {
|
|
1388
|
+
// const shouldEnableUpload = uploadFile.status === FileStatus.UPLOAD_FAILED || uploadFile.status === FileStatus.ANALYSE_FAILED;
|
|
1389
|
+
// const newMessageList = [...messageList.slice(0, -2),
|
|
1390
|
+
// { ...messageList[messageList.length - 2], disableUploadFile: !shouldEnableUpload },
|
|
1391
|
+
// { ...messageList[messageList.length - 1], messageFiles: [uploadFile] }];
|
|
1392
|
+
// dispatch(setMessageList({ messageList: newMessageList }));
|
|
1393
|
+
// // 当有文件内容时处理请求
|
|
1394
|
+
// if (uploadFile?.content && targetMessage?.moduleType === 'ask') {
|
|
1395
|
+
// const moduleInfo = targetMessage?.moduleInfo;
|
|
1396
|
+
// const _inputModel = {
|
|
1397
|
+
// [`${moduleInfo?.id}.input`]: '',
|
|
1398
|
+
// };
|
|
1399
|
+
// inputModelRef.current = _inputModel;
|
|
1400
|
+
// if (messageListRef.current?.length > 0) {
|
|
1401
|
+
// handleSendFile(newMessageList);
|
|
1402
|
+
// }
|
|
1403
|
+
// }
|
|
1404
|
+
// } else {
|
|
1405
|
+
// // const newMessageList = [
|
|
1406
|
+
// // ...messageList.slice(0, -1),
|
|
1407
|
+
// // {
|
|
1408
|
+
// // ...messageList[messageList.length - 1],
|
|
1409
|
+
// // disableUploadFile: true,
|
|
1410
|
+
// // },
|
|
1411
|
+
// // createUserChat('', `${conversationIdRef.current}`),
|
|
1412
|
+
// // ];
|
|
1413
|
+
// // dispatch(setMessageList({ messageList: newMessageList }));
|
|
1414
|
+
// }
|
|
1415
|
+
// }
|
|
1388
1416
|
}, [fileList, dispatch, handleSendFile, createUserChat]);
|
|
1389
1417
|
var onSucessExcel = React.useCallback(function (value) {
|
|
1390
1418
|
// setDisableSend(true);
|
|
@@ -111,6 +111,7 @@ declare const enUS: {
|
|
|
111
111
|
'common.scoreUnit': string;
|
|
112
112
|
'common.networkUnavailable': string;
|
|
113
113
|
'askCard.fileUpload': string;
|
|
114
|
+
'askCard.uploading': string;
|
|
114
115
|
'upload.readFailed': string;
|
|
115
116
|
'upload.networkRetry': string;
|
|
116
117
|
'upload.failedMaxRetry': string;
|
|
@@ -111,6 +111,7 @@ var enUS = {
|
|
|
111
111
|
'common.scoreUnit': 'Points',
|
|
112
112
|
'common.networkUnavailable': 'Network connection error',
|
|
113
113
|
'askCard.fileUpload': 'File Upload',
|
|
114
|
+
'askCard.uploading': 'Uploading',
|
|
114
115
|
'upload.readFailed': 'File read failed',
|
|
115
116
|
'upload.networkRetry': 'Network error, waiting to retry',
|
|
116
117
|
'upload.failedMaxRetry': 'Upload failed, max retries reached',
|
|
@@ -113,6 +113,7 @@ declare const zhCN: {
|
|
|
113
113
|
'common.scoreUnit': string;
|
|
114
114
|
'common.networkUnavailable': string;
|
|
115
115
|
'askCard.fileUpload': string;
|
|
116
|
+
'askCard.uploading': string;
|
|
116
117
|
'upload.readFailed': string;
|
|
117
118
|
'upload.networkRetry': string;
|
|
118
119
|
'upload.failedMaxRetry': string;
|
|
@@ -113,6 +113,7 @@ var zhCN = {
|
|
|
113
113
|
'common.scoreUnit': '分',
|
|
114
114
|
'common.networkUnavailable': '无法连接到网络',
|
|
115
115
|
'askCard.fileUpload': '文件上传',
|
|
116
|
+
'askCard.uploading': '上传中',
|
|
116
117
|
'upload.readFailed': '文件读取失败',
|
|
117
118
|
'upload.networkRetry': '网络异常,等待恢复后重试',
|
|
118
119
|
'upload.failedMaxRetry': '文件上传失败,已达到最大重试次数',
|