@myun/gimi-chat 0.9.48 → 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.
@@ -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: item.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
- if ([].concat(_toConsumableArray(TOOL_MODULE_TYPES), ["user_confirm"]).includes(item.moduleType)) {
236
- var _data;
237
- var data = null;
238
- try {
239
- data = JSON.parse(item.eventData || '{}');
240
- } catch (error) {}
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') : (_data = data) === null || _data === void 0 ? void 0 : _data.toolName;
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 _data2;
247
- return v.id === ((_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.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 {
@@ -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: text-bottom;
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
  }
@@ -214,4 +214,5 @@
214
214
  bottom: -24px;
215
215
  left: 50%;
216
216
  transform: translateX(-50%);
217
+ white-space: nowrap;
217
218
  }
@@ -2,7 +2,6 @@ import React, { useMemo } from 'react';
2
2
  import styles from "./index.module.css";
3
3
  var SkillTag = function SkillTag(_ref) {
4
4
  var value = _ref.value;
5
- console.log(value);
6
5
  var item = useMemo(function () {
7
6
  try {
8
7
  return JSON.parse(value);
@@ -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
- _context.prev = 4;
83
- _context.next = 7;
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 7:
87
+ case 8:
86
88
  Toast.success(t('action.copySuccess'));
87
- _context.next = 13;
89
+ _context.next = 14;
88
90
  break;
89
- case 10:
90
- _context.prev = 10;
91
- _context.t0 = _context["catch"](4);
91
+ case 11:
92
+ _context.prev = 11;
93
+ _context.t0 = _context["catch"](5);
92
94
  Toast.error(t('action.copyFailed'));
93
- case 13:
95
+ case 14:
94
96
  case "end":
95
97
  return _context.stop();
96
98
  }
97
- }, _callee, null, [[4, 10]]);
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
- if (dataObj.moduleType === 'agent' && curToolList.length > 0) return;
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
  });