@myun/gimi-chat 0.9.26 → 0.9.28
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/ai-chat-dialogue/index.js +4 -4
- package/dist/components/ai-chat-dialogue/index.module.css +7 -0
- package/dist/components/chat-input/index.js +19 -1
- package/dist/components/file-upload/index.js +36 -10
- package/dist/components/iconfont-com/index.js +1 -1
- package/dist/components/upload-list/CustomFile.js +15 -2
- package/dist/components/upload-list/ImageFile.js +22 -16
- package/dist/components/upload-list/imageFile.module.css +4 -12
- package/dist/hooks/useFile.d.ts +1 -0
- package/dist/hooks/useFile.js +51 -13
- package/dist/i18n/locales/en-US.js +1 -1
- package/dist/i18n/locales/zh-CN.js +1 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -987,7 +987,7 @@ var AiExplain = function AiExplain(_ref) {
|
|
|
987
987
|
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202508/08/f5b48_20250808145334.png",
|
|
988
988
|
alt: ""
|
|
989
989
|
})), /*#__PURE__*/React.createElement("div", {
|
|
990
|
-
className: classNames(styles.content, '
|
|
990
|
+
className: classNames(styles.content, 'dialogueSscrollBar'),
|
|
991
991
|
ref: containerRef
|
|
992
992
|
}, /*#__PURE__*/React.createElement("div", {
|
|
993
993
|
className: styles.container
|
|
@@ -1025,7 +1025,7 @@ var AiExplain = function AiExplain(_ref) {
|
|
|
1025
1025
|
className: styles.btnItem
|
|
1026
1026
|
}, /*#__PURE__*/React.createElement(IconFontCom, {
|
|
1027
1027
|
type: !showCaptions ? 'icon-a-tongyong-zhankaibeifen1' : 'icon-tongyong-zhankaibeifen1',
|
|
1028
|
-
size:
|
|
1028
|
+
size: 18,
|
|
1029
1029
|
extraStyle: {
|
|
1030
1030
|
cursor: 'pointer'
|
|
1031
1031
|
},
|
|
@@ -1046,7 +1046,7 @@ var AiExplain = function AiExplain(_ref) {
|
|
|
1046
1046
|
}
|
|
1047
1047
|
}, /*#__PURE__*/React.createElement(IconFontCom, {
|
|
1048
1048
|
type: "icon-a-mti-guaduanshi",
|
|
1049
|
-
size:
|
|
1049
|
+
size: 22
|
|
1050
1050
|
}))), /*#__PURE__*/React.createElement(Tooltip, {
|
|
1051
1051
|
zIndex: 10000,
|
|
1052
1052
|
placement: "top",
|
|
@@ -1061,7 +1061,7 @@ var AiExplain = function AiExplain(_ref) {
|
|
|
1061
1061
|
}
|
|
1062
1062
|
}, /*#__PURE__*/React.createElement(IconFontCom, {
|
|
1063
1063
|
type: audioEnabled ? 'icon-voice' : 'icon-a-voice1',
|
|
1064
|
-
size:
|
|
1064
|
+
size: 22
|
|
1065
1065
|
}))))))), document.body);
|
|
1066
1066
|
};
|
|
1067
1067
|
export default AiExplain;
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
overflow-y: scroll;
|
|
38
38
|
overflow-x: hidden;
|
|
39
39
|
padding-bottom: 10px;
|
|
40
|
+
scrollbar-width: none;
|
|
41
|
+
-ms-overflow-style: none;
|
|
42
|
+
}
|
|
43
|
+
.aiChat .main .content::-webkit-scrollbar {
|
|
44
|
+
display: none;
|
|
40
45
|
}
|
|
41
46
|
.aiChat .main .tips {
|
|
42
47
|
font-weight: 400;
|
|
@@ -148,6 +153,8 @@
|
|
|
148
153
|
cursor: not-allowed;
|
|
149
154
|
}
|
|
150
155
|
.aiChat .bottom .btnWrap .btnItem.hasBorder {
|
|
156
|
+
width: 36px;
|
|
157
|
+
height: 36px;
|
|
151
158
|
border-radius: 50%;
|
|
152
159
|
background: #ffffff;
|
|
153
160
|
box-shadow: 0px 2px 10px 0px rgba(153, 167, 191, 0.1);
|
|
@@ -479,8 +479,26 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
479
479
|
var _props$onSend;
|
|
480
480
|
var inputContents = content.inputContents || [];
|
|
481
481
|
var text = extractText(inputContents);
|
|
482
|
+
|
|
483
|
+
// 检查是否有文件正在上传或解析中
|
|
484
|
+
var uploadingFile = fileList === null || fileList === void 0 ? void 0 : fileList.find(function (file) {
|
|
485
|
+
return file.status === FileStatus.UPLOADING || file.status === FileStatus.PADDING || file.status === FileStatus.RETRING;
|
|
486
|
+
});
|
|
487
|
+
if (uploadingFile) {
|
|
488
|
+
var _inputRef$current7;
|
|
489
|
+
// 文件处理中,恢复输入内容,不发送
|
|
490
|
+
var message = '';
|
|
491
|
+
if (uploadingFile.status === FileStatus.UPLOADING || uploadingFile.status === FileStatus.RETRING) {
|
|
492
|
+
message = t('fileValidation.uploading');
|
|
493
|
+
} else if (uploadingFile.status === FileStatus.PADDING) {
|
|
494
|
+
message = t('fileValidation.parsing');
|
|
495
|
+
}
|
|
496
|
+
Toast.info(message);
|
|
497
|
+
(_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 || _inputRef$current7.setContent(text);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
482
500
|
(_props$onSend = props.onSend) === null || _props$onSend === void 0 || _props$onSend.call(props, text);
|
|
483
|
-
}, [props]);
|
|
501
|
+
}, [props, fileList, t]);
|
|
484
502
|
var renderConfigureArea = React.useCallback(function () {
|
|
485
503
|
return /*#__PURE__*/React.createElement("div", {
|
|
486
504
|
className: styles.configureArea
|
|
@@ -2,6 +2,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
2
2
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
5
10
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
11
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -13,6 +18,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
13
18
|
import { Upload, Toast, Button } from '@douyinfe/semi-ui';
|
|
14
19
|
import { IconPaperclip } from '@douyinfe/semi-icons';
|
|
15
20
|
import { useAppDispatch, useAppSelector } from "../../store/hooks";
|
|
21
|
+
import { useStore } from 'react-redux';
|
|
16
22
|
import { setFileList } from "../../store/slices/gimiMenuSlice";
|
|
17
23
|
import { FileStatus } from "../../interfaces/fileInterface";
|
|
18
24
|
import { useGimiFileUpload } from "../../hooks/useFile";
|
|
@@ -52,16 +58,22 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
52
58
|
var fileList = useAppSelector(function (s) {
|
|
53
59
|
return s.gimiMenu.fileList;
|
|
54
60
|
});
|
|
61
|
+
var store = useStore();
|
|
55
62
|
var baseUrl = useAppSelector(function (s) {
|
|
56
63
|
return s.gimiMenu.baseUrl;
|
|
57
64
|
});
|
|
58
65
|
var token = useAppSelector(function (s) {
|
|
59
66
|
return s.gimiMenu.token;
|
|
60
67
|
});
|
|
68
|
+
|
|
69
|
+
/** 取 store 中最新的 fileList,避免闭包快照导致并发写入互相覆盖 */
|
|
70
|
+
var getLatestFileList = function getLatestFileList() {
|
|
71
|
+
return store.getState().gimiMenu.fileList || [];
|
|
72
|
+
};
|
|
61
73
|
var uploadUrl = "https://".concat(baseUrl, "/mfilesvc/agentMessage/uploadFile");
|
|
62
74
|
var _useGimiFileUpload = useGimiFileUpload(props.onFileUploaded),
|
|
63
75
|
handleSSEFileAnalyize = _useGimiFileUpload.handleSSEFileAnalyize,
|
|
64
|
-
|
|
76
|
+
abortAll = _useGimiFileUpload.abortAll;
|
|
65
77
|
|
|
66
78
|
/** 保存原始 File:uid -> File */
|
|
67
79
|
var rawFileMapRef = React.useRef(new Map());
|
|
@@ -69,9 +81,12 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
69
81
|
/** 重试次数:uid -> count */
|
|
70
82
|
var retryCountMapRef = React.useRef(new Map());
|
|
71
83
|
|
|
84
|
+
/** 上传请求 controller:uid -> controller(与解析 controller 分开管理) */
|
|
85
|
+
var uploadControllerMapRef = React.useRef(new Map());
|
|
86
|
+
|
|
72
87
|
/** 验证文件数量和大小限制 */
|
|
73
88
|
var validateFileCount = function validateFileCount(newFile) {
|
|
74
|
-
var currentList =
|
|
89
|
+
var currentList = getLatestFileList();
|
|
75
90
|
var imageCount = currentList.filter(function (f) {
|
|
76
91
|
return f.isImage;
|
|
77
92
|
}).length;
|
|
@@ -117,14 +132,15 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
117
132
|
|
|
118
133
|
/** 更新 Redux 中的文件状态 */
|
|
119
134
|
var updateFile = function updateFile(file) {
|
|
120
|
-
|
|
135
|
+
// 从 store 读取最新 fileList,避免闭包快照导致并发写入互相覆盖/丢项
|
|
136
|
+
var currentList = getLatestFileList();
|
|
121
137
|
var existingIndex = currentList.findIndex(function (f) {
|
|
122
138
|
return f.uid === file.uid;
|
|
123
139
|
});
|
|
124
140
|
if (existingIndex >= 0) {
|
|
125
|
-
//
|
|
141
|
+
// 更新现有文件:以 store 中的当前项为基底,再覆盖传入字段,保留并发写入的进度等
|
|
126
142
|
var newList = _toConsumableArray(currentList);
|
|
127
|
-
newList[existingIndex] = file;
|
|
143
|
+
newList[existingIndex] = _objectSpread(_objectSpread({}, currentList[existingIndex]), file);
|
|
128
144
|
dispatch(setFileList({
|
|
129
145
|
fileList: newList
|
|
130
146
|
}));
|
|
@@ -180,7 +196,7 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
180
196
|
retryCountMapRef.current.set(file.uid, 0);
|
|
181
197
|
}
|
|
182
198
|
controller = new AbortController();
|
|
183
|
-
|
|
199
|
+
uploadControllerMapRef.current.set(file.uid, controller);
|
|
184
200
|
isImage = isImageFile(rawFile);
|
|
185
201
|
updateFile({
|
|
186
202
|
uid: file.uid,
|
|
@@ -292,10 +308,15 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
292
308
|
retryUpload(file.uid);
|
|
293
309
|
}, 1000);
|
|
294
310
|
case 52:
|
|
311
|
+
_context.prev = 52;
|
|
312
|
+
// 本次上传请求结束(含成功/失败/重试前),清理其 controller
|
|
313
|
+
uploadControllerMapRef.current.delete(file.uid);
|
|
314
|
+
return _context.finish(52);
|
|
315
|
+
case 55:
|
|
295
316
|
case "end":
|
|
296
317
|
return _context.stop();
|
|
297
318
|
}
|
|
298
|
-
}, _callee, null, [[15, 32]]);
|
|
319
|
+
}, _callee, null, [[15, 32, 52, 55]]);
|
|
299
320
|
}));
|
|
300
321
|
return function customRequest(_x) {
|
|
301
322
|
return _ref.apply(this, arguments);
|
|
@@ -304,8 +325,13 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
304
325
|
React.useImperativeHandle(ref, function () {
|
|
305
326
|
return {
|
|
306
327
|
abortUpload: function abortUpload() {
|
|
307
|
-
|
|
308
|
-
|
|
328
|
+
// 中断所有正在进行的上传请求(按 uid 独立管理)
|
|
329
|
+
uploadControllerMapRef.current.forEach(function (controller) {
|
|
330
|
+
return controller.abort();
|
|
331
|
+
});
|
|
332
|
+
uploadControllerMapRef.current.clear();
|
|
333
|
+
// 中断所有正在进行的文件解析(按 uid 独立管理)
|
|
334
|
+
abortAll();
|
|
309
335
|
},
|
|
310
336
|
handleSSEFileAnalyize: handleSSEFileAnalyize,
|
|
311
337
|
retryUpload: retryUpload,
|
|
@@ -335,7 +361,7 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
335
361
|
limit: MAX_TOTAL_COUNT
|
|
336
362
|
}));
|
|
337
363
|
},
|
|
338
|
-
multiple:
|
|
364
|
+
multiple: false,
|
|
339
365
|
accept: (accept === null || accept === void 0 ? void 0 : accept.join(',')) || DEFAULT_ACCEPT,
|
|
340
366
|
maxSize: maxSize * 1024,
|
|
341
367
|
onSizeError: function onSizeError() {
|
|
@@ -12,7 +12,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
12
12
|
*/
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import Icon from '@douyinfe/semi-icons';
|
|
15
|
-
var scriptUrl = '//at.alicdn.com/t/c/
|
|
15
|
+
var scriptUrl = '//at.alicdn.com/t/c/font_3429456_uja4kf0ar6.js';
|
|
16
16
|
|
|
17
17
|
// Load iconfont script
|
|
18
18
|
if (typeof document !== 'undefined' && scriptUrl) {
|
|
@@ -50,11 +50,21 @@ var CustomFile = function CustomFile(_ref) {
|
|
|
50
50
|
|
|
51
51
|
var isError = file.status === FileStatus.UPLOAD_FAILED || file.status === FileStatus.ANALYSE_FAILED || file.status === FileStatus.NETWORK_ERROR;
|
|
52
52
|
var isLoading = [FileStatus.PADDING, FileStatus.RETRING, FileStatus.UPLOADING].includes(file.status);
|
|
53
|
+
// 仅上传中阶段 fileUrl/fileIcon 尚未就绪;解析中(PADDING/RETRING)资源已就绪,应展示真实图
|
|
54
|
+
var isUploading = file.status === FileStatus.UPLOADING;
|
|
53
55
|
return /*#__PURE__*/React.createElement("div", {
|
|
54
56
|
className: styles.uploadBox
|
|
55
57
|
}, /*#__PURE__*/React.createElement("div", {
|
|
56
58
|
className: styles.uploadIcon
|
|
57
|
-
},
|
|
59
|
+
}, isUploading ? /*#__PURE__*/React.createElement("div", {
|
|
60
|
+
style: {
|
|
61
|
+
width: '24px',
|
|
62
|
+
height: '22px',
|
|
63
|
+
borderRadius: 4,
|
|
64
|
+
background: '#D9DCE5',
|
|
65
|
+
flexShrink: 0
|
|
66
|
+
}
|
|
67
|
+
}) : isImage ? /*#__PURE__*/React.createElement("img", {
|
|
58
68
|
src: file.fileUrl,
|
|
59
69
|
alt: "file-icon",
|
|
60
70
|
style: {
|
|
@@ -62,7 +72,10 @@ var CustomFile = function CustomFile(_ref) {
|
|
|
62
72
|
height: '36px',
|
|
63
73
|
objectFit: 'cover',
|
|
64
74
|
borderRadius: 8,
|
|
65
|
-
background:
|
|
75
|
+
background: '#D9DCE5'
|
|
76
|
+
},
|
|
77
|
+
onError: function onError(e) {
|
|
78
|
+
e.currentTarget.style.visibility = 'hidden';
|
|
66
79
|
}
|
|
67
80
|
}) : /*#__PURE__*/React.createElement("img", {
|
|
68
81
|
src: fileIcon,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import styles from "./imageFile.module.css";
|
|
4
|
-
import reTry from "../../assets/image/retry.png";
|
|
5
4
|
import { FileStatus } from "../../interfaces/fileInterface";
|
|
6
5
|
import classNames from 'classnames';
|
|
6
|
+
import IconFontCom from "../iconfont-com";
|
|
7
7
|
var ImageFile = function ImageFile(_ref) {
|
|
8
8
|
var file = _ref.file,
|
|
9
9
|
handleDelFile = _ref.handleDelFile,
|
|
@@ -30,19 +30,23 @@ var ImageFile = function ImageFile(_ref) {
|
|
|
30
30
|
|
|
31
31
|
var isError = file.status === FileStatus.UPLOAD_FAILED || file.status === FileStatus.ANALYSE_FAILED || file.status === FileStatus.NETWORK_ERROR;
|
|
32
32
|
var isLoading = [FileStatus.PADDING, FileStatus.RETRING, FileStatus.UPLOADING].includes(file.status);
|
|
33
|
+
// 仅上传中阶段 fileUrl 尚未就绪;解析中(PADDING/RETRING)资源已就绪,应展示真实图片
|
|
34
|
+
var isUploading = file.status === FileStatus.UPLOADING;
|
|
33
35
|
return /*#__PURE__*/React.createElement("div", {
|
|
34
36
|
className: classNames(styles.uploadBox, isMessage ? styles.messageImg : styles.inputImg, isSingle ? styles.singleImg : '')
|
|
35
|
-
}, /*#__PURE__*/React.createElement("
|
|
37
|
+
}, isUploading ? /*#__PURE__*/React.createElement("div", {
|
|
38
|
+
className: classNames(styles.uploadImg),
|
|
39
|
+
style: {
|
|
40
|
+
background: '#D9DCE5'
|
|
41
|
+
}
|
|
42
|
+
}) : /*#__PURE__*/React.createElement("img", {
|
|
36
43
|
src: file.fileUrl,
|
|
37
44
|
alt: "file-icon",
|
|
38
|
-
className: classNames(styles.uploadImg)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}, isError && /*#__PURE__*/React.createElement("span", {
|
|
44
|
-
className: styles.errorText
|
|
45
|
-
}, file.status === FileStatus.UPLOAD_FAILED ? t('upload.status.uploadFailed') : file.status === FileStatus.NETWORK_ERROR ? t('upload.status.networkError') : t('upload.status.parseFailed')))), isLoading && /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: classNames(styles.uploadImg),
|
|
46
|
+
onError: function onError(e) {
|
|
47
|
+
e.currentTarget.style.visibility = 'hidden';
|
|
48
|
+
}
|
|
49
|
+
}), isLoading && /*#__PURE__*/React.createElement("div", {
|
|
46
50
|
className: styles.uploadLoading
|
|
47
51
|
}, /*#__PURE__*/React.createElement("img", {
|
|
48
52
|
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202509/07/0a0fa_20250907093927.gif",
|
|
@@ -50,12 +54,14 @@ var ImageFile = function ImageFile(_ref) {
|
|
|
50
54
|
})), isError && /*#__PURE__*/React.createElement("div", {
|
|
51
55
|
className: styles.uploadError,
|
|
52
56
|
onClick: handleRetryClick
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
}, /*#__PURE__*/React.createElement(IconFontCom, {
|
|
58
|
+
type: "icon-a-iconjichu1",
|
|
59
|
+
size: 16,
|
|
60
|
+
extraStyle: {
|
|
61
|
+
position: 'absolute',
|
|
62
|
+
top: '50%',
|
|
63
|
+
left: '50%',
|
|
64
|
+
transform: 'translate(-50%, -50%)'
|
|
59
65
|
}
|
|
60
66
|
})), showDel && /*#__PURE__*/React.createElement("div", {
|
|
61
67
|
className: styles.delIcon,
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
.uploadStatus,
|
|
47
|
-
.uploadLoading
|
|
47
|
+
.uploadLoading,
|
|
48
|
+
.uploadError {
|
|
48
49
|
position: absolute;
|
|
49
50
|
top: 0;
|
|
50
51
|
left: 0;
|
|
@@ -55,7 +56,8 @@
|
|
|
55
56
|
background: rgba(0, 0, 0, 0.4);
|
|
56
57
|
}
|
|
57
58
|
.uploadStatus img,
|
|
58
|
-
.uploadLoading img
|
|
59
|
+
.uploadLoading img,
|
|
60
|
+
.uploadError img {
|
|
59
61
|
position: absolute;
|
|
60
62
|
top: 50%;
|
|
61
63
|
left: 50%;
|
|
@@ -88,14 +90,4 @@
|
|
|
88
90
|
|
|
89
91
|
.uploadError {
|
|
90
92
|
cursor: pointer;
|
|
91
|
-
color: #4086ff;
|
|
92
|
-
text-align: right;
|
|
93
|
-
font-family: "PingFang SC";
|
|
94
|
-
font-size: 14px;
|
|
95
|
-
font-style: normal;
|
|
96
|
-
font-weight: 400;
|
|
97
|
-
line-height: normal;
|
|
98
|
-
margin-left: 20px;
|
|
99
|
-
display: flex;
|
|
100
|
-
align-items: center;
|
|
101
93
|
}
|
package/dist/hooks/useFile.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const retryWithExponentialBackoff: <T>(fn: () => Promise<T>, opti
|
|
|
8
8
|
}) => Promise<T | undefined>;
|
|
9
9
|
export declare const useGimiFileUpload: (onFileUploaded?: ((file: FileItem) => void) | undefined) => {
|
|
10
10
|
fileUploadAbortRef: import("react").MutableRefObject<AbortController | null>;
|
|
11
|
+
abortAll: () => void;
|
|
11
12
|
handleSSEFileAnalyize: (file: FileItem, autoRetry?: boolean) => void;
|
|
12
13
|
fileUpload: (file: any, autoRetry?: boolean) => void;
|
|
13
14
|
};
|
package/dist/hooks/useFile.js
CHANGED
|
@@ -85,6 +85,9 @@ var parseStrToObj = function parseStrToObj(value) {
|
|
|
85
85
|
export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
86
86
|
var _useTranslation = useTranslation(),
|
|
87
87
|
t = _useTranslation.t;
|
|
88
|
+
// 每个 uid 独立维护 AbortController,避免多文件并发解析时互相打断
|
|
89
|
+
var abortControllerMapRef = useRef(new Map());
|
|
90
|
+
// 兼容外部仅持有单个 ref 的调用:取最后一个存入的 controller
|
|
88
91
|
var abortControllerRef = useRef(null);
|
|
89
92
|
var token = useSelector(function (state) {
|
|
90
93
|
return state.gimiMenu.token;
|
|
@@ -97,11 +100,35 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
97
100
|
var IMAGE_ANALYIZE_URL = "https://".concat(baseUrl, "/mflux/api/llmRunning/instruction/run/question");
|
|
98
101
|
var dispatch = useDispatch();
|
|
99
102
|
var store = useStore();
|
|
103
|
+
|
|
104
|
+
/** 设置某个 uid 的 abort controller,并同步到最后存入的引用 */
|
|
105
|
+
var setAbortController = function setAbortController(uid, controller) {
|
|
106
|
+
if (controller) {
|
|
107
|
+
abortControllerMapRef.current.set(uid, controller);
|
|
108
|
+
abortControllerRef.current = controller;
|
|
109
|
+
} else {
|
|
110
|
+
abortControllerMapRef.current.delete(uid);
|
|
111
|
+
// 同步对外 ref:若当前指向的就是被清理的,则置空
|
|
112
|
+
if (abortControllerRef.current && !abortControllerMapRef.current.has(uid)) {
|
|
113
|
+
abortControllerRef.current = null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** 中断某个 uid 的解析(仅影响该 uid) */
|
|
119
|
+
var abortByUid = function abortByUid(uid) {
|
|
120
|
+
var controller = abortControllerMapRef.current.get(uid);
|
|
121
|
+
if (controller) {
|
|
122
|
+
controller.abort();
|
|
123
|
+
abortControllerMapRef.current.delete(uid);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
100
126
|
var changeFileStatus = function changeFileStatus(newStatus, file) {
|
|
101
127
|
var currentFileList = store.getState().gimiMenu.fileList || [];
|
|
102
128
|
var newFileList = currentFileList.map(function (item) {
|
|
103
129
|
if (item.uid === file.uid) {
|
|
104
|
-
|
|
130
|
+
// 基于 store 中的当前 item 更新,避免用旧快照覆盖并发写入的进度
|
|
131
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
105
132
|
status: newStatus
|
|
106
133
|
});
|
|
107
134
|
}
|
|
@@ -156,7 +183,8 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
156
183
|
currentFileList = store.getState().gimiMenu.fileList || [];
|
|
157
184
|
newFileList = currentFileList.map(function (item) {
|
|
158
185
|
if (item.uid === file.uid) {
|
|
159
|
-
|
|
186
|
+
// 基于 store 中的当前 item 更新,避免覆盖并发写入的进度
|
|
187
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
160
188
|
status: FileStatus.ANALYSE_SUCCESS,
|
|
161
189
|
content: data.result
|
|
162
190
|
});
|
|
@@ -184,7 +212,7 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
184
212
|
_context2.prev = 20;
|
|
185
213
|
_context2.t0 = _context2["catch"](2);
|
|
186
214
|
changeFileStatus(FileStatus.ANALYSE_FAILED, file);
|
|
187
|
-
Toast.error(
|
|
215
|
+
Toast.error(t('upload.parseFailed'));
|
|
188
216
|
case 24:
|
|
189
217
|
case "end":
|
|
190
218
|
return _context2.stop();
|
|
@@ -206,11 +234,10 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
206
234
|
// 非图片文件使用原有的 SSE 解析接口
|
|
207
235
|
var fetchSSE = function fetchSSE() {
|
|
208
236
|
changeFileStatus(FileStatus.PADDING, file);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
237
|
+
// 仅中断该 uid 上一次未完成的解析(如重试场景),不影响其它文件
|
|
238
|
+
abortByUid(file.uid);
|
|
212
239
|
var abortController = new AbortController();
|
|
213
|
-
|
|
240
|
+
setAbortController(file.uid, abortController);
|
|
214
241
|
var params = {
|
|
215
242
|
fileType: file.fileType,
|
|
216
243
|
fileUrl: file.fileUrl,
|
|
@@ -239,10 +266,11 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
239
266
|
var currentFileList = store.getState().gimiMenu.fileList || [];
|
|
240
267
|
var newFileList = currentFileList.map(function (item) {
|
|
241
268
|
if (item.uid === file.uid) {
|
|
242
|
-
|
|
269
|
+
// 基于 store 中的当前 item 更新,避免用旧快照覆盖并发写入的进度
|
|
270
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
243
271
|
status: data.statusCode === 'Success' ? FileStatus.ANALYSE_SUCCESS : FileStatus.PADDING,
|
|
244
272
|
process: data.process,
|
|
245
|
-
content: data.statusCode === 'Success' ? data.mdContent : ''
|
|
273
|
+
content: data.statusCode === 'Success' ? data.mdContent : item.content || ''
|
|
246
274
|
});
|
|
247
275
|
}
|
|
248
276
|
return item;
|
|
@@ -268,11 +296,11 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
268
296
|
}
|
|
269
297
|
},
|
|
270
298
|
onclose: function onclose() {
|
|
271
|
-
|
|
299
|
+
setAbortController(file.uid, null);
|
|
272
300
|
},
|
|
273
301
|
onerror: function onerror(error) {
|
|
274
302
|
abortController.abort();
|
|
275
|
-
|
|
303
|
+
setAbortController(file.uid, null);
|
|
276
304
|
reject(new Error(t('upload.parseFailed'))); // 将错误抛出以触发重试逻辑
|
|
277
305
|
throw error; // 抛出异常阻止默认的ES重连
|
|
278
306
|
}
|
|
@@ -290,13 +318,13 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
290
318
|
}
|
|
291
319
|
}).catch(function () {
|
|
292
320
|
changeFileStatus(FileStatus.ANALYSE_FAILED, file);
|
|
293
|
-
|
|
321
|
+
setAbortController(file.uid, null);
|
|
294
322
|
Toast.error(t('upload.parseFailedMaxRetry'));
|
|
295
323
|
});
|
|
296
324
|
} else {
|
|
297
325
|
fetchSSE().catch(function () {
|
|
298
326
|
changeFileStatus(FileStatus.ANALYSE_FAILED, file);
|
|
299
|
-
|
|
327
|
+
setAbortController(file.uid, null);
|
|
300
328
|
Toast.error(t('upload.parseFailed'));
|
|
301
329
|
});
|
|
302
330
|
}
|
|
@@ -384,8 +412,18 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
|
|
|
384
412
|
});
|
|
385
413
|
}
|
|
386
414
|
};
|
|
415
|
+
|
|
416
|
+
/** 中断所有正在进行的解析(供外部 abortUpload 调用) */
|
|
417
|
+
var abortAll = function abortAll() {
|
|
418
|
+
abortControllerMapRef.current.forEach(function (controller) {
|
|
419
|
+
return controller.abort();
|
|
420
|
+
});
|
|
421
|
+
abortControllerMapRef.current.clear();
|
|
422
|
+
abortControllerRef.current = null;
|
|
423
|
+
};
|
|
387
424
|
return {
|
|
388
425
|
fileUploadAbortRef: abortControllerRef,
|
|
426
|
+
abortAll: abortAll,
|
|
389
427
|
handleSSEFileAnalyize: handleSSEFileAnalyize,
|
|
390
428
|
fileUpload: fileUpload
|
|
391
429
|
};
|
|
@@ -15,7 +15,7 @@ var enUS = {
|
|
|
15
15
|
'chatInput.uploadLimitFive': 'Upload limit is 5 files',
|
|
16
16
|
'chatInput.uploadLimitTen': 'Upload limit is 10 files',
|
|
17
17
|
'chatInput.flowUnsupported': 'This button is not supported in the current flow. Please wait for the current flow to finish or follow the instructions on the chat card.',
|
|
18
|
-
'chatInput.uploadFile': 'Supports Word, Excel, images\nUp to 10 files (max
|
|
18
|
+
'chatInput.uploadFile': 'Supports Word, Excel, images\nUp to 10 files (max 10MB each)',
|
|
19
19
|
'chatInput.newConversation': 'New conversation',
|
|
20
20
|
'chatInput.deepThinkTip': 'System intelligently switches thinking mode',
|
|
21
21
|
'chatInput.deepThinkModeAuto': 'Thinking',
|
|
@@ -15,7 +15,7 @@ var zhCN = {
|
|
|
15
15
|
'chatInput.uploadLimitFive': '最多上传5个文件哦',
|
|
16
16
|
'chatInput.uploadLimitTen': '最多上传10个文件哦',
|
|
17
17
|
'chatInput.flowUnsupported': '当前流程不支持该按钮的使用,请等待正在进行的流程结束或按对话卡片指示继续流程',
|
|
18
|
-
'chatInput.uploadFile': '支持Word、Excel、图片\n最多10个文件(单个不超过
|
|
18
|
+
'chatInput.uploadFile': '支持Word、Excel、图片\n最多10个文件(单个不超过10M)',
|
|
19
19
|
'chatInput.newConversation': '新对话',
|
|
20
20
|
'chatInput.deepThinkTip': '系统智能切换思考模式',
|
|
21
21
|
'chatInput.deepThinkModeAuto': '思考',
|