@myun/gimi-chat 0.9.52 → 0.9.53

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.
@@ -105,8 +105,8 @@ var AnswerItem = function AnswerItem(_ref) {
105
105
  var messageList = useAppSelector(function (state) {
106
106
  return state.gimiMenu.messageList;
107
107
  });
108
- var agentObj = useAppSelector(function (state) {
109
- return state.gimiMenu.agentObj || {};
108
+ var conversationId = useAppSelector(function (state) {
109
+ return state.gimiMenu.conversationId || '';
110
110
  });
111
111
  var handleLinkClickCapture = React.useCallback(function (e) {
112
112
  if (platform !== 'preview') return;
@@ -216,8 +216,8 @@ var AnswerItem = function AnswerItem(_ref) {
216
216
  setToolLoading(true);
217
217
  _context.next = 5;
218
218
  return apiService.getAgentToolList({
219
- conversationId: item.conversationId,
220
- chatId: item.chatId,
219
+ conversationId: item.conversationId || conversationId.toString() || '',
220
+ chatId: item.chatId || '',
221
221
  pageSize: 200
222
222
  });
223
223
  case 5:
@@ -298,10 +298,10 @@
298
298
  border-radius: 16px;
299
299
  }
300
300
  :global(.markdown_container) ul {
301
- list-style-type: disc;
301
+ list-style-type: disc !important;
302
302
  }
303
303
  :global(.markdown_container) ul > li::before {
304
- content: "";
304
+ content: "" !important;
305
305
  }
306
306
  @media (min-width: 1920px) {
307
307
  :global(.markdown_container) {
@@ -25,6 +25,7 @@ interface MentionListProps {
25
25
  query?: string;
26
26
  agentId?: number;
27
27
  apiService?: IUseApi | null;
28
+ getCurrentTextLength?: () => number;
28
29
  }
29
30
  declare const MentionList: React.ForwardRefExoticComponent<MentionListProps & React.RefAttributes<MentionListRef>>;
30
31
  export default MentionList;
@@ -5,6 +5,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5
5
  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; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
8
+ import { Toast } from '@douyinfe/semi-ui';
8
9
  import AiLoading from "../../../../components/ai-loading";
9
10
  import "./index.less";
10
11
  import { useTranslation } from 'react-i18next';
@@ -12,7 +13,8 @@ var MentionList = /*#__PURE__*/forwardRef(function (_ref, ref) {
12
13
  var command = _ref.command,
13
14
  query = _ref.query,
14
15
  agentId = _ref.agentId,
15
- apiService = _ref.apiService;
16
+ apiService = _ref.apiService,
17
+ getCurrentTextLength = _ref.getCurrentTextLength;
16
18
  var _useState = useState(0),
17
19
  _useState2 = _slicedToArray(_useState, 2),
18
20
  selectedIndex = _useState2[0],
@@ -98,6 +100,20 @@ var MentionList = /*#__PURE__*/forwardRef(function (_ref, ref) {
98
100
  var selectItem = function selectItem(id) {
99
101
  var item = filterOptions[id];
100
102
  if (item) {
103
+ if (getCurrentTextLength) {
104
+ var _item$toolId, _item$toolCategoryDes, _item$imageUrl, _item$toolName;
105
+ var serialized = "<skilltool>".concat(JSON.stringify({
106
+ toolId: (_item$toolId = item.toolId) !== null && _item$toolId !== void 0 ? _item$toolId : '',
107
+ toolType: (_item$toolCategoryDes = item.toolCategoryDesc) !== null && _item$toolCategoryDes !== void 0 ? _item$toolCategoryDes : '',
108
+ imageUrl: (_item$imageUrl = item.imageUrl) !== null && _item$imageUrl !== void 0 ? _item$imageUrl : '',
109
+ toolName: (_item$toolName = item.toolName) !== null && _item$toolName !== void 0 ? _item$toolName : ''
110
+ }), "</skilltool>");
111
+ var currentLen = getCurrentTextLength();
112
+ if (currentLen + serialized.length > 1000) {
113
+ Toast.warning(t('common.skillExceedLimit'));
114
+ return;
115
+ }
116
+ }
101
117
  command({
102
118
  item: item
103
119
  });
@@ -8,6 +8,7 @@ declare let skillContext: {
8
8
  getAgentId?: () => number | undefined;
9
9
  getApiService?: () => IUseApi | null;
10
10
  getSkillDisplay?: () => number | undefined;
11
+ getCurrentTextLength?: () => number;
11
12
  };
12
13
  export declare const setSkillContext: (ctx: Partial<typeof skillContext>) => void;
13
14
  export declare const suggestion: any;
@@ -100,6 +100,9 @@ export var suggestion = {
100
100
  render: function render() {
101
101
  var component;
102
102
  var reposition = null;
103
+ var outsideClickHandler = null;
104
+ var currentEditor = null;
105
+ var currentRange = null;
103
106
  return {
104
107
  onStart: function onStart(props) {
105
108
  var _skillContext$getSkil, _skillContext;
@@ -112,10 +115,14 @@ export var suggestion = {
112
115
  var _skillContext$getAgen, _skillContext2, _skillContext$getApiS, _skillContext$getApiS2, _skillContext3;
113
116
  var agentId = (_skillContext$getAgen = (_skillContext2 = skillContext).getAgentId) === null || _skillContext$getAgen === void 0 ? void 0 : _skillContext$getAgen.call(_skillContext2);
114
117
  var apiService = (_skillContext$getApiS = (_skillContext$getApiS2 = (_skillContext3 = skillContext).getApiService) === null || _skillContext$getApiS2 === void 0 ? void 0 : _skillContext$getApiS2.call(_skillContext3)) !== null && _skillContext$getApiS !== void 0 ? _skillContext$getApiS : null;
118
+ var getCurrentTextLength = skillContext.getCurrentTextLength;
119
+ currentEditor = props.editor;
120
+ currentRange = props.range;
115
121
  component = new ReactRenderer(MentionList, {
116
122
  props: _objectSpread(_objectSpread({}, props), {}, {
117
123
  agentId: agentId,
118
- apiService: apiService
124
+ apiService: apiService,
125
+ getCurrentTextLength: getCurrentTextLength
119
126
  }),
120
127
  editor: props.editor
121
128
  });
@@ -133,34 +140,54 @@ export var suggestion = {
133
140
  };
134
141
  window.addEventListener('resize', reposition);
135
142
  window.addEventListener('scroll', reposition, true);
143
+ outsideClickHandler = function outsideClickHandler(e) {
144
+ var _component;
145
+ if (!((_component = component) !== null && _component !== void 0 && _component.element)) return;
146
+ if (component.element.contains(e.target)) return;
147
+ e.stopPropagation();
148
+ // 手动移除面板 DOM,再通过内容变更让 suggestion plugin 退出
149
+ component.element.remove();
150
+ if (currentEditor && currentRange) {
151
+ var insertPos = currentRange.from;
152
+ currentEditor.chain().focus().deleteRange(currentRange).insertContentAt(insertPos, '/').run();
153
+ }
154
+ };
155
+ document.addEventListener('mousedown', outsideClickHandler, true);
136
156
  } catch (e) {
137
157
  console.error('[skill] onStart render error:', e);
138
158
  }
139
159
  },
140
160
  onUpdate: function onUpdate(props) {
141
161
  if (!component) return;
162
+ currentRange = props.range;
142
163
  component.updateProps(props);
143
164
  // query 变化导致面板高度变化,重新判断上下翻转
144
165
  positionPanel(props.editor, component.element);
145
166
  },
146
167
  onKeyDown: function onKeyDown(props) {
147
- var _component, _component$onKeyDown;
168
+ var _component2, _component2$onKeyDown;
148
169
  function onExit() {
149
170
  component.destroy();
150
171
  }
151
- return (_component = component) === null || _component === void 0 || (_component = _component.ref) === null || _component === void 0 || (_component$onKeyDown = _component.onKeyDown) === null || _component$onKeyDown === void 0 ? void 0 : _component$onKeyDown.call(_component, _objectSpread(_objectSpread({}, props), {}, {
172
+ return (_component2 = component) === null || _component2 === void 0 || (_component2 = _component2.ref) === null || _component2 === void 0 || (_component2$onKeyDown = _component2.onKeyDown) === null || _component2$onKeyDown === void 0 ? void 0 : _component2$onKeyDown.call(_component2, _objectSpread(_objectSpread({}, props), {}, {
152
173
  exitCb: onExit
153
174
  }));
154
175
  },
155
176
  onExit: function onExit() {
156
- var _component2, _component3;
177
+ var _component3, _component4;
157
178
  if (reposition) {
158
179
  window.removeEventListener('resize', reposition);
159
180
  window.removeEventListener('scroll', reposition, true);
160
181
  reposition = null;
161
182
  }
162
- (_component2 = component) === null || _component2 === void 0 || (_component2 = _component2.element) === null || _component2 === void 0 || _component2.remove();
163
- (_component3 = component) === null || _component3 === void 0 || _component3.destroy();
183
+ if (outsideClickHandler) {
184
+ document.removeEventListener('mousedown', outsideClickHandler, true);
185
+ outsideClickHandler = null;
186
+ }
187
+ currentEditor = null;
188
+ currentRange = null;
189
+ (_component3 = component) === null || _component3 === void 0 || (_component3 = _component3.element) === null || _component3 === void 0 || _component3.remove();
190
+ (_component4 = component) === null || _component4 === void 0 || _component4.destroy();
164
191
  },
165
192
  focusEditor: function focusEditor(props) {
166
193
  props.editor.commands.focus();
@@ -155,6 +155,9 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
155
155
  getSkillDisplay: function getSkillDisplay() {
156
156
  var _agentObjRef$current2;
157
157
  return (_agentObjRef$current2 = agentObjRef.current) === null || _agentObjRef$current2 === void 0 ? void 0 : _agentObjRef$current2.skillDisplay;
158
+ },
159
+ getCurrentTextLength: function getCurrentTextLength() {
160
+ return preInputValueRef.current.length;
158
161
  }
159
162
  });
160
163
  }, [apiService]);
@@ -189,9 +192,8 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
189
192
  });
190
193
  var onContentChange = React.useCallback(function (content) {
191
194
  var _props$onValueChange;
192
- var skipSkillVal = extractText(content, true);
193
195
  var value = extractText(content);
194
- if (skipSkillVal.length > 10000) {
196
+ if (value.length > 10000) {
195
197
  var _inputRef$current4;
196
198
  Toast.warning(t('chatInput.maxLength'));
197
199
  value = value.slice(0, 10000);
@@ -246,7 +246,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
246
246
 
247
247
  // 打断ai输出
248
248
  var handleInterrupt = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
249
- var uid, _parseMessageContent, content, _item, newMessageList, _newMessageList;
249
+ var uid, _parseMessageContent, content, _item, newMessageList, lastToolList, _newMessageList;
250
250
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
251
251
  while (1) switch (_context2.prev = _context2.next) {
252
252
  case 0:
@@ -296,6 +296,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
296
296
  }));
297
297
  }
298
298
  } else {
299
+ lastToolList = _toConsumableArray(messageList[messageList.length - 1].toolList || []);
299
300
  _newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
300
301
  loading: false,
301
302
  reasoningLoading: false,
@@ -306,10 +307,13 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
306
307
  mcp: null,
307
308
  thinkingInfo: {
308
309
  status: "COMPLETED",
309
- toolName: "已完成",
310
+ toolName: t('chatApi.completed'),
310
311
  collapse: true,
311
312
  loaded: false
312
- }
313
+ },
314
+ toolList: _toConsumableArray(lastToolList.filter(function (v) {
315
+ return v.moduleType !== "agent" && v.moduleType !== 'end';
316
+ }))
313
317
  })]);
314
318
  dispatch(setMessageList({
315
319
  messageList: _newMessageList
@@ -542,7 +546,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
542
546
  moduleType: 'end',
543
547
  content: '',
544
548
  status: "RUNNING",
545
- toolName: "正在整理答案",
549
+ toolName: t('chatApi.organizingAnswer'),
546
550
  id: "".concat(new Date().getTime())
547
551
  });
548
552
  }
@@ -571,7 +575,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
571
575
  mcp: null,
572
576
  thinkingInfo: {
573
577
  status: "RUNNING",
574
- toolName: "已完成",
578
+ toolName: t('chatApi.completed'),
575
579
  collapse: false,
576
580
  loaded: true
577
581
  },
@@ -580,7 +584,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
580
584
  content: '',
581
585
  data: Response,
582
586
  status: "RUNNING",
583
- toolName: "等待人工确认",
587
+ toolName: t('chatApi.waitingForConfirmation'),
584
588
  confirmStatus: "PENDING",
585
589
  id: "".concat(new Date().getTime())
586
590
  }])
@@ -590,7 +594,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
590
594
  moduleType: type
591
595
  }, type === 'end' ? 'content' : 'moduleInfo', Response), "reasoningResponse", type === 'end' ? reasoningResponse : ''), "loading", false), "reasoningLoading", false), "mcp", null), "durationMs", (dataObj === null || dataObj === void 0 ? void 0 : dataObj.elapsed) || 0), "totalTokens", (dataObj === null || dataObj === void 0 ? void 0 : dataObj.totalTokens) || 0), "thinkingInfo", {
592
596
  status: type === 'end' ? "COMPLETED" : "RUNNING",
593
- toolName: "已完成",
597
+ toolName: t('chatApi.completed'),
594
598
  collapse: true,
595
599
  loaded: true
596
600
  }), "toolList", _toConsumableArray(lastToolList.filter(function (v) {
@@ -636,13 +640,23 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
636
640
  }(), function () {
637
641
  setIgnoreOnMessage(true);
638
642
  var currentMessageList = messageListRef.current;
643
+ var lastToolList = [].concat(_toConsumableArray(currentMessageList[currentMessageList.length - 1].toolList || []), [{
644
+ moduleType: 'FAILED',
645
+ content: '',
646
+ status: "COMPLETED",
647
+ toolName: '服务异常',
648
+ id: "".concat(new Date().getTime())
649
+ }]);
639
650
  var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
640
651
  loading: false,
641
652
  reasoningLoading: false,
642
653
  stop: 0,
643
654
  reasoningStatus: 3,
644
655
  msgLoading: false,
645
- mcp: null
656
+ mcp: null,
657
+ toolList: _toConsumableArray(lastToolList.filter(function (v) {
658
+ return v.moduleType !== "agent" && v.moduleType !== 'end';
659
+ }))
646
660
  })]);
