@myun/gimi-chat 0.9.72 → 0.9.74
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.d.ts +2 -1
- package/dist/components/answer-item/component/tool-list/index.js +117 -4
- package/dist/components/answer-item/component/tool-list/index.module.css +99 -0
- package/dist/components/answer-item/index.js +30 -11
- package/dist/components/chat-input/index.js +55 -5
- package/dist/hooks/useChatActions.js +35 -16
- package/dist/hooks/useChatStream.js +0 -3
- package/dist/hooks/useCommonChatAPI.js +68 -27
- package/dist/interfaces/chatMessage.d.ts +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ToolItem } from "../../../../interfaces/chatMessage";
|
|
3
|
-
declare const ToolList: ({ toolList, handleClickConfirm, customRender }: {
|
|
3
|
+
declare const ToolList: ({ toolList, handleClickConfirm, handleClickAskList, customRender }: {
|
|
4
4
|
toolList: ToolItem[];
|
|
5
5
|
handleClickConfirm: (item: any, confirmed: boolean) => void;
|
|
6
|
+
handleClickAskList: (item: any, operation: string, key: string, value?: string, inputModel?: any) => void;
|
|
6
7
|
customRender: any;
|
|
7
8
|
}) => React.JSX.Element;
|
|
8
9
|
export default ToolList;
|
|
@@ -11,8 +11,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
11
11
|
import React, { useMemo, useState } from "react";
|
|
12
12
|
import { MMarkdown } from '@myun/gimi-design';
|
|
13
13
|
import IconFont from "../../../iconfont-com";
|
|
14
|
+
import FileUpload from "../../../file-upload";
|
|
14
15
|
import styles from "./index.module.css";
|
|
15
16
|
import classNames from "classnames";
|
|
17
|
+
import { useTranslation } from "react-i18next";
|
|
16
18
|
|
|
17
19
|
// 思考工具项组件
|
|
18
20
|
var ThinkingToolItem = function ThinkingToolItem(_ref) {
|
|
@@ -133,10 +135,114 @@ var ConfirmToolItem = function ConfirmToolItem(_ref3) {
|
|
|
133
135
|
}
|
|
134
136
|
}, "\u62D2\u7EDD"))));
|
|
135
137
|
};
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
var AskToolItem = function AskToolItem(_ref4) {
|
|
139
|
+
var item = _ref4.item,
|
|
140
|
+
handleClickAskList = _ref4.handleClickAskList;
|
|
141
|
+
var _React$useState = React.useState(false),
|
|
142
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
143
|
+
disabled = _React$useState2[0],
|
|
144
|
+
setDisabled = _React$useState2[1];
|
|
145
|
+
var _React$useState3 = React.useState(''),
|
|
146
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
147
|
+
inputValue = _React$useState4[0],
|
|
148
|
+
setInputValue = _React$useState4[1];
|
|
149
|
+
var _useState5 = useState(false),
|
|
150
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
151
|
+
showContent = _useState6[0],
|
|
152
|
+
setShowContent = _useState6[1];
|
|
153
|
+
var _useTranslation = useTranslation(),
|
|
154
|
+
t = _useTranslation.t;
|
|
155
|
+
var askTextMap = {
|
|
156
|
+
RUNNING: "等待用户回答",
|
|
157
|
+
COMPLETED: "用户已回答"
|
|
158
|
+
};
|
|
159
|
+
var _React$useMemo = React.useMemo(function () {
|
|
160
|
+
var _item$data2, _detailInfo$questionC, _item$data3;
|
|
161
|
+
var detailInfo = ((_item$data2 = item.data) === null || _item$data2 === void 0 || (_item$data2 = _item$data2.results) === null || _item$data2 === void 0 ? void 0 : _item$data2.askShowInfo) || {};
|
|
162
|
+
var optionsList = detailInfo.options ? Object.entries(detailInfo.options).map(function (_ref5) {
|
|
163
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
164
|
+
key = _ref6[0],
|
|
165
|
+
value = _ref6[1];
|
|
166
|
+
return {
|
|
167
|
+
key: key,
|
|
168
|
+
value: value
|
|
169
|
+
};
|
|
170
|
+
}) : [];
|
|
171
|
+
var questionContent = ((_detailInfo$questionC = detailInfo.questionContent) === null || _detailInfo$questionC === void 0 ? void 0 : _detailInfo$questionC.replace(/\n/g, '\n')) || ((_item$data3 = item.data) === null || _item$data3 === void 0 ? void 0 : _item$data3.message) || '';
|
|
172
|
+
return {
|
|
173
|
+
detailInfo: detailInfo,
|
|
174
|
+
optionsList: optionsList,
|
|
175
|
+
questionContent: questionContent
|
|
176
|
+
};
|
|
177
|
+
}, [item.data]),
|
|
178
|
+
detailInfo = _React$useMemo.detailInfo,
|
|
179
|
+
optionsList = _React$useMemo.optionsList,
|
|
180
|
+
questionContent = _React$useMemo.questionContent;
|
|
181
|
+
React.useEffect(function () {
|
|
182
|
+
var isAnswered = item.status === 'ANSWERED' || item.confirmStatus === 'CONFIRMED';
|
|
183
|
+
setDisabled(Boolean(isAnswered));
|
|
184
|
+
}, [item.confirmStatus, item.status]);
|
|
185
|
+
var onAskItemClick = function onAskItemClick(key, value) {
|
|
186
|
+
if (disabled) return;
|
|
187
|
+
setDisabled(true);
|
|
188
|
+
handleClickAskList(item, 'click', key, value);
|
|
189
|
+
};
|
|
190
|
+
var optionRender = function optionRender(v) {
|
|
191
|
+
return /*#__PURE__*/React.createElement("span", null, v.value ? v.value : v.key);
|
|
192
|
+
};
|
|
193
|
+
var statusKey = item.status || "PENDING";
|
|
194
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
195
|
+
className: styles.toolItem
|
|
196
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
197
|
+
className: styles.toolItemLabel,
|
|
198
|
+
onClick: function onClick() {
|
|
199
|
+
return item.content && setShowContent(!showContent);
|
|
200
|
+
}
|
|
201
|
+
}, item.status === "COMPLETED" && /*#__PURE__*/React.createElement("img", {
|
|
202
|
+
className: styles.toolIcon,
|
|
203
|
+
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202609/07/e5347_20260907085700.png"
|
|
204
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
205
|
+
className: classNames(styles.toolName, _defineProperty({}, styles.running, item.status === "PENDING" || item.status === "RUNNING"))
|
|
206
|
+
}, askTextMap[statusKey] || askTextMap.PENDING), item.status === "COMPLETED" && item.content && /*#__PURE__*/React.createElement(IconFont, {
|
|
207
|
+
className: classNames(styles.icon, _defineProperty({}, styles.hasContent, showContent)),
|
|
208
|
+
type: showContent ? "icon-a-jiantoucu2x-copy1" : "icon-a-jiantoucu2x",
|
|
209
|
+
size: 12,
|
|
210
|
+
extraStyle: {
|
|
211
|
+
color: !showContent ? "var(--theme-neutral, #626262)" : "var(--theme-mediumNeutral, #B3B2B2)"
|
|
212
|
+
}
|
|
213
|
+
})), item.confirmStatus === "PENDING" || item.status === "RUNNING" ? /*#__PURE__*/React.createElement("div", {
|
|
214
|
+
className: styles.askContent
|
|
215
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
216
|
+
className: styles.askQuestion
|
|
217
|
+
}, questionContent), detailInfo.answerType === 1 && /*#__PURE__*/React.createElement("div", {
|
|
218
|
+
className: styles.askOptions
|
|
219
|
+
}, optionsList === null || optionsList === void 0 ? void 0 : optionsList.map(function (v) {
|
|
220
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
221
|
+
className: classNames(styles.askItem, disabled ? styles.disablebox : ''),
|
|
222
|
+
key: v.key,
|
|
223
|
+
onClick: function onClick() {
|
|
224
|
+
return onAskItemClick(v.key, v.value || v.key);
|
|
225
|
+
}
|
|
226
|
+
}, optionRender(v));
|
|
227
|
+
})), detailInfo.uploadFile && detailInfo.answerType === 0 && /*#__PURE__*/React.createElement("div", {
|
|
228
|
+
className: classNames(styles.showUpload)
|
|
229
|
+
}, /*#__PURE__*/React.createElement(FileUpload, null, /*#__PURE__*/React.createElement("div", {
|
|
230
|
+
className: classNames(styles.uploadIcon)
|
|
231
|
+
}, /*#__PURE__*/React.createElement(IconFont, {
|
|
232
|
+
type: "icon-shurukuang-webtianjia",
|
|
233
|
+
size: 26,
|
|
234
|
+
color: 'var(--theme-deepNeutral, #2E394C)'
|
|
235
|
+
}), /*#__PURE__*/React.createElement("span", null, t('askCard.fileUpload')))))) : item.content && showContent && /*#__PURE__*/React.createElement("div", {
|
|
236
|
+
className: styles.toolItemContent
|
|
237
|
+
}, /*#__PURE__*/React.createElement(MMarkdown, {
|
|
238
|
+
content: item.content
|
|
239
|
+
})));
|
|
240
|
+
};
|
|
241
|
+
var ToolList = function ToolList(_ref7) {
|
|
242
|
+
var toolList = _ref7.toolList,
|
|
243
|
+
handleClickConfirm = _ref7.handleClickConfirm,
|
|
244
|
+
handleClickAskList = _ref7.handleClickAskList,
|
|
245
|
+
customRender = _ref7.customRender;
|
|
140
246
|
return /*#__PURE__*/React.createElement("div", {
|
|
141
247
|
className: styles.toolList
|
|
142
248
|
}, toolList.map(function (item) {
|
|
@@ -147,6 +253,13 @@ var ToolList = function ToolList(_ref4) {
|
|
|
147
253
|
handleClickConfirm: handleClickConfirm
|
|
148
254
|
});
|
|
149
255
|
}
|
|
256
|
+
if (item.moduleType === "ask") {
|
|
257
|
+
return /*#__PURE__*/React.createElement(AskToolItem, {
|
|
258
|
+
key: item.id,
|
|
259
|
+
item: item,
|
|
260
|
+
handleClickAskList: handleClickAskList
|
|
261
|
+
});
|
|
262
|
+
}
|
|
150
263
|
if (item.moduleType === "thinking") {
|
|
151
264
|
return /*#__PURE__*/React.createElement(ThinkingToolItem, {
|
|
152
265
|
key: item.id,
|
|
@@ -86,6 +86,105 @@
|
|
|
86
86
|
.toolItem .confirmContent .confirmBtn:hover {
|
|
87
87
|
opacity: 0.85;
|
|
88
88
|
}
|
|
89
|
+
.toolItem .askContent {
|
|
90
|
+
width: clamp(360px, 90%, 600px);
|
|
91
|
+
flex-shrink: 0;
|
|
92
|
+
padding: 20px;
|
|
93
|
+
border-radius: 16px;
|
|
94
|
+
border: 1px solid var(--theme-lightNeutral, #E9EBF2);
|
|
95
|
+
background-color: var(--theme-subtleNeutral, #F7F7F7);
|
|
96
|
+
margin-top: 12px;
|
|
97
|
+
}
|
|
98
|
+
.toolItem .askContent .askQuestion {
|
|
99
|
+
color: var(--theme-deepNeutral, #2E394C);
|
|
100
|
+
font-size: 16px;
|
|
101
|
+
font-weight: 400;
|
|
102
|
+
line-height: 28px;
|
|
103
|
+
margin-bottom: 12px;
|
|
104
|
+
white-space: pre-wrap;
|
|
105
|
+
}
|
|
106
|
+
.toolItem .askContent .askOptions {
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
gap: 16px;
|
|
110
|
+
}
|
|
111
|
+
.toolItem .askContent .askItem {
|
|
112
|
+
height: 44px;
|
|
113
|
+
border-radius: 22px;
|
|
114
|
+
border: 1px solid #E3E3E1;
|
|
115
|
+
background: #FFFFFF;
|
|
116
|
+
color: #221813;
|
|
117
|
+
font-size: 14px;
|
|
118
|
+
font-weight: 600;
|
|
119
|
+
display: flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
justify-content: center;
|
|
122
|
+
cursor: pointer;
|
|
123
|
+
transition: opacity 0.2s;
|
|
124
|
+
}
|
|
125
|
+
.toolItem .askContent .askItem:hover {
|
|
126
|
+
opacity: 0.85;
|
|
127
|
+
}
|
|
128
|
+
.toolItem .askContent .disablebox {
|
|
129
|
+
border-radius: 22px;
|
|
130
|
+
border: 1px solid var(--theme-softNeutral, #D9DCE5);
|
|
131
|
+
background: #fff;
|
|
132
|
+
color: #ced3d9;
|
|
133
|
+
cursor: not-allowed;
|
|
134
|
+
pointer-events: none;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.showUpload {
|
|
138
|
+
width: fit-content;
|
|
139
|
+
min-width: 128px;
|
|
140
|
+
height: 44px;
|
|
141
|
+
flex-shrink: 0;
|
|
142
|
+
border-radius: 22px;
|
|
143
|
+
border: 1px solid var(--theme-softNeutral, #D9DCE5);
|
|
144
|
+
background: #fff;
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
display: flex;
|
|
150
|
+
align-items: center;
|
|
151
|
+
padding: 0 12px;
|
|
152
|
+
box-sizing: border-box;
|
|
153
|
+
color: var(--theme-deepNeutral, #2E394C);
|
|
154
|
+
font-family: "PingFang SC";
|
|
155
|
+
font-size: 14px;
|
|
156
|
+
font-style: normal;
|
|
157
|
+
font-weight: 600;
|
|
158
|
+
line-height: normal;
|
|
159
|
+
}
|
|
160
|
+
.showUpload :global(.ant-upload) {
|
|
161
|
+
height: 100%;
|
|
162
|
+
}
|
|
163
|
+
.showUpload .uploadIcon {
|
|
164
|
+
height: 100%;
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
gap: 6px;
|
|
168
|
+
}
|
|
169
|
+
.showUpload .uploadIcon span {
|
|
170
|
+
white-space: nowrap;
|
|
171
|
+
}
|
|
172
|
+
.showUpload .disableFile {
|
|
173
|
+
border-radius: 22px;
|
|
174
|
+
border: 1px solid var(--theme-softNeutral, #D9DCE5);
|
|
175
|
+
background: #fff;
|
|
176
|
+
color: #ced3d9;
|
|
177
|
+
font-family: "PingFang SC";
|
|
178
|
+
font-size: 14px;
|
|
179
|
+
font-style: normal;
|
|
180
|
+
font-weight: 600;
|
|
181
|
+
line-height: normal;
|
|
182
|
+
}
|
|
183
|
+
.showUpload img {
|
|
184
|
+
width: 32px;
|
|
185
|
+
height: 32px;
|
|
186
|
+
flex-shrink: 0;
|
|
187
|
+
}
|
|
89
188
|
|
|
90
189
|
@keyframes shine {
|
|
91
190
|
0% {
|
|
@@ -118,17 +118,16 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
118
118
|
}
|
|
119
119
|
}, [platform]);
|
|
120
120
|
var _React$useMemo = React.useMemo(function () {
|
|
121
|
-
var _item$moduleInfo
|
|
121
|
+
var _item$moduleInfo;
|
|
122
122
|
var contentStr = item.content && processString(item.content) || '';
|
|
123
123
|
var showContentFlag = Boolean(contentStr);
|
|
124
|
-
|
|
125
|
-
var showSkillTag = item.moduleType === 'skill' || ((_item$
|
|
126
|
-
var showOperation = (showContentFlag || showSkillTag) && !
|
|
124
|
+
// const showAskTag = item.moduleType === 'ask' || item.moduleInfo?.moduleType === 'ask';
|
|
125
|
+
var showSkillTag = item.moduleType === 'skill' || ((_item$moduleInfo = item.moduleInfo) === null || _item$moduleInfo === void 0 ? void 0 : _item$moduleInfo.moduleType) === 'skill';
|
|
126
|
+
var showOperation = (showContentFlag || showSkillTag) && !isMsgRecieving;
|
|
127
127
|
var showTaskSuccess = (contentStr === null || contentStr === void 0 ? void 0 : contentStr.indexOf('<excel>')) > -1 && !isMsgRecieving;
|
|
128
128
|
var showRegerate = lastMessageId !== undefined && item.id === lastMessageId;
|
|
129
129
|
return {
|
|
130
130
|
showContentFlag: showContentFlag,
|
|
131
|
-
showAskTag: showAskTag,
|
|
132
131
|
showSkillTag: showSkillTag,
|
|
133
132
|
showOperation: showOperation,
|
|
134
133
|
showTaskSuccess: showTaskSuccess,
|
|
@@ -136,7 +135,6 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
136
135
|
};
|
|
137
136
|
}, [item.id, item.content, item.moduleType, item.moduleInfo, isMsgRecieving, lastMessageId]),
|
|
138
137
|
showContentFlag = _React$useMemo.showContentFlag,
|
|
139
|
-
showAskTag = _React$useMemo.showAskTag,
|
|
140
138
|
showSkillTag = _React$useMemo.showSkillTag,
|
|
141
139
|
showOperation = _React$useMemo.showOperation,
|
|
142
140
|
showTaskSuccess = _React$useMemo.showTaskSuccess,
|
|
@@ -266,20 +264,21 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
266
264
|
try {
|
|
267
265
|
data = JSON.parse(item.eventData || '{}');
|
|
268
266
|
} catch (error) {}
|
|
269
|
-
if (
|
|
267
|
+
if (item.moduleType === 'start') return;
|
|
268
|
+
if ([].concat(_toConsumableArray(TOOL_MODULE_TYPES), ["user_confirm", "stream", "ask"]).includes(item.moduleType) && !["execute", "notifyWorkflowStart"].includes((_data = data) === null || _data === void 0 ? void 0 : _data.name)) {
|
|
270
269
|
var _data2, _data3;
|
|
271
270
|
// 只处理工作流模式下的 tool_result,其他情况暂不处理
|
|
272
271
|
if (data.moduleType === 'tool_result' && ((_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.name) !== 'executeWorkflow') return;
|
|
273
272
|
|
|
274
273
|
// 为新节点类型根据 status 生成 toolName
|
|
275
|
-
var isNewNodeType = !['tool_invocation', 'tool_result', "user_confirm"].includes(item.moduleType);
|
|
274
|
+
var isNewNodeType = !['tool_invocation', 'tool_result', "user_confirm", 'ask'].includes(item.moduleType);
|
|
276
275
|
var toolName = isNewNodeType ? getToolNameByStatus(item.moduleType, 'COMPLETED') : (_data3 = data) === null || _data3 === void 0 ? void 0 : _data3.toolName;
|
|
277
276
|
var index = toolList.findIndex(function (v) {
|
|
278
277
|
var _data4;
|
|
279
278
|
return v.id === ((_data4 = data) === null || _data4 === void 0 ? void 0 : _data4.id);
|
|
280
279
|
});
|
|
281
280
|
if (index < 0) {
|
|
282
|
-
|
|
281
|
+
var newItem = {
|
|
283
282
|
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
284
283
|
askingEventId: item.askingEventId
|
|
285
284
|
}),
|
|
@@ -289,7 +288,26 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
289
288
|
confirmStatus: item.confirmStatus,
|
|
290
289
|
id: data.id || item.id || +new Date(),
|
|
291
290
|
moduleType: item.moduleType
|
|
292
|
-
}
|
|
291
|
+
};
|
|
292
|
+
if (item.moduleType === 'ask') {
|
|
293
|
+
var eventData = {};
|
|
294
|
+
var askContent = '';
|
|
295
|
+
try {
|
|
296
|
+
var _eventData, _eventData2;
|
|
297
|
+
eventData = JSON.parse(item.eventData || '{}');
|
|
298
|
+
// 当存在 clickedOptionId 时,从 askShowInfo.options 中获取对应选项的值
|
|
299
|
+
var clickedOptionId = (_eventData = eventData) === null || _eventData === void 0 || (_eventData = _eventData.data) === null || _eventData === void 0 || (_eventData = _eventData.results) === null || _eventData === void 0 ? void 0 : _eventData.clickedOptionId;
|
|
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
|
+
if (clickedOptionId && options && options[clickedOptionId]) {
|
|
302
|
+
askContent = options[clickedOptionId];
|
|
303
|
+
}
|
|
304
|
+
} catch (error) {}
|
|
305
|
+
newItem.content = askContent;
|
|
306
|
+
newItem.data = _objectSpread(_objectSpread({}, newItem.data), eventData.data);
|
|
307
|
+
newItem.status = item.status === 'PENDING' ? 'RUNNING' : 'COMPLETED';
|
|
308
|
+
newItem.confirmStatus = item.status === 'PENDING' ? 'RUNNING' : 'COMPLETED';
|
|
309
|
+
}
|
|
310
|
+
toolList.push(newItem);
|
|
293
311
|
} else {
|
|
294
312
|
toolList[index] = _objectSpread(_objectSpread({}, toolList[index]), {}, {
|
|
295
313
|
content: data.content || toolList[index].content
|
|
@@ -354,6 +372,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
354
372
|
})), expendThinking && /*#__PURE__*/React.createElement(React.Fragment, null, mergedToolList.length > 0 && /*#__PURE__*/React.createElement(ToolList, {
|
|
355
373
|
toolList: mergedToolList,
|
|
356
374
|
handleClickConfirm: handleClickConfirm,
|
|
375
|
+
handleClickAskList: handleClickAskList,
|
|
357
376
|
customRender: customRender
|
|
358
377
|
}))), item.mcp && /*#__PURE__*/React.createElement(WorkFlowContent, {
|
|
359
378
|
chatItem: item
|
|
@@ -390,7 +409,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
390
409
|
}), enableUnLike && /*#__PURE__*/React.createElement(UnLikeButton, {
|
|
391
410
|
item: item,
|
|
392
411
|
onUnLikeCallback: onUnLikeCallback
|
|
393
|
-
}), enableVoicePlay && !
|
|
412
|
+
}), enableVoicePlay && !showSkillTag && ((_agentDetail$voiceCon = agentDetail.voiceConfigs) === null || _agentDetail$voiceCon === void 0 ? void 0 : _agentDetail$voiceCon.length) > 0 && /*#__PURE__*/React.createElement(VoicePlay, {
|
|
394
413
|
playTTSByText: playTTSByText,
|
|
395
414
|
stopTTSByText: stopTTSByText,
|
|
396
415
|
isVoicePlaying: isVoicePlaying,
|
|
@@ -103,6 +103,12 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
103
103
|
var inputRef = React.useRef(null);
|
|
104
104
|
var isTruncatingRef = React.useRef(false);
|
|
105
105
|
var uploadFileRef = React.useRef(null);
|
|
106
|
+
// 缓存 getThinkingEffective 的结果,避免重复请求
|
|
107
|
+
var thinkingCacheRef = React.useRef({
|
|
108
|
+
agentId: null,
|
|
109
|
+
promise: null,
|
|
110
|
+
result: null
|
|
111
|
+
});
|
|
106
112
|
var conversationIdRef = React.useRef(conversationId);
|
|
107
113
|
conversationIdRef.current = conversationId;
|
|
108
114
|
var agentObjRef = React.useRef(agentObj);
|
|
@@ -181,25 +187,69 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
181
187
|
setDeepThinkActive(false);
|
|
182
188
|
return;
|
|
183
189
|
}
|
|
190
|
+
|
|
191
|
+
// 如果缓存中有相同 agentId 的结果,直接使用
|
|
192
|
+
if (thinkingCacheRef.current.agentId === agentId && thinkingCacheRef.current.result) {
|
|
193
|
+
var result = thinkingCacheRef.current.result;
|
|
194
|
+
setDeepThinkDisabled(result.thinking !== 1);
|
|
195
|
+
setDeepThinkActive(result.thinkingEnable === 1);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 如果有正在进行的请求,复用该 Promise
|
|
200
|
+
if (thinkingCacheRef.current.agentId === agentId && thinkingCacheRef.current.promise) {
|
|
201
|
+
thinkingCacheRef.current.promise.then(function (result) {
|
|
202
|
+
setDeepThinkDisabled(result.thinking !== 1);
|
|
203
|
+
setDeepThinkActive(result.thinkingEnable === 1);
|
|
204
|
+
}).catch(function (e) {
|
|
205
|
+
console.error('[deepThink] getThinkingEffective error:', e);
|
|
206
|
+
setDeepThinkDisabled(false);
|
|
207
|
+
setDeepThinkActive(false);
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 创建新请求并缓存
|
|
184
213
|
var cancelled = false;
|
|
185
|
-
apiService.getThinkingEffective(agentId).then(function (res) {
|
|
186
|
-
if (cancelled) return;
|
|
214
|
+
var promise = apiService.getThinkingEffective(agentId).then(function (res) {
|
|
215
|
+
if (cancelled) return null;
|
|
187
216
|
var result = (res === null || res === void 0 ? void 0 : res.result) || {};
|
|
188
|
-
//
|
|
217
|
+
// 缓存结果
|
|
218
|
+
thinkingCacheRef.current = {
|
|
219
|
+
agentId: agentId,
|
|
220
|
+
promise: null,
|
|
221
|
+
result: result
|
|
222
|
+
};
|
|
189
223
|
setDeepThinkDisabled(result.thinking !== 1);
|
|
190
|
-
// thinkingEnable: 1 高亮(已开启),0 默认
|
|
191
224
|
setDeepThinkActive(result.thinkingEnable === 1);
|
|
225
|
+
return result;
|
|
192
226
|
}).catch(function (e) {
|
|
193
227
|
if (!cancelled) {
|
|
194
228
|
console.error('[deepThink] getThinkingEffective error:', e);
|
|
195
229
|
setDeepThinkDisabled(false);
|
|
196
230
|
setDeepThinkActive(false);
|
|
231
|
+
// 清除失败的缓存
|
|
232
|
+
if (thinkingCacheRef.current.agentId === agentId) {
|
|
233
|
+
thinkingCacheRef.current = {
|
|
234
|
+
agentId: null,
|
|
235
|
+
promise: null,
|
|
236
|
+
result: null
|
|
237
|
+
};
|
|
238
|
+
}
|
|
197
239
|
}
|
|
240
|
+
throw e;
|
|
198
241
|
});
|
|
242
|
+
|
|
243
|
+
// 缓存正在进行的请求
|
|
244
|
+
thinkingCacheRef.current = {
|
|
245
|
+
agentId: agentId,
|
|
246
|
+
promise: promise,
|
|
247
|
+
result: null
|
|
248
|
+
};
|
|
199
249
|
return function () {
|
|
200
250
|
cancelled = true;
|
|
201
251
|
};
|
|
202
|
-
}, [agentObj === null || agentObj === void 0 ? void 0 : agentObj.agentId, apiService]);
|
|
252
|
+
}, [agentObj === null || agentObj === void 0 ? void 0 : agentObj.agentId, apiService, props.hiddenDeepThink]);
|
|
203
253
|
React.useEffect(function () {
|
|
204
254
|
if (!props.defaultPrompt) {
|
|
205
255
|
setHasContent(false);
|
|
@@ -190,22 +190,41 @@ var useChatActions = function useChatActions(showCopyId, inputModelRef, handleSe
|
|
|
190
190
|
*/
|
|
191
191
|
var handleClickAskList = React.useMemo(function () {
|
|
192
192
|
return debounce(function (item, operation, key, value, inputModel) {
|
|
193
|
-
var
|
|
194
|
-
var messageList = messageListRef.current;
|
|
195
|
-
if ((_messageList8 = messageList[messageList.length - 1]) !== null && _messageList8 !== void 0 && _messageList8.selectValue) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
193
|
+
var _lastMessage$toolList;
|
|
198
194
|
var _inputModel = inputModel || _defineProperty({}, "".concat(item.id, ".").concat(operation), key);
|
|
199
|
-
|
|
200
|
-
var
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
195
|
+
var currentMessageList = messageListRef.current;
|
|
196
|
+
var lastMessage = currentMessageList[currentMessageList.length - 1];
|
|
197
|
+
|
|
198
|
+
// if (messageList[messageList.length - 1]?.selectValue) {
|
|
199
|
+
// return;
|
|
200
|
+
// }
|
|
201
|
+
// 根据 operation 类型获取答案内容
|
|
202
|
+
var answerContent = '';
|
|
203
|
+
if (operation === 'click') {
|
|
204
|
+
var _item$data;
|
|
205
|
+
// 点击选项:用 key 从 askShowInfo.options 中获取选项值
|
|
206
|
+
var options = (_item$data = item.data) === null || _item$data === void 0 || (_item$data = _item$data.results) === null || _item$data === void 0 || (_item$data = _item$data.askShowInfo) === null || _item$data === void 0 ? void 0 : _item$data.options;
|
|
207
|
+
answerContent = (options === null || options === void 0 ? void 0 : options[key]) || key;
|
|
208
|
+
} else if (operation === 'input') {
|
|
209
|
+
// 输入模式:直接使用 value
|
|
210
|
+
answerContent = value || '';
|
|
211
|
+
}
|
|
212
|
+
var updatedToolList = (_lastMessage$toolList = lastMessage.toolList) === null || _lastMessage$toolList === void 0 ? void 0 : _lastMessage$toolList.map(function (tool) {
|
|
213
|
+
return tool.id === item.id ? _objectSpread(_objectSpread({}, tool), {}, {
|
|
214
|
+
moduleType: "ask",
|
|
215
|
+
status: 'COMPLETED',
|
|
216
|
+
confirmStatus: "CONFIRMED",
|
|
217
|
+
content: answerContent
|
|
218
|
+
}) : tool;
|
|
204
219
|
});
|
|
220
|
+
var updatedMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, lastMessage), {}, {
|
|
221
|
+
toolList: updatedToolList
|
|
222
|
+
})]);
|
|
205
223
|
dispatch(setMessageList({
|
|
206
|
-
messageList:
|
|
224
|
+
messageList: updatedMessageList
|
|
207
225
|
}));
|
|
208
|
-
|
|
226
|
+
inputModelRef.current = _inputModel;
|
|
227
|
+
handleSend(value || '', undefined, true, undefined, true); // skipCreateNewMessage: true 复用当前消息
|
|
209
228
|
}, 100);
|
|
210
229
|
}, [handleSend, inputModelRef, dispatch]);
|
|
211
230
|
|
|
@@ -214,11 +233,11 @@ var useChatActions = function useChatActions(showCopyId, inputModelRef, handleSe
|
|
|
214
233
|
* 绕开 ask 的 selectValue 防重逻辑,直接组装 user_confirm inputModel 发送
|
|
215
234
|
*/
|
|
216
235
|
var handleClickConfirm = React.useCallback(function (item, confirmed) {
|
|
217
|
-
var _lastMessage$
|
|
236
|
+
var _lastMessage$toolList2, _item$data2, _item$data3;
|
|
218
237
|
// 1. 更新最后一条消息的 toolList,把这条 user_confirm 改成已确认/已拒绝
|
|
219
238
|
var currentMessageList = messageListRef.current;
|
|
220
239
|
var lastMessage = currentMessageList[currentMessageList.length - 1];
|
|
221
|
-
var updatedToolList = (_lastMessage$
|
|
240
|
+
var updatedToolList = (_lastMessage$toolList2 = lastMessage.toolList) === null || _lastMessage$toolList2 === void 0 ? void 0 : _lastMessage$toolList2.map(function (tool) {
|
|
222
241
|
return tool.id === item.id ? _objectSpread(_objectSpread({}, tool), {}, {
|
|
223
242
|
moduleType: "user_confirm",
|
|
224
243
|
status: 'COMPLETED',
|
|
@@ -235,9 +254,9 @@ var useChatActions = function useChatActions(showCopyId, inputModelRef, handleSe
|
|
|
235
254
|
// 2. 组装 inputModel 并发送
|
|
236
255
|
var inputModel = {
|
|
237
256
|
user_confirm: {
|
|
238
|
-
askingEventId: (_item$
|
|
257
|
+
askingEventId: (_item$data2 = item.data) === null || _item$data2 === void 0 ? void 0 : _item$data2.askingEventId,
|
|
239
258
|
confirmResults: [{
|
|
240
|
-
toolCallId: ((_item$
|
|
259
|
+
toolCallId: ((_item$data3 = item.data) === null || _item$data3 === void 0 || (_item$data3 = _item$data3.toolCalls) === null || _item$data3 === void 0 || (_item$data3 = _item$data3[0]) === null || _item$data3 === void 0 ? void 0 : _item$data3.id) || '',
|
|
241
260
|
confirmed: confirmed
|
|
242
261
|
}]
|
|
243
262
|
}
|
|
@@ -305,13 +305,10 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
305
305
|
if (_dataObj.moduleType === 'artifact' && _dataObj.status === 'COMPLETED') {
|
|
306
306
|
onArtifactStream === null || onArtifactStream === void 0 || onArtifactStream(_dataObj);
|
|
307
307
|
}
|
|
308
|
-
|
|
309
|
-
// 问答确认
|
|
310
308
|
if ((_dataObj.moduleType === 'ask' || _dataObj.moduleType === 'skill') && _dataObj.status === 'PENDING') {
|
|
311
309
|
onComplete === null || onComplete === void 0 || onComplete(_dataObj, _dataObj.moduleType);
|
|
312
310
|
return;
|
|
313
311
|
}
|
|
314
|
-
// 确认模式
|
|
315
312
|
if (_dataObj.moduleType === 'user_confirm' && _dataObj.status === 'ASKING') {
|
|
316
313
|
onComplete === null || onComplete === void 0 || onComplete(_dataObj, _dataObj.moduleType);
|
|
317
314
|
return;
|