@myun/gimi-chat 0.9.71 → 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/apis/useApi.js +2 -2
- package/dist/components/answer-item/component/tool-list/index.d.ts +2 -1
- package/dist/components/answer-item/component/tool-list/index.js +165 -17
- package/dist/components/answer-item/component/tool-list/index.module.css +47 -0
- package/dist/components/answer-item/index.js +83 -30
- package/dist/components/chat-input/index.js +77 -22
- package/dist/components/chat-input/index.module.css +9 -4
- package/dist/components/knowledge-trace/KnowledgeIconComponent.js +10 -15
- package/dist/hooks/useChatActions.js +37 -16
- package/dist/hooks/useChatStream.js +17 -15
- package/dist/hooks/useCommonChatAPI.js +22 -7
- package/dist/i18n/locales/en-US.d.ts +2 -1
- package/dist/i18n/locales/en-US.js +2 -1
- package/dist/i18n/locales/zh-CN.d.ts +2 -1
- package/dist/i18n/locales/zh-CN.js +2 -1
- package/dist/interfaces/chatMessage.d.ts +3 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
package/dist/apis/useApi.js
CHANGED
|
@@ -622,7 +622,7 @@ var useApi = function useApi(baseUrl, authToken) {
|
|
|
622
622
|
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
623
623
|
while (1) switch (_context31.prev = _context31.next) {
|
|
624
624
|
case 0:
|
|
625
|
-
return _context31.abrupt("return", fetchService.get('/
|
|
625
|
+
return _context31.abrupt("return", fetchService.get('/mcourse/web/agent/thinking/effective', {
|
|
626
626
|
params: {
|
|
627
627
|
agentId: agentId
|
|
628
628
|
}
|
|
@@ -644,7 +644,7 @@ var useApi = function useApi(baseUrl, authToken) {
|
|
|
644
644
|
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
645
645
|
while (1) switch (_context32.prev = _context32.next) {
|
|
646
646
|
case 0:
|
|
647
|
-
return _context32.abrupt("return", fetchService.post('/
|
|
647
|
+
return _context32.abrupt("return", fetchService.post('/mcourse/web/agent/thinking/save', params));
|
|
648
648
|
case 1:
|
|
649
649
|
case "end":
|
|
650
650
|
return _context32.stop();
|
|
@@ -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;
|
|
@@ -13,16 +13,50 @@ import { MMarkdown } from '@myun/gimi-design';
|
|
|
13
13
|
import IconFont from "../../../iconfont-com";
|
|
14
14
|
import styles from "./index.module.css";
|
|
15
15
|
import classNames from "classnames";
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
// 思考工具项组件
|
|
18
|
+
var ThinkingToolItem = function ThinkingToolItem(_ref) {
|
|
17
19
|
var item = _ref.item,
|
|
18
20
|
customRender = _ref.customRender;
|
|
19
21
|
var _useState = useState(false),
|
|
20
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
21
23
|
showContent = _useState2[0],
|
|
22
24
|
setShowContent = _useState2[1];
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
className: styles.toolItem
|
|
27
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
28
|
+
className: styles.toolItemLabel,
|
|
29
|
+
onClick: function onClick() {
|
|
30
|
+
return item.content && setShowContent(!showContent);
|
|
31
|
+
}
|
|
32
|
+
}, item.status === "COMPLETED" && /*#__PURE__*/React.createElement("img", {
|
|
33
|
+
className: styles.toolIcon,
|
|
34
|
+
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202609/07/e5347_20260907085700.png"
|
|
35
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
36
|
+
className: classNames(styles.toolName, _defineProperty({}, styles.running, item.status === "RUNNING" || item.status === "STARTED"))
|
|
37
|
+
}, item.toolName), item.status === "COMPLETED" && item.content && /*#__PURE__*/React.createElement(IconFont, {
|
|
38
|
+
className: classNames(styles.icon, _defineProperty({}, styles.hasContent, showContent)),
|
|
39
|
+
type: showContent ? "icon-a-jiantoucu2x-copy1" : "icon-a-jiantoucu2x",
|
|
40
|
+
size: 12,
|
|
41
|
+
extraStyle: {
|
|
42
|
+
color: !showContent ? "var(--theme-neutral, #626262)" : "var(--theme-mediumNeutral, #B3B2B2)"
|
|
43
|
+
}
|
|
44
|
+
})), item.content && showContent && /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: styles.toolItemContent
|
|
46
|
+
}, /*#__PURE__*/React.createElement(MMarkdown, {
|
|
47
|
+
content: item.content,
|
|
48
|
+
customRender: customRender,
|
|
49
|
+
showLoading: item.status === "RUNNING"
|
|
50
|
+
})));
|
|
51
|
+
};
|
|
52
|
+
var ToolItemCom = function ToolItemCom(_ref2) {
|
|
53
|
+
var item = _ref2.item,
|
|
54
|
+
customRender = _ref2.customRender;
|
|
55
|
+
var _useState3 = useState(false),
|
|
56
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
57
|
+
showContent = _useState4[0],
|
|
58
|
+
setShowContent = _useState4[1];
|
|
23
59
|
var content = useMemo(function () {
|
|
24
|
-
// item.content 可能是:普通文本 / 单层 JSON / 双层 JSON 字符串
|
|
25
|
-
// 逐层 parse,直到结果不是字符串或 parse 失败为止
|
|
26
60
|
var result = item.content || '';
|
|
27
61
|
for (var depth = 0; depth < 2 && typeof result === 'string'; depth++) {
|
|
28
62
|
try {
|
|
@@ -31,10 +65,8 @@ var ToolItemCom = function ToolItemCom(_ref) {
|
|
|
31
65
|
break;
|
|
32
66
|
}
|
|
33
67
|
}
|
|
34
|
-
// parse 到底是字符串直接用;如果是对象,取里面的文本字段渲染
|
|
35
68
|
if (typeof result === 'string') return result;
|
|
36
69
|
if (result && typeof result.content === 'string') return result.content;
|
|
37
|
-
// 兜底:对象序列化
|
|
38
70
|
return JSON.stringify(result, null, 2);
|
|
39
71
|
}, [item.content]);
|
|
40
72
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -64,10 +96,10 @@ var ToolItemCom = function ToolItemCom(_ref) {
|
|
|
64
96
|
showLoading: item.status === "RUNNING"
|
|
65
97
|
})));
|
|
66
98
|
};
|
|
67
|
-
var ConfirmToolItem = function ConfirmToolItem(
|
|
99
|
+
var ConfirmToolItem = function ConfirmToolItem(_ref3) {
|
|
68
100
|
var _item$data;
|
|
69
|
-
var item =
|
|
70
|
-
handleClickConfirm =
|
|
101
|
+
var item = _ref3.item,
|
|
102
|
+
handleClickConfirm = _ref3.handleClickConfirm;
|
|
71
103
|
var confirmTextMap = {
|
|
72
104
|
PENDING: "等待人工确认",
|
|
73
105
|
CONFIRMED: "用户已同意",
|
|
@@ -101,18 +133,134 @@ var ConfirmToolItem = function ConfirmToolItem(_ref2) {
|
|
|
101
133
|
}
|
|
102
134
|
}, "\u62D2\u7EDD"))));
|
|
103
135
|
};
|
|
104
|
-
var
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
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;
|
|
108
239
|
return /*#__PURE__*/React.createElement("div", {
|
|
109
240
|
className: styles.toolList
|
|
110
241
|
}, toolList.map(function (item) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
242
|
+
if (item.moduleType === "user_confirm") {
|
|
243
|
+
return /*#__PURE__*/React.createElement(ConfirmToolItem, {
|
|
244
|
+
key: item.id,
|
|
245
|
+
item: item,
|
|
246
|
+
handleClickConfirm: handleClickConfirm
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (item.moduleType === "ask") {
|
|
250
|
+
return /*#__PURE__*/React.createElement(AskToolItem, {
|
|
251
|
+
key: item.id,
|
|
252
|
+
item: item,
|
|
253
|
+
handleClickAskList: handleClickAskList
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (item.moduleType === "thinking") {
|
|
257
|
+
return /*#__PURE__*/React.createElement(ThinkingToolItem, {
|
|
258
|
+
key: item.id,
|
|
259
|
+
item: item,
|
|
260
|
+
customRender: customRender
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return /*#__PURE__*/React.createElement(ToolItemCom, {
|
|
116
264
|
key: item.id,
|
|
117
265
|
item: item,
|
|
118
266
|
customRender: customRender
|
|
@@ -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% {
|
|
@@ -5,12 +5,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
8
10
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
11
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
12
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
13
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
13
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
14
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
15
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
16
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -21,7 +21,6 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
|
21
21
|
import { useTranslation } from 'react-i18next';
|
|
22
22
|
import styles from "./index.module.css";
|
|
23
23
|
import classNames from 'classnames';
|
|
24
|
-
import ReasoningContent from "../reasoning-content/index";
|
|
25
24
|
import { processString, formatDurationMs } from "../../utils/tools";
|
|
26
25
|
import { MMarkdown } from '@myun/gimi-design';
|
|
27
26
|
import WorkFlowContent from "../work-flow-content";
|
|
@@ -43,8 +42,10 @@ import Artifacts from "./component/artifacts";
|
|
|
43
42
|
import ChatContext from "../templates/chatContext";
|
|
44
43
|
import { setMessageList } from "../../store/slices/gimiMenuSlice";
|
|
45
44
|
import { TOOL_MODULE_TYPES, getToolNameByStatus } from "../../hooks/useChatStream";
|
|
45
|
+
import ReasoningSearch from "../reasoning-search";
|
|
46
|
+
import { Toast } from '@douyinfe/semi-ui';
|
|
46
47
|
var AnswerItem = function AnswerItem(_ref) {
|
|
47
|
-
var _item$thinkingInfo3, _item$thinkingInfo5, _item$thinkingInfo6, _item$thinkingInfo7, _item$
|
|
48
|
+
var _item$thinkingInfo3, _item$thinkingInfo5, _item$thinkingInfo6, _item$thinkingInfo7, _item$artifacts, _agentDetail$voiceCon;
|
|
48
49
|
var item = _ref.item,
|
|
49
50
|
onSucess = _ref.onSucess,
|
|
50
51
|
onFailure = _ref.onFailure,
|
|
@@ -117,17 +118,16 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
117
118
|
}
|
|
118
119
|
}, [platform]);
|
|
119
120
|
var _React$useMemo = React.useMemo(function () {
|
|
120
|
-
var _item$moduleInfo
|
|
121
|
+
var _item$moduleInfo;
|
|
121
122
|
var contentStr = item.content && processString(item.content) || '';
|
|
122
123
|
var showContentFlag = Boolean(contentStr);
|
|
123
|
-
|
|
124
|
-
var showSkillTag = item.moduleType === 'skill' || ((_item$
|
|
125
|
-
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;
|
|
126
127
|
var showTaskSuccess = (contentStr === null || contentStr === void 0 ? void 0 : contentStr.indexOf('<excel>')) > -1 && !isMsgRecieving;
|
|
127
128
|
var showRegerate = lastMessageId !== undefined && item.id === lastMessageId;
|
|
128
129
|
return {
|
|
129
130
|
showContentFlag: showContentFlag,
|
|
130
|
-
showAskTag: showAskTag,
|
|
131
131
|
showSkillTag: showSkillTag,
|
|
132
132
|
showOperation: showOperation,
|
|
133
133
|
showTaskSuccess: showTaskSuccess,
|
|
@@ -135,7 +135,6 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
135
135
|
};
|
|
136
136
|
}, [item.id, item.content, item.moduleType, item.moduleInfo, isMsgRecieving, lastMessageId]),
|
|
137
137
|
showContentFlag = _React$useMemo.showContentFlag,
|
|
138
|
-
showAskTag = _React$useMemo.showAskTag,
|
|
139
138
|
showSkillTag = _React$useMemo.showSkillTag,
|
|
140
139
|
showOperation = _React$useMemo.showOperation,
|
|
141
140
|
showTaskSuccess = _React$useMemo.showTaskSuccess,
|
|
@@ -193,13 +192,42 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
193
192
|
}, {
|
|
194
193
|
type: 'myunproduct',
|
|
195
194
|
component: ProductTag
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// }
|
|
201
|
-
];
|
|
195
|
+
}, {
|
|
196
|
+
type: 'search',
|
|
197
|
+
component: ReasoningSearch
|
|
198
|
+
}];
|
|
202
199
|
}, [onDownloadCallback, model, item.id]);
|
|
200
|
+
|
|
201
|
+
// 构造思考工具项
|
|
202
|
+
var thinkingToolItem = React.useMemo(function () {
|
|
203
|
+
if (!item.reasoningContent || item.vipLevel !== 1) return null;
|
|
204
|
+
return {
|
|
205
|
+
id: "thinking-".concat(item.id),
|
|
206
|
+
moduleType: 'thinking',
|
|
207
|
+
toolName: getToolNameByStatus('thinking', item.reasoningStatus === 1 ? 'RUNNING' : item.reasoningStatus === 2 ? 'COMPLETED' : 'FAILED'),
|
|
208
|
+
content: item.reasoningContent,
|
|
209
|
+
status: item.reasoningStatus === 1 ? 'RUNNING' : item.reasoningStatus === 2 ? 'COMPLETED' : 'FAILED'
|
|
210
|
+
};
|
|
211
|
+
}, [item.reasoningContent, item.reasoningStatus, item.vipLevel, item.id]);
|
|
212
|
+
|
|
213
|
+
// 合并工具列表
|
|
214
|
+
var mergedToolList = React.useMemo(function () {
|
|
215
|
+
var tools = _toConsumableArray(item.toolList || []);
|
|
216
|
+
if (thinkingToolItem) {
|
|
217
|
+
// 找到 moduleType 为 end 的索引
|
|
218
|
+
var endIndex = tools.findIndex(function (tool) {
|
|
219
|
+
return tool.moduleType === 'end';
|
|
220
|
+
});
|
|
221
|
+
if (endIndex !== -1) {
|
|
222
|
+
// 插入到 end 前面
|
|
223
|
+
tools.splice(endIndex, 0, thinkingToolItem);
|
|
224
|
+
} else {
|
|
225
|
+
// 没有 end,插入到结尾
|
|
226
|
+
tools.push(thinkingToolItem);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return tools;
|
|
230
|
+
}, [item.toolList, thinkingToolItem]);
|
|
203
231
|
var handleExpendThinking = /*#__PURE__*/function () {
|
|
204
232
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
205
233
|
var _item$thinkingInfo;
|
|
@@ -236,20 +264,21 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
236
264
|
try {
|
|
237
265
|
data = JSON.parse(item.eventData || '{}');
|
|
238
266
|
} catch (error) {}
|
|
239
|
-
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)) {
|
|
240
269
|
var _data2, _data3;
|
|
241
270
|
// 只处理工作流模式下的 tool_result,其他情况暂不处理
|
|
242
271
|
if (data.moduleType === 'tool_result' && ((_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.name) !== 'executeWorkflow') return;
|
|
243
272
|
|
|
244
273
|
// 为新节点类型根据 status 生成 toolName
|
|
245
|
-
var isNewNodeType = !['tool_invocation', 'tool_result', "user_confirm"].includes(item.moduleType);
|
|
274
|
+
var isNewNodeType = !['tool_invocation', 'tool_result', "user_confirm", 'ask'].includes(item.moduleType);
|
|
246
275
|
var toolName = isNewNodeType ? getToolNameByStatus(item.moduleType, 'COMPLETED') : (_data3 = data) === null || _data3 === void 0 ? void 0 : _data3.toolName;
|
|
247
276
|
var index = toolList.findIndex(function (v) {
|
|
248
277
|
var _data4;
|
|
249
278
|
return v.id === ((_data4 = data) === null || _data4 === void 0 ? void 0 : _data4.id);
|
|
250
279
|
});
|
|
251
280
|
if (index < 0) {
|
|
252
|
-
|
|
281
|
+
var newItem = {
|
|
253
282
|
data: _objectSpread(_objectSpread({}, data), {}, {
|
|
254
283
|
askingEventId: item.askingEventId
|
|
255
284
|
}),
|
|
@@ -259,7 +288,28 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
259
288
|
confirmStatus: item.confirmStatus,
|
|
260
289
|
id: data.id || item.id || +new Date(),
|
|
261
290
|
moduleType: item.moduleType
|
|
262
|
-
}
|
|
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);
|
|
263
313
|
} else {
|
|
264
314
|
toolList[index] = _objectSpread(_objectSpread({}, toolList[index]), {}, {
|
|
265
315
|
content: data.content || toolList[index].content
|
|
@@ -321,18 +371,13 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
321
371
|
className: classNames(styles.icon, _defineProperty({}, styles.hasContent, expendThinking)),
|
|
322
372
|
type: expendThinking ? "icon-a-jiantoucu2x-copy1" : "icon-a-jiantoucu2x",
|
|
323
373
|
size: 12
|
|
324
|
-
})), expendThinking && /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
325
|
-
toolList:
|
|
374
|
+
})), expendThinking && /*#__PURE__*/React.createElement(React.Fragment, null, mergedToolList.length > 0 && /*#__PURE__*/React.createElement(ToolList, {
|
|
375
|
+
toolList: mergedToolList,
|
|
326
376
|
handleClickConfirm: handleClickConfirm,
|
|
377
|
+
handleClickAskList: handleClickAskList,
|
|
327
378
|
customRender: customRender
|
|
328
|
-
}), item.vipLevel === 1 && item.reasoningContent && /*#__PURE__*/React.createElement(ReasoningContent, {
|
|
329
|
-
reasoningTitle: reasoningTitle,
|
|
330
|
-
item: item
|
|
331
379
|
}))), item.mcp && /*#__PURE__*/React.createElement(WorkFlowContent, {
|
|
332
380
|
chatItem: item
|
|
333
|
-
}), (agentDetail === null || agentDetail === void 0 ? void 0 : agentDetail.agentMode) === 'workflow' && item.vipLevel === 1 && item.reasoningContent && /*#__PURE__*/React.createElement(ReasoningContent, {
|
|
334
|
-
reasoningTitle: reasoningTitle,
|
|
335
|
-
item: item
|
|
336
381
|
}), showTaskSuccess && /*#__PURE__*/React.createElement("div", {
|
|
337
382
|
className: styles.completed
|
|
338
383
|
}, /*#__PURE__*/React.createElement(IconTickCircle, {
|
|
@@ -366,7 +411,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
366
411
|
}), enableUnLike && /*#__PURE__*/React.createElement(UnLikeButton, {
|
|
367
412
|
item: item,
|
|
368
413
|
onUnLikeCallback: onUnLikeCallback
|
|
369
|
-
}), enableVoicePlay && !
|
|
414
|
+
}), enableVoicePlay && !showSkillTag && ((_agentDetail$voiceCon = agentDetail.voiceConfigs) === null || _agentDetail$voiceCon === void 0 ? void 0 : _agentDetail$voiceCon.length) > 0 && /*#__PURE__*/React.createElement(VoicePlay, {
|
|
370
415
|
playTTSByText: playTTSByText,
|
|
371
416
|
stopTTSByText: stopTTSByText,
|
|
372
417
|
isVoicePlaying: isVoicePlaying,
|
|
@@ -395,6 +440,10 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
395
440
|
}, t('answer.courseRecommend')), (item.relatedCourseRecommendation || []).length > 4 && /*#__PURE__*/React.createElement("div", {
|
|
396
441
|
className: styles.course_recommend_header_more,
|
|
397
442
|
onClick: function onClick() {
|
|
443
|
+
if (platform === 'qiwei') {
|
|
444
|
+
Toast.info(t('trace.traceNotOpen'));
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
398
447
|
handleShowCourse(item);
|
|
399
448
|
}
|
|
400
449
|
}, /*#__PURE__*/React.createElement("span", {
|
|
@@ -407,7 +456,11 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
407
456
|
className: styles.courseItem,
|
|
408
457
|
key: course.id,
|
|
409
458
|
onClick: function onClick() {
|
|
410
|
-
|
|
459
|
+
if (platform === 'qiwei') {
|
|
460
|
+
Toast.info(t('trace.traceNotOpen'));
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
window.open(course.productType === 'project' ? "/project-product/".concat(course.productId || course.id) : "/new-product/".concat(course.productId || course.id));
|
|
411
464
|
}
|
|
412
465
|
}, /*#__PURE__*/React.createElement("div", {
|
|
413
466
|
className: styles.cover
|