@myun/gimi-chat 0.9.47 → 0.9.49
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 +19 -2
- package/dist/components/answer-item/index.js +26 -22
- package/dist/components/chat-input/extension/skill/index.less +3 -2
- package/dist/components/chat-input/index.module.css +1 -0
- package/dist/components/knowledge-trace/tryWatch.js +0 -1
- package/dist/components/message-list/skill-tag/index.js +0 -1
- package/dist/hooks/useChatActions.js +11 -9
- package/dist/hooks/useChatStream.js +2 -2
- package/dist/hooks/useCommonChatAPI.js +3 -2
- package/dist/umd/index.min.js +1 -1
- package/dist/utils/tools.js +1 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ 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, { useState } from "react";
|
|
11
|
+
import React, { useMemo, useState } from "react";
|
|
12
12
|
import { MMarkdown } from '@myun/gimi-design';
|
|
13
13
|
import IconFont from "../../../iconfont-com";
|
|
14
14
|
import styles from "./index.module.css";
|
|
@@ -19,6 +19,23 @@ var ToolItemCom = function ToolItemCom(_ref) {
|
|
|
19
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
20
20
|
showContent = _useState2[0],
|
|
21
21
|
setShowContent = _useState2[1];
|
|
22
|
+
var content = useMemo(function () {
|
|
23
|
+
// item.content 可能是:普通文本 / 单层 JSON / 双层 JSON 字符串
|
|
24
|
+
// 逐层 parse,直到结果不是字符串或 parse 失败为止
|
|
25
|
+
var result = item.content || '';
|
|
26
|
+
for (var depth = 0; depth < 2 && typeof result === 'string'; depth++) {
|
|
27
|
+
try {
|
|
28
|
+
result = JSON.parse(result);
|
|
29
|
+
} catch (_unused) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// parse 到底是字符串直接用;如果是对象,取里面的文本字段渲染
|
|
34
|
+
if (typeof result === 'string') return result;
|
|
35
|
+
if (result && typeof result.content === 'string') return result.content;
|
|
36
|
+
// 兜底:对象序列化
|
|
37
|
+
return JSON.stringify(result, null, 2);
|
|
38
|
+
}, [item.content]);
|
|
22
39
|
return /*#__PURE__*/React.createElement("div", {
|
|
23
40
|
className: styles.toolItem
|
|
24
41
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -38,7 +55,7 @@ var ToolItemCom = function ToolItemCom(_ref) {
|
|
|
38
55
|
})), item.content && showContent && /*#__PURE__*/React.createElement("div", {
|
|
39
56
|
className: styles.toolItemContent
|
|
40
57
|
}, /*#__PURE__*/React.createElement(MMarkdown, {
|
|
41
|
-
content:
|
|
58
|
+
content: content
|
|
42
59
|
})));
|
|
43
60
|
};
|
|
44
61
|
var ConfirmToolItem = function ConfirmToolItem(_ref2) {
|
|
@@ -204,13 +204,13 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
204
204
|
var handleExpendThinking = /*#__PURE__*/function () {
|
|
205
205
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
206
206
|
var _item$thinkingInfo;
|
|
207
|
-
var _res$result, res, list, toolList,
|
|
207
|
+
var _res$result, res, list, toolList, newMessageList;
|
|
208
208
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
209
209
|
while (1) switch (_context.prev = _context.next) {
|
|
210
210
|
case 0:
|
|
211
211
|
setExpendThinking(!expendThinking);
|
|
212
212
|
if (!(!((_item$thinkingInfo = item.thinkingInfo) !== null && _item$thinkingInfo !== void 0 && _item$thinkingInfo.loaded) && apiService)) {
|
|
213
|
-
_context.next =
|
|
213
|
+
_context.next = 14;
|
|
214
214
|
break;
|
|
215
215
|
}
|
|
216
216
|
setToolLoading(true);
|
|
@@ -232,25 +232,25 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
232
232
|
// 组装tool数据
|
|
233
233
|
toolList = [];
|
|
234
234
|
list.forEach(function (item) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
235
|
+
var _data;
|
|
236
|
+
var data = null;
|
|
237
|
+
try {
|
|
238
|
+
data = JSON.parse(item.eventData || '{}');
|
|
239
|
+
} catch (error) {}
|
|
240
|
+
if ([].concat(_toConsumableArray(TOOL_MODULE_TYPES), ["user_confirm", "stream"]).includes(item.moduleType) && !["execute", "notifyWorkflowStart"].includes((_data = data) === null || _data === void 0 ? void 0 : _data.name)) {
|
|
241
|
+
var _data2;
|
|
242
242
|
// 为新节点类型根据 status 生成 toolName
|
|
243
243
|
var isNewNodeType = !['tool_invocation', 'tool_result', "user_confirm"].includes(item.moduleType);
|
|
244
|
-
var toolName = isNewNodeType ? getToolNameByStatus(item.moduleType, 'COMPLETED') : (
|
|
244
|
+
var toolName = isNewNodeType ? getToolNameByStatus(item.moduleType, 'COMPLETED') : (_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.toolName;
|
|
245
245
|
var index = toolList.findIndex(function (v) {
|
|
246
|
-
var
|
|
247
|
-
return v.id === ((
|
|
246
|
+
var _data3;
|
|
247
|
+
return v.id === ((_data3 = data) === null || _data3 === void 0 ? void 0 : _data3.id);
|
|
248
248
|
});
|
|
249
249
|
if (index < 0) {
|
|
250
250
|
toolList.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
251
251
|
status: 'COMPLETED',
|
|
252
252
|
content: data.content || '',
|
|
253
|
-
toolName: toolName,
|
|
253
|
+
toolName: item.moduleType === 'stream' && item.status === 'TERMINATED' ? '技能调用已停止' : toolName,
|
|
254
254
|
confirmStatus: item.confirmStatus
|
|
255
255
|
}));
|
|
256
256
|
} else {
|
|
@@ -260,19 +260,23 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
|
|
264
|
+
// 注意:chatId 在 role=0(用户消息) 和 role=1(AI回复) 之间可能共享,
|
|
265
|
+
// 加 type === 1 确保只更新 AI 消息这一条
|
|
266
|
+
newMessageList = messageList.map(function (msg) {
|
|
267
|
+
return msg.chatId === item.chatId && msg.type === 1 ? _objectSpread(_objectSpread({}, msg), {}, {
|
|
268
|
+
moduleType: item.moduleType,
|
|
269
|
+
toolList: toolList,
|
|
270
|
+
thinkingInfo: _objectSpread(_objectSpread({}, item.thinkingInfo), {}, {
|
|
271
|
+
loaded: true
|
|
272
|
+
})
|
|
273
|
+
}) : msg;
|
|
274
|
+
});
|
|
271
275
|
dispatch(setMessageList({
|
|
272
276
|
messageList: newMessageList
|
|
273
277
|
}));
|
|
274
278
|
setToolLoading(false);
|
|
275
|
-
case
|
|
279
|
+
case 14:
|
|
276
280
|
case "end":
|
|
277
281
|
return _context.stop();
|
|
278
282
|
}
|
|
@@ -81,14 +81,13 @@
|
|
|
81
81
|
border-radius: 10px;
|
|
82
82
|
background:#E3E3E1;
|
|
83
83
|
padding: 0 8px;
|
|
84
|
-
height: 24px;
|
|
85
84
|
line-height: 24px;
|
|
86
85
|
margin-right: 6px;
|
|
87
86
|
.ai-chat-input-refer-slot {
|
|
88
87
|
font-size: 14px;
|
|
89
88
|
color: var(--theme-deepNeutral, #221813);
|
|
90
89
|
font-weight: 500;
|
|
91
|
-
vertical-align:
|
|
90
|
+
vertical-align: middle;
|
|
92
91
|
|
|
93
92
|
}
|
|
94
93
|
.ai-chat-input-refer-slot-image {
|
|
@@ -96,5 +95,7 @@
|
|
|
96
95
|
height: 14px;
|
|
97
96
|
margin-right: 4px;
|
|
98
97
|
flex-shrink: 0;
|
|
98
|
+
vertical-align: middle;
|
|
99
|
+
|
|
99
100
|
}
|
|
100
101
|
}
|
|
@@ -282,7 +282,6 @@ var TryWatch = function TryWatch(_ref7) {
|
|
|
282
282
|
var handleDocument = function handleDocument() {
|
|
283
283
|
var searchParams = "gradeId=".concat(item.gradeId, "&teachModuleId=").concat(item.id, "&outlineId=").concat(item.courseId, "&phaseId=").concat(item.phaseId);
|
|
284
284
|
if (item.isJoinClass) {
|
|
285
|
-
window.open(item.resourceMountType === 'teachingModule' ? "/learningPage?".concat(searchParams) : item.productType === 'single' ? "/courseDetail/".concat(item.gradeId, "?trigger=resource") : "/class-project/".concat(item.gradeId, "/").concat(item.productId, "?trigger=resource"));
|
|
286
285
|
window.open(item.resourceMountType === 'teachingModule' ? "/learningPage?".concat(searchParams) : item.productType === 'single' ? "/courseDetail/".concat(item.gradeId, "?trigger=resource&resourcesId=").concat(item.hostId) : "/class-project/".concat(item.gradeId, "/").concat(item.productId, "?trigger=resource&resourcesId=").concat(item.hostId));
|
|
287
286
|
} else {
|
|
288
287
|
if (item.productType === 'single') {
|
|
@@ -79,22 +79,24 @@ export var usePureChatActions = function usePureChatActions() {
|
|
|
79
79
|
replaceTags.forEach(function (tag) {
|
|
80
80
|
text = text.replace(new RegExp("<".concat(tag, ">(.*?)</").concat(tag, ">"), 'g'), '');
|
|
81
81
|
});
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
// 过滤 <skilltool>...</skilltool> 标签及内容(含多行)
|
|
83
|
+
text = text.replace(/<skilltool>[\s\S]*?<\/skilltool>/gi, '');
|
|
84
|
+
_context.prev = 5;
|
|
85
|
+
_context.next = 8;
|
|
84
86
|
return navigator.clipboard.writeText(text);
|
|
85
|
-
case
|
|
87
|
+
case 8:
|
|
86
88
|
Toast.success(t('action.copySuccess'));
|
|
87
|
-
_context.next =
|
|
89
|
+
_context.next = 14;
|
|
88
90
|
break;
|
|
89
|
-
case
|
|
90
|
-
_context.prev =
|
|
91
|
-
_context.t0 = _context["catch"](
|
|
91
|
+
case 11:
|
|
92
|
+
_context.prev = 11;
|
|
93
|
+
_context.t0 = _context["catch"](5);
|
|
92
94
|
Toast.error(t('action.copyFailed'));
|
|
93
|
-
case
|
|
95
|
+
case 14:
|
|
94
96
|
case "end":
|
|
95
97
|
return _context.stop();
|
|
96
98
|
}
|
|
97
|
-
}, _callee, null, [[
|
|
99
|
+
}, _callee, null, [[5, 11]]);
|
|
98
100
|
}));
|
|
99
101
|
return function (_x) {
|
|
100
102
|
return _ref2.apply(this, arguments);
|
|
@@ -203,7 +203,6 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
203
203
|
dispatch(setIsMsgRecieving({
|
|
204
204
|
isMsgRecieving: true
|
|
205
205
|
}));
|
|
206
|
-
console.log('[onmessage] 收到消息:', event.data);
|
|
207
206
|
if (!(event !== null && event !== void 0 && event.data) || ignoreOnMessageRef.current) {
|
|
208
207
|
return;
|
|
209
208
|
}
|
|
@@ -230,7 +229,8 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
230
229
|
}
|
|
231
230
|
|
|
232
231
|
// 工具调用
|
|
233
|
-
if (TOOL_MODULE_TYPES.includes(_dataObj.moduleType)) {
|
|
232
|
+
if (TOOL_MODULE_TYPES.includes(_dataObj.moduleType) && !["execute", "notifyWorkflowStart"].includes(_dataObj.name)) {
|
|
233
|
+
// console.log('dataObj',dataObj);
|
|
234
234
|
onToolStream === null || onToolStream === void 0 || onToolStream(_dataObj);
|
|
235
235
|
}
|
|
236
236
|
// 生成产物
|
|
@@ -360,7 +360,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
360
360
|
});
|
|
361
361
|
|
|
362
362
|
// 为新节点类型根据 status 生成 toolName
|
|
363
|
-
var isNewNodeType = !['tool_invocation', 'tool_result'].includes(dataObj.moduleType);
|
|
363
|
+
var isNewNodeType = !['tool_invocation', 'tool_result', "agent"].includes(dataObj.moduleType);
|
|
364
364
|
var toolName = isNewNodeType ? getToolNameByStatus(dataObj.moduleType, dataObj.status) : dataObj.toolName;
|
|
365
365
|
if (curToolIndex >= 0) {
|
|
366
366
|
curToolList[curToolIndex] = _objectSpread(_objectSpread({}, curToolList[curToolIndex]), {}, {
|
|
@@ -372,7 +372,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
372
372
|
} else {
|
|
373
373
|
// 新增工具时,为新节点类型补充 toolName
|
|
374
374
|
// agent 类类型,保持只有一个 agent
|
|
375
|
-
|
|
375
|
+
// tool_result只是工具的结果,不能新增
|
|
376
|
+
if (dataObj.moduleType === 'agent' && curToolList.length > 0 || dataObj.moduleType === 'tool_result') return;
|
|
376
377
|
curToolList = curToolList.filter(function (tool) {
|
|
377
378
|
return tool.moduleType !== 'agent';
|
|
378
379
|
});
|