@myun/gimi-chat 0.9.58 → 0.9.60

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.
@@ -101,6 +101,7 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
101
101
  var inputWrapRef = React.useRef(null);
102
102
  var preInputValueRef = React.useRef('');
103
103
  var inputRef = React.useRef(null);
104
+ var isTruncatingRef = React.useRef(false);
104
105
  var uploadFileRef = React.useRef(null);
105
106
  var conversationIdRef = React.useRef(conversationId);
106
107
  conversationIdRef.current = conversationId;
@@ -192,12 +193,49 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
192
193
  });
193
194
  var onContentChange = React.useCallback(function (content) {
194
195
  var _props$onValueChange;
196
+ // 长度按 extractText 的完整值计算(含 skill 序列化后的 <skilltool> 字符串)
195
197
  var value = extractText(content);
196
- if (value.length > maxInputLength) {
197
- var _inputRef$current4;
198
- Toast.warning(t('chatInput.maxLength'));
199
- value = value.slice(0, maxInputLength);
200
- (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 || _inputRef$current4.setContent(value);
198
+ var overflow = value.length - maxInputLength;
199
+ // 超限时从文档末尾倒着删掉多余的文本字符,只动文本节点,
200
+ // skill / refer-slot / titleSlot 等节点结构原样保留(不能用 setContent,会把富文本拍平成纯文本)
201
+ if (overflow > 0 && !isTruncatingRef.current) {
202
+ var _inputRef$current4, _inputRef$current4$ge;
203
+ var editor = (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 || (_inputRef$current4$ge = _inputRef$current4.getEditor) === null || _inputRef$current4$ge === void 0 ? void 0 : _inputRef$current4$ge.call(_inputRef$current4);
204
+ var ranges = [];
205
+ editor === null || editor === void 0 || editor.state.doc.descendants(function (node, pos) {
206
+ if (node.isText && node.text) {
207
+ ranges.push({
208
+ from: pos,
209
+ to: pos + node.text.length
210
+ });
211
+ }
212
+ return true;
213
+ });
214
+ var textTotal = ranges.reduce(function (sum, r) {
215
+ return sum + (r.to - r.from);
216
+ }, 0);
217
+ // 文本字符不足以抵掉超出量(超出来自 skill 节点本身),删也没用,避免死循环
218
+ if (editor && textTotal >= overflow) {
219
+ Toast.warning(t('chatInput.maxLength'));
220
+ var tr = editor.state.tr;
221
+ var remaining = overflow;
222
+ for (var i = ranges.length - 1; i >= 0 && remaining > 0; i--) {
223
+ var _ranges$i = ranges[i],
224
+ from = _ranges$i.from,
225
+ to = _ranges$i.to;
226
+ var take = Math.min(remaining, to - from);
227
+ tr.delete(tr.mapping.map(to - take), tr.mapping.map(to));
228
+ remaining -= take;
229
+ }
230
+ if (tr.docChanged) {
231
+ // 防止删除本身再次触发截断逻辑;删除后长度正好等于上限,
232
+ // 由它触发的这次回调会走下面的正常分支去同步 state
233
+ isTruncatingRef.current = true;
234
+ editor.view.dispatch(tr);
235
+ isTruncatingRef.current = false;
236
+ return;
237
+ }
238
+ }
201
239
  }
202
240
  setHasContent(value.trim().length > 0);
203
241
  preInputValueRef.current = value;
@@ -215,6 +215,7 @@ export var useChatStream = function useChatStream(platform) {
215
215
  saveLastEventId(messageId, event.id);
216
216
  }
217
217
  if (data.status === 0 && data.result && PROCESSABLE_MODULE_TYPES.includes(_dataObj.moduleType) && !_dataObj.ERROR) {
218
+ console.log('dataObj-----', _dataObj);
218
219
  if (_dataObj.status === 'RUNNING' && _dataObj.moduleType === 'end') {
219
220
  if (_dataObj.content && !_dataObj.reasoningContent) {
220
221
  fullResponse += _dataObj.content;
@@ -403,6 +403,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
403
403
  moduleType: dataObj.moduleType,
404
404
  artifacts: dataObj.artifacts || []
405
405
  })]);
406
+ console.log('handleArtifactStreamRs-----', newMessageList);
406
407
  dispatch(setMessageList({
407
408
  messageList: newMessageList
408
409
  }));
@@ -601,6 +602,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
601
602
  return v.moduleType !== "agent" && v.moduleType !== 'end';
602
603
  }))))]);
603
604
  }
605
+ console.log('end---------', newMessageList);
604
606
  dispatch(setMessageList({
605
607
  messageList: newMessageList
606
608
  }));
@@ -611,13 +613,13 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
611
613
  // 获取最新的agent详情,防止redux异步更新
612
614
  agentDetail = agentInfo || agentObjRef.current; // 获取推荐追问
613
615
  if (!((agentDetail === null || agentDetail === void 0 ? void 0 : agentDetail.isEnableRelated) === 1 && (type === 'end' || type === 'COMPLETED'))) {
614
- _context5.next = 12;
616
+ _context5.next = 13;
615
617
  break;
616
618
  }
617
619
  setMsgLoading(true);
618
- _context5.next = 12;
620
+ _context5.next = 13;
619
621
  return getRecommendList(newMessageList, lastId, statusRef.current);
620
- case 12:
622
+ case 13:
621
623
  // 获取相关课程
622
624
  userInput = newMessageList[newMessageList.length - 2].content;
623
625
  getRelatedCourses(userInput || '');
@@ -628,7 +630,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
628
630
  }
629
631
  setMsgLoading(false);
630
632
  onSendEnd === null || onSendEnd === void 0 || onSendEnd(newMessageList[newMessageList.length - 1]);
631
- case 17:
633
+ case 18:
632
634
  case "end":
633
635
  return _context5.stop();
634
636
  }