@myun/gimi-chat 0.9.72 → 0.9.73
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 +110 -4
- package/dist/components/answer-item/component/tool-list/index.module.css +47 -0
- package/dist/components/answer-item/index.js +32 -11
- package/dist/components/chat-input/index.js +55 -5
- package/dist/hooks/useChatActions.js +37 -16
- package/dist/hooks/useChatStream.js +0 -3
- package/dist/hooks/useCommonChatAPI.js +14 -5
- 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;
|
|
@@ -133,10 +133,109 @@ var ConfirmToolItem = function ConfirmToolItem(_ref3) {
|
|
|
133
133
|
}
|
|
134
134
|
}, "\u62D2\u7EDD"))));
|
|
135
135
|
};
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
var AskToolItem = function AskToolItem(_ref4) {
|
|
137
|
+
var item = _ref4.item,
|
|
138
|
+
handleClickAskList = _ref4.handleClickAskList;
|
|
139
|
+
var _React$useState = React.useState(false),
|
|
140
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
141
|
+
disabled = _React$useState2[0],
|
|
142
|
+
setDisabled = _React$useState2[1];
|
|
143
|
+
var _React$useState3 = React.useState(''),
|
|
144
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
145
|
+
inputValue = _React$useState4[0],
|
|
146
|
+
setInputValue = _React$useState4[1];
|
|
147
|
+
var _useState5 = useState(false),
|
|
148
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
149
|
+
showContent = _useState6[0],
|
|
150
|
+
setShowContent = _useState6[1];
|
|
151
|
+
var askTextMap = {
|
|
152
|
+
RUNNING: "等待用户回答",
|
|
153
|
+
COMPLETED: "用户已回答"
|
|
154
|
+
};
|
|
155
|
+
var _React$useMemo = React.useMemo(function () {
|
|
156
|
+
var _item$data2, _detailInfo$questionC, _item$data3;
|
|
157
|
+
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) || {};
|
|
158
|
+
var optionsList = detailInfo.options ? Object.entries(detailInfo.options).map(function (_ref5) {
|
|
159
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
160
|
+
key = _ref6[0],
|
|
161
|
+
value = _ref6[1];
|
|
162
|
+
return {
|
|
163
|
+
key: key,
|
|
164
|
+
value: value
|
|
165
|
+
};
|
|
166
|
+
}) : [];
|
|
167
|
+
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) || '';
|
|
168
|
+
return {
|
|
169
|
+
detailInfo: detailInfo,
|
|
170
|
+
optionsList: optionsList,
|
|
171
|
+
questionContent: questionContent
|
|
172
|
+
};
|
|
173
|
+
}, [item.data]),
|
|
174
|
+
detailInfo = _React$useMemo.detailInfo,
|
|
175
|
+
optionsList = _React$useMemo.optionsList,
|
|
176
|
+
questionContent = _React$useMemo.questionContent;
|
|
177
|
+
React.useEffect(function () {
|
|
178
|
+
var isAnswered = item.status === 'ANSWERED' || item.confirmStatus === 'CONFIRMED';
|
|
179
|
+
setDisabled(Boolean(isAnswered));
|
|
180
|
+
}, [item.confirmStatus, item.status]);
|
|
181
|
+
var onAskItemClick = function onAskItemClick(key, value) {
|
|
182
|
+
if (disabled) return;
|
|
183
|
+
setDisabled(true);
|
|
184
|
+
handleClickAskList(item, 'click', key, value);
|
|
185
|
+
};
|
|
186
|
+
var handleInputSubmit = function handleInputSubmit() {
|
|
187
|
+
if (!inputValue.trim() || disabled) return;
|
|
188
|
+
setDisabled(true);
|
|
189
|
+
handleClickAskList(item, 'input', 'answer', inputValue.trim());
|
|
190
|
+
};
|
|
191
|
+
var optionRender = function optionRender(v) {
|
|
192
|
+
return /*#__PURE__*/React.createElement("span", null, v.value ? v.value : v.key);
|
|
193
|
+
};
|
|
194
|
+
var statusKey = item.status || "PENDING";
|
|
195
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
196
|
+
className: styles.toolItem
|
|
197
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
198
|
+
className: styles.toolItemLabel,
|
|
199
|
+
onClick: function onClick() {
|
|
200
|
+
return item.content && setShowContent(!showContent);
|
|
201
|
+
}
|
|
202
|
+
}, item.status === "COMPLETED" && /*#__PURE__*/React.createElement("img", {
|
|
203
|
+
className: styles.toolIcon,
|
|
204
|
+
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202609/07/e5347_20260907085700.png"
|
|
205
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
206
|
+
className: classNames(styles.toolName, _defineProperty({}, styles.running, item.status === "PENDING" || item.status === "RUNNING"))
|
|
207
|
+
}, askTextMap[statusKey] || askTextMap.PENDING), item.status === "COMPLETED" && item.content && /*#__PURE__*/React.createElement(IconFont, {
|
|
208
|
+
className: classNames(styles.icon, _defineProperty({}, styles.hasContent, showContent)),
|
|
209
|
+
type: showContent ? "icon-a-jiantoucu2x-copy1" : "icon-a-jiantoucu2x",
|
|
210
|
+
size: 12,
|
|
211
|
+
extraStyle: {
|
|
212
|
+
color: !showContent ? "var(--theme-neutral, #626262)" : "var(--theme-mediumNeutral, #B3B2B2)"
|
|
213
|
+
}
|
|
214
|
+
})), item.confirmStatus === "PENDING" || item.status === "RUNNING" ? /*#__PURE__*/React.createElement("div", {
|
|
215
|
+
className: styles.askContent
|
|
216
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
217
|
+
className: styles.askQuestion
|
|
218
|
+
}, questionContent), detailInfo.answerType === 1 && /*#__PURE__*/React.createElement("div", {
|
|
219
|
+
className: styles.askOptions
|
|
220
|
+
}, optionsList === null || optionsList === void 0 ? void 0 : optionsList.map(function (v) {
|
|
221
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
222
|
+
className: classNames(styles.askItem, disabled ? styles.disablebox : ''),
|
|
223
|
+
key: v.key,
|
|
224
|
+
onClick: function onClick() {
|
|
225
|
+
return onAskItemClick(v.key, v.value || v.key);
|
|
226
|
+
}
|
|
227
|
+
}, optionRender(v));
|
|
228
|
+
}))) : item.content && showContent && /*#__PURE__*/React.createElement("div", {
|
|
229
|
+
className: styles.toolItemContent
|
|
230
|
+
}, /*#__PURE__*/React.createElement(MMarkdown, {
|
|
231
|
+
content: item.content
|
|
232
|
+
})));
|
|
233
|
+
};
|
|
234
|
+
var ToolList = function ToolList(_ref7) {
|
|
235
|
+
var toolList = _ref7.toolList,
|
|
236
|
+
handleClickConfirm = _ref7.handleClickConfirm,
|
|
237
|
+
handleClickAskList = _ref7.handleClickAskList,
|
|
238
|
+
customRender = _ref7.customRender;
|
|
140
239
|
return /*#__PURE__*/React.createElement("div", {
|
|
141
240
|
className: styles.toolList
|
|
142
241
|
}, toolList.map(function (item) {
|
|
@@ -147,6 +246,13 @@ var ToolList = function ToolList(_ref4) {
|
|
|
147
246
|
handleClickConfirm: handleClickConfirm
|
|
148
247
|
});
|
|
149
248
|
}
|
|
249
|
+
if (item.moduleType === "ask") {
|
|
250
|
+
return /*#__PURE__*/React.createElement(AskToolItem, {
|
|
251
|
+
key: item.id,
|
|
252
|
+
item: item,
|
|
253
|
+
handleClickAskList: handleClickAskList
|
|
254
|
+
});
|
|
255
|
+
}
|
|
150
256
|
if (item.moduleType === "thinking") {
|
|
151
257
|
return /*#__PURE__*/React.createElement(ThinkingToolItem, {
|
|
152
258
|
key: item.id,
|
|
@@ -86,6 +86,53 @@
|
|
|
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
|
+
}
|
|
89
136
|
|
|
90
137
|
@keyframes shine {
|
|
91
138
|
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,28 @@ 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), {}, {
|
|
307
|
+
data: eventData
|
|
308
|
+
});
|
|
309
|
+
newItem.status = item.status === 'PENDING' ? 'RUNNING' : 'COMPLETED';
|
|
310
|
+
newItem.confirmStatus = item.status === 'PENDING' ? 'RUNNING' : 'COMPLETED';
|
|
311
|
+
}
|
|
312
|
+
toolList.push(newItem);
|
|
293
313
|
} else {
|
|
294
314
|
toolList[index] = _objectSpread(_objectSpread({}, toolList[index]), {}, {
|
|
295
315
|
content: data.content || toolList[index].content
|
|
@@ -354,6 +374,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
354
374
|
})), expendThinking && /*#__PURE__*/React.createElement(React.Fragment, null, mergedToolList.length > 0 && /*#__PURE__*/React.createElement(ToolList, {
|
|
355
375
|
toolList: mergedToolList,
|
|
356
376
|
handleClickConfirm: handleClickConfirm,
|
|
377
|
+
handleClickAskList: handleClickAskList,
|
|
357
378
|
customRender: customRender
|
|
358
379
|
}))), item.mcp && /*#__PURE__*/React.createElement(WorkFlowContent, {
|
|
359
380
|
chatItem: item
|
|
@@ -390,7 +411,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
390
411
|
}), enableUnLike && /*#__PURE__*/React.createElement(UnLikeButton, {
|
|
391
412
|
item: item,
|
|
392
413
|
onUnLikeCallback: onUnLikeCallback
|
|
393
|
-
}), enableVoicePlay && !
|
|
414
|
+
}), enableVoicePlay && !showSkillTag && ((_agentDetail$voiceCon = agentDetail.voiceConfigs) === null || _agentDetail$voiceCon === void 0 ? void 0 : _agentDetail$voiceCon.length) > 0 && /*#__PURE__*/React.createElement(VoicePlay, {
|
|
394
415
|
playTTSByText: playTTSByText,
|
|
395
416
|
stopTTSByText: stopTTSByText,
|
|
396
417
|
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,43 @@ 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
|
+
console.log(item);
|
|
202
|
+
|
|
203
|
+
// 根据 operation 类型获取答案内容
|
|
204
|
+
var answerContent = '';
|
|
205
|
+
if (operation === 'click') {
|
|
206
|
+
var _item$data;
|
|
207
|
+
// 点击选项:用 key 从 askShowInfo.options 中获取选项值
|
|
208
|
+
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;
|
|
209
|
+
answerContent = (options === null || options === void 0 ? void 0 : options[key]) || key;
|
|
210
|
+
} else if (operation === 'input') {
|
|
211
|
+
// 输入模式:直接使用 value
|
|
212
|
+
answerContent = value || '';
|
|
213
|
+
}
|
|
214
|
+
var updatedToolList = (_lastMessage$toolList = lastMessage.toolList) === null || _lastMessage$toolList === void 0 ? void 0 : _lastMessage$toolList.map(function (tool) {
|
|
215
|
+
return tool.id === item.id ? _objectSpread(_objectSpread({}, tool), {}, {
|
|
216
|
+
moduleType: "ask",
|
|
217
|
+
status: 'COMPLETED',
|
|
218
|
+
confirmStatus: "CONFIRMED",
|
|
219
|
+
content: answerContent
|
|
220
|
+
}) : tool;
|
|
204
221
|
});
|
|
222
|
+
var updatedMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, lastMessage), {}, {
|
|
223
|
+
toolList: updatedToolList
|
|
224
|
+
})]);
|
|
205
225
|
dispatch(setMessageList({
|
|
206
|
-
messageList:
|
|
226
|
+
messageList: updatedMessageList
|
|
207
227
|
}));
|
|
208
|
-
|
|
228
|
+
inputModelRef.current = _inputModel;
|
|
229
|
+
handleSend(value || '', undefined, true, undefined, true); // skipCreateNewMessage: true 复用当前消息
|
|
209
230
|
}, 100);
|
|
210
231
|
}, [handleSend, inputModelRef, dispatch]);
|
|
211
232
|
|
|
@@ -214,11 +235,11 @@ var useChatActions = function useChatActions(showCopyId, inputModelRef, handleSe
|
|
|
214
235
|
* 绕开 ask 的 selectValue 防重逻辑,直接组装 user_confirm inputModel 发送
|
|
215
236
|
*/
|
|
216
237
|
var handleClickConfirm = React.useCallback(function (item, confirmed) {
|
|
217
|
-
var _lastMessage$
|
|
238
|
+
var _lastMessage$toolList2, _item$data2, _item$data3;
|
|
218
239
|
// 1. 更新最后一条消息的 toolList,把这条 user_confirm 改成已确认/已拒绝
|
|
219
240
|
var currentMessageList = messageListRef.current;
|
|
220
241
|
var lastMessage = currentMessageList[currentMessageList.length - 1];
|
|
221
|
-
var updatedToolList = (_lastMessage$
|
|
242
|
+
var updatedToolList = (_lastMessage$toolList2 = lastMessage.toolList) === null || _lastMessage$toolList2 === void 0 ? void 0 : _lastMessage$toolList2.map(function (tool) {
|
|
222
243
|
return tool.id === item.id ? _objectSpread(_objectSpread({}, tool), {}, {
|
|
223
244
|
moduleType: "user_confirm",
|
|
224
245
|
status: 'COMPLETED',
|
|
@@ -235,9 +256,9 @@ var useChatActions = function useChatActions(showCopyId, inputModelRef, handleSe
|
|
|
235
256
|
// 2. 组装 inputModel 并发送
|
|
236
257
|
var inputModel = {
|
|
237
258
|
user_confirm: {
|
|
238
|
-
askingEventId: (_item$
|
|
259
|
+
askingEventId: (_item$data2 = item.data) === null || _item$data2 === void 0 ? void 0 : _item$data2.askingEventId,
|
|
239
260
|
confirmResults: [{
|
|
240
|
-
toolCallId: ((_item$
|
|
261
|
+
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
262
|
confirmed: confirmed
|
|
242
263
|
}]
|
|
243
264
|
}
|
|
@@ -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;
|
|
@@ -370,13 +370,22 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
370
370
|
var curToolIndex = curToolList.findIndex(function (item) {
|
|
371
371
|
return (item === null || item === void 0 ? void 0 : item.id) === dataObj.id;
|
|
372
372
|
});
|
|
373
|
-
|
|
373
|
+
// 记录当前思考内容
|
|
374
|
+
var curContent = ((_curToolList$curToolI = curToolList[curToolIndex]) === null || _curToolList$curToolI === void 0 ? void 0 : _curToolList$curToolI.content) || '';
|
|
375
|
+
if (dataObj.moduleType === 'thinking') {
|
|
376
|
+
curContent = curContent + (dataObj.reasoningContent || '');
|
|
377
|
+
} else if (dataObj.moduleType === 'llm') {
|
|
378
|
+
var _dataObj$outputs;
|
|
379
|
+
curContent = curContent + ((dataObj === null || dataObj === void 0 || (_dataObj$outputs = dataObj.outputs) === null || _dataObj$outputs === void 0 || (_dataObj$outputs = _dataObj$outputs.result) === null || _dataObj$outputs === void 0 ? void 0 : _dataObj$outputs.reasoning_content) || '');
|
|
380
|
+
} else {
|
|
381
|
+
curContent = curContent + (dataObj.content || '');
|
|
382
|
+
}
|
|
374
383
|
// 为新节点类型根据 status 生成 toolName
|
|
375
384
|
var isNewNodeType = !['tool_invocation', 'tool_result', "agent"].includes(dataObj.moduleType);
|
|
376
385
|
var toolName = isNewNodeType ? getToolNameByStatus(dataObj.moduleType, dataObj.status) : dataObj.toolName;
|
|
377
386
|
if (curToolIndex >= 0) {
|
|
378
387
|
curToolList[curToolIndex] = _objectSpread(_objectSpread({}, curToolList[curToolIndex]), {}, {
|
|
379
|
-
content:
|
|
388
|
+
content: curContent,
|
|
380
389
|
// tool_invocation 更新 toolName 和 status,新节点类型也更新
|
|
381
390
|
toolName: dataObj.moduleType === 'tool_invocation' ? dataObj.toolName || '' : isNewNodeType ? toolName : curToolList[curToolIndex].toolName,
|
|
382
391
|
status: dataObj.moduleType === 'tool_invocation' || isNewNodeType ? dataObj.status : curToolList[curToolIndex].status
|
|
@@ -572,7 +581,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
572
581
|
currentMessageList = messageListRef.current;
|
|
573
582
|
lastToolList = _toConsumableArray(currentMessageList[currentMessageList.length - 1].toolList || []);
|
|
574
583
|
newMessageList = [];
|
|
575
|
-
if (type === 'user_confirm') {
|
|
584
|
+
if (type === 'user_confirm' || type === 'ask') {
|
|
576
585
|
newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
|
|
577
586
|
moduleType: type,
|
|
578
587
|
moduleInfo: Response,
|
|
@@ -589,11 +598,11 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
589
598
|
toolList: [].concat(_toConsumableArray(lastToolList), [{
|
|
590
599
|
moduleType: type,
|
|
591
600
|
content: '',
|
|
592
|
-
data: Response,
|
|
601
|
+
data: type === 'ask' ? Response.data : Response,
|
|
593
602
|
status: "RUNNING",
|
|
594
603
|
toolName: t('chatApi.waitingForConfirmation'),
|
|
595
604
|
confirmStatus: "PENDING",
|
|
596
|
-
id: "".concat(new Date().getTime())
|
|
605
|
+
id: Response.id || "".concat(new Date().getTime())
|
|
597
606
|
}])
|
|
598
607
|
})]);
|
|
599
608
|
} else {
|