@myun/gimi-chat 0.9.48 → 0.9.50
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 +13 -13
- package/dist/components/answer-item/index.module.css +5 -0
- package/dist/components/chat-input/extension/skill/index.less +3 -2
- package/dist/components/chat-input/index.module.css +1 -0
- 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 +5 -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) {
|
|
@@ -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 {
|
|
@@ -345,7 +345,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
345
345
|
artifacts: item.artifacts
|
|
346
346
|
}), showOperation && /*#__PURE__*/React.createElement("div", {
|
|
347
347
|
className: styles.opera
|
|
348
|
-
}, (showOpera === null || showOpera === void 0 ? void 0 : showOpera(item.id)) && !item.loading && /*#__PURE__*/React.createElement("div", {
|
|
348
|
+
}, (showOpera === null || showOpera === void 0 ? void 0 : showOpera(item.id)) && !item.loading && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
349
349
|
className: styles.opera_item
|
|
350
350
|
}, enableCopy && /*#__PURE__*/React.createElement(CopyButton, {
|
|
351
351
|
item: item,
|
|
@@ -366,7 +366,7 @@ var AnswerItem = function AnswerItem(_ref) {
|
|
|
366
366
|
onRegenerateClick: onRegenerateClick
|
|
367
367
|
})), /*#__PURE__*/React.createElement("div", {
|
|
368
368
|
className: styles.totalTokensWrap
|
|
369
|
-
}, item !== null && item !== void 0 && item.durationMs ? formatDurationMs(item.durationMs) : '', " ", platform === 'preview' && item.totalTokens ? " | ".concat(item.totalTokens, " Tokens") : '')), (item.relatedResourceList || []).length > 0 && (showCommend === null || showCommend === void 0 ? void 0 : showCommend(item.id)) && /*#__PURE__*/React.createElement("div", {
|
|
369
|
+
}, item !== null && item !== void 0 && item.durationMs ? formatDurationMs(item.durationMs) : '', " ", platform === 'preview' && item.totalTokens ? " | ".concat(item.totalTokens, " Tokens") : ''))), (item.relatedResourceList || []).length > 0 && (showCommend === null || showCommend === void 0 ? void 0 : showCommend(item.id)) && /*#__PURE__*/React.createElement("div", {
|
|
370
370
|
className: styles.quickInputList
|
|
371
371
|
}, (item.relatedResourceList || []).map(function (item, index) {
|
|
372
372
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -292,6 +292,11 @@
|
|
|
292
292
|
:global(.markdown_container) {
|
|
293
293
|
max-width: 800px;
|
|
294
294
|
}
|
|
295
|
+
:global(.markdown_container) img {
|
|
296
|
+
max-width: 200px;
|
|
297
|
+
max-height: 200px;
|
|
298
|
+
border-radius: 16px;
|
|
299
|
+
}
|
|
295
300
|
@media (min-width: 1920px) {
|
|
296
301
|
:global(.markdown_container) {
|
|
297
302
|
max-width: 1000px;
|
|
@@ -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
|
}
|
|
@@ -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
|
// 生成产物
|
|
@@ -351,6 +351,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
351
351
|
}));
|
|
352
352
|
}, [dispatch]);
|
|
353
353
|
var handleToolStreamRs = React.useCallback(function (dataObj) {
|
|
354
|
+
// 只处理工作流模式下的 tool_result,其他情况暂不处理
|
|
355
|
+
if (dataObj.moduleType === 'tool_result' && dataObj.name !== 'executeWorkflow') return;
|
|
354
356
|
setStatus(2);
|
|
355
357
|
var messageList = messageListRef.current;
|
|
356
358
|
var lastMessage = messageList[messageList.length - 1];
|
|
@@ -360,7 +362,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
360
362
|
});
|
|
361
363
|
|
|
362
364
|
// 为新节点类型根据 status 生成 toolName
|
|
363
|
-
var isNewNodeType = !['tool_invocation', 'tool_result'].includes(dataObj.moduleType);
|
|
365
|
+
var isNewNodeType = !['tool_invocation', 'tool_result', "agent"].includes(dataObj.moduleType);
|
|
364
366
|
var toolName = isNewNodeType ? getToolNameByStatus(dataObj.moduleType, dataObj.status) : dataObj.toolName;
|
|
365
367
|
if (curToolIndex >= 0) {
|
|
366
368
|
curToolList[curToolIndex] = _objectSpread(_objectSpread({}, curToolList[curToolIndex]), {}, {
|
|
@@ -372,7 +374,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
372
374
|
} else {
|
|
373
375
|
// 新增工具时,为新节点类型补充 toolName
|
|
374
376
|
// agent 类类型,保持只有一个 agent
|
|
375
|
-
|
|
377
|
+
// tool_result只是工具的结果,不能新增
|
|
378
|
+
if (dataObj.moduleType === 'agent' && curToolList.length > 0 || dataObj.moduleType === 'tool_result') return;
|
|
376
379
|
curToolList = curToolList.filter(function (tool) {
|
|
377
380
|
return tool.moduleType !== 'agent';
|
|
378
381
|
});
|