647
661
  dispatch(setMessageList({
648
662
  messageList: newMessageList
@@ -98,6 +98,7 @@ declare const enUS: {
98
98
  'common.pleaseWait': string;
99
99
  'common.empty': string;
100
100
  'common.noSkill': string;
101
+ 'common.skillExceedLimit': string;
101
102
  'common.delete': string;
102
103
  'common.cancel': string;
103
104
  'common.retry': string;
@@ -166,6 +167,9 @@ declare const enUS: {
166
167
  'chatApi.deleteSuccess': string;
167
168
  'chatApi.deleteFailed': string;
168
169
  'chatApi.noRequestToCancel': string;
170
+ 'chatApi.completed': string;
171
+ 'chatApi.organizingAnswer': string;
172
+ 'chatApi.waitingForConfirmation': string;
169
173
  'messageAction.copy': string;
170
174
  'messageAction.likeDone': string;
171
175
  'messageAction.like': string;
@@ -98,6 +98,7 @@ var enUS = {
98
98
  'common.pleaseWait': 'Please wait...',
99
99
  'common.empty': 'No content',
100
100
  'common.noSkill': 'No Skill',
101
+ 'common.skillExceedLimit': 'Adding this skill will exceed the 10000-character limit. Please shorten your input first.',
101
102
  'common.delete': 'Delete',
102
103
  'common.cancel': 'Cancel',
103
104
  'common.retry': 'Retry',
@@ -166,6 +167,9 @@ var enUS = {
166
167
  'chatApi.deleteSuccess': 'Conversation deleted successfully',
167
168
  'chatApi.deleteFailed': 'Failed to delete conversation',
168
169
  'chatApi.noRequestToCancel': 'No request to cancel',
170
+ 'chatApi.completed': 'Completed',
171
+ 'chatApi.organizingAnswer': 'Organizing answer',
172
+ 'chatApi.waitingForConfirmation': 'Waiting for confirmation',
169
173
  'messageAction.copy': 'Copy',
170
174
  'messageAction.likeDone': 'Liked',
171
175
  'messageAction.like': 'Like',
@@ -100,6 +100,7 @@ declare const zhCN: {
100
100
  'common.pleaseWait': string;
101
101
  'common.empty': string;
102
102
  'common.noSkill': string;
103
+ 'common.skillExceedLimit': string;
103
104
  'common.delete': string;
104
105
  'common.cancel': string;
105
106
  'common.retry': string;
@@ -168,6 +169,9 @@ declare const zhCN: {
168
169
  'chatApi.deleteSuccess': string;
169
170
  'chatApi.deleteFailed': string;
170
171
  'chatApi.noRequestToCancel': string;
172
+ 'chatApi.completed': string;
173
+ 'chatApi.organizingAnswer': string;
174
+ 'chatApi.waitingForConfirmation': string;
171
175
  'messageAction.copy': string;
172
176
  'messageAction.likeDone': string;
173
177
  'messageAction.like': string;
@@ -100,6 +100,7 @@ var zhCN = {
100
100
  'common.pleaseWait': '请稍等...',
101
101
  'common.empty': '暂无内容',
102
102
  'common.noSkill': '暂无技能',
103
+ 'common.skillExceedLimit': '添加该技能后内容将超过10000字,请精简输入内容后再选择',
103
104
  'common.delete': '删除',
104
105
  'common.cancel': '取消',
105
106
  'common.retry': '重试',
@@ -168,6 +169,9 @@ var zhCN = {
168
169
  'chatApi.deleteSuccess': '删除会话成功',
169
170
  'chatApi.deleteFailed': '删除会话失败',
170
171
  'chatApi.noRequestToCancel': '没有可取消的请求',
172
+ 'chatApi.completed': '已完成',
173
+ 'chatApi.organizingAnswer': '正在整理答案',
174
+ 'chatApi.waitingForConfirmation': '等待人工确认',
171
175
  'messageAction.copy': '复制',
172
176
  'messageAction.likeDone': '已点赞',
173
177
  'messageAction.like': '点赞',