@myun/gimi-chat 0.9.58 → 0.9.59
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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;
|