@myun/gimi-chat 0.0.3 → 0.0.5
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/apis/fetch.d.ts +64 -0
- package/dist/apis/fetch.js +512 -0
- package/dist/apis/useApi.d.ts +57 -0
- package/dist/apis/useApi.js +378 -0
- package/dist/assets/image/Subtract.png +0 -0
- package/dist/assets/image/ai-logo.png +0 -0
- package/dist/assets/image/copyIcon.png +0 -0
- package/dist/assets/image/deepthinkActive.png +0 -0
- package/dist/assets/image/empty-img-dark.png +0 -0
- package/dist/assets/image/empty-img.png +0 -0
- package/dist/assets/image/like_active.png +0 -0
- package/dist/assets/image/love.png +0 -0
- package/dist/assets/image/retry.png +0 -0
- package/dist/assets/image/soundOut.png +0 -0
- package/dist/assets/image/unlike_active.png +0 -0
- package/dist/assets/image/unlove.png +0 -0
- package/dist/assets/lottie/ai-bg.json +1704 -0
- package/dist/assets/lottie/ai-loading.json +192 -0
- package/dist/assets/lottie/ai-output-loading.json +272 -0
- package/dist/assets/lottie/ai-output-normal.json +17694 -0
- package/dist/assets/lottie/ai-output-strengthen.json +17321 -0
- package/dist/assets/lottie/ai-voice-play.json +1 -0
- package/dist/assets/lottie/living.json +705 -0
- package/dist/assets/lottie/myun-living.json +726 -0
- package/dist/assets/lottie/myun-loading.json +530 -0
- package/dist/components/ai-chat-dialogue/index.d.ts +16 -0
- package/dist/components/ai-chat-dialogue/index.js +1056 -0
- package/dist/components/ai-chat-dialogue/index.module.css +230 -0
- package/dist/components/ai-chat-dialogue/message-parser.d.ts +36 -0
- package/dist/components/ai-chat-dialogue/message-parser.js +52 -0
- package/dist/components/ai-chat-dialogue/tlv.d.ts +7 -0
- package/dist/components/ai-chat-dialogue/tlv.js +32 -0
- package/dist/components/ai-chat-dialogue/volc-voice-call-client.d.ts +47 -0
- package/dist/components/ai-chat-dialogue/volc-voice-call-client.js +246 -0
- package/dist/components/ai-correction/index.d.ts +5 -0
- package/dist/components/ai-correction/index.js +45 -0
- package/dist/components/ai-loading/index.d.ts +3 -0
- package/dist/components/ai-loading/index.js +14 -0
- package/dist/components/ai-loading/index.module.css +11 -0
- package/dist/components/answer-item/index.d.ts +27 -0
- package/dist/components/answer-item/index.js +194 -0
- package/dist/components/answer-item/index.module.css +266 -0
- package/dist/components/ask-card/index.d.ts +10 -0
- package/dist/components/ask-card/index.js +76 -0
- package/dist/components/ask-card/index.module.css +122 -0
- package/dist/components/chat-input/index.d.ts +31 -0
- package/dist/components/chat-input/index.js +433 -0
- package/dist/components/chat-input/index.module.css +42 -0
- package/dist/components/chat-voice/VoiceCommunication.d.ts +7 -0
- package/dist/components/chat-voice/VoiceCommunication.js +69 -0
- package/dist/components/chat-voice/VoiceRecord.d.ts +7 -0
- package/dist/components/chat-voice/VoiceRecord.js +34 -0
- package/dist/components/conversation-delete/index.d.ts +5 -0
- package/dist/components/conversation-delete/index.js +24 -0
- package/dist/components/dots-loading/index.d.ts +2 -0
- package/dist/components/dots-loading/index.js +11 -0
- package/dist/components/dots-loading/index.module.css +41 -0
- package/dist/components/empty/index.d.ts +9 -0
- package/dist/components/empty/index.js +32 -0
- package/dist/components/empty/index.module.css +24 -0
- package/dist/components/excel-components/ExcelCard.d.ts +11 -0
- package/dist/components/excel-components/ExcelCard.js +35 -0
- package/dist/components/excel-components/ExcelExcuting.d.ts +10 -0
- package/dist/components/excel-components/ExcelExcuting.js +263 -0
- package/dist/components/excel-components/ExcelFailCard.d.ts +9 -0
- package/dist/components/excel-components/ExcelFailCard.js +20 -0
- package/dist/components/excel-components/ExcelSuccessCard.d.ts +5 -0
- package/dist/components/excel-components/ExcelSuccessCard.js +50 -0
- package/dist/components/excel-components/index.module.css +212 -0
- package/dist/components/excel-components/styles.module.css +178 -0
- package/dist/components/file-card/fileCardSidebar.d.ts +8 -0
- package/dist/components/file-card/fileCardSidebar.js +56 -0
- package/dist/components/file-card/index.d.ts +15 -0
- package/dist/components/file-card/index.js +97 -0
- package/dist/components/file-card/index.module.css +139 -0
- package/dist/components/file-preview/index.d.ts +3 -0
- package/dist/components/file-preview/index.js +227 -0
- package/dist/components/file-preview/index.module.css +83 -0
- package/dist/components/file-upload/index.d.ts +16 -0
- package/dist/components/file-upload/index.js +238 -0
- package/dist/components/file-upload/uploadV1.d.ts +16 -0
- package/dist/components/file-upload/uploadV1.js +267 -0
- package/dist/components/gimi-sidebar/index.d.ts +17 -0
- package/dist/components/gimi-sidebar/index.js +41 -0
- package/dist/components/gimi-sidebar/index.module.css +118 -0
- package/dist/components/header/index.d.ts +5 -0
- package/dist/components/header/index.js +20 -0
- package/dist/components/header/index.module.css +19 -0
- package/dist/components/iconfont-com/index.d.ts +11 -0
- package/dist/components/iconfont-com/index.js +29 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.d.ts +7 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.js +101 -0
- package/dist/components/knowledge-trace/classList.d.ts +6 -0
- package/dist/components/knowledge-trace/classList.js +72 -0
- package/dist/components/knowledge-trace/documentList.d.ts +6 -0
- package/dist/components/knowledge-trace/documentList.js +75 -0
- package/dist/components/knowledge-trace/index.d.ts +18 -0
- package/dist/components/knowledge-trace/index.js +155 -0
- package/dist/components/knowledge-trace/index.module.css +254 -0
- package/dist/components/knowledge-trace/interfaces.d.ts +166 -0
- package/dist/components/knowledge-trace/interfaces.js +1 -0
- package/dist/components/knowledge-trace/videoList.d.ts +6 -0
- package/dist/components/knowledge-trace/videoList.js +91 -0
- package/dist/components/lottie-img/index.d.ts +8 -0
- package/dist/components/lottie-img/index.js +99 -0
- package/dist/components/message-actions/CopyButton.d.ts +7 -0
- package/dist/components/message-actions/CopyButton.js +33 -0
- package/dist/components/message-actions/LikeButton.d.ts +7 -0
- package/dist/components/message-actions/LikeButton.js +34 -0
- package/dist/components/message-actions/RegenerateButton.d.ts +5 -0
- package/dist/components/message-actions/RegenerateButton.js +27 -0
- package/dist/components/message-actions/UnLikeButton.d.ts +7 -0
- package/dist/components/message-actions/UnLikeButton.js +34 -0
- package/dist/components/message-actions/VoicePlay.d.ts +10 -0
- package/dist/components/message-actions/VoicePlay.js +74 -0
- package/dist/components/message-list/index.d.ts +19 -0
- package/dist/components/message-list/index.js +164 -0
- package/dist/components/message-list/index.module.css +261 -0
- package/dist/components/no-microphone-root/index.d.ts +6 -0
- package/dist/components/no-microphone-root/index.js +36 -0
- package/dist/components/no-microphone-root/index.module.css +48 -0
- package/dist/components/preset-agent-content/index.d.ts +8 -0
- package/dist/components/preset-agent-content/index.js +24 -0
- package/dist/components/preset-agent-content/index.module.css +46 -0
- package/dist/components/quoted-content/index.d.ts +0 -0
- package/dist/components/quoted-content/index.js +171 -0
- package/dist/components/quoted-content/index.module.css +80 -0
- package/dist/components/reasoning-content/index.d.ts +6 -0
- package/dist/components/reasoning-content/index.js +116 -0
- package/dist/components/reasoning-content/index.module.css +169 -0
- package/dist/components/reference-content/index.d.ts +28 -0
- package/dist/components/reference-content/index.js +125 -0
- package/dist/components/reference-content/index.module.css +84 -0
- package/dist/components/templates/CommonChat.d.ts +5 -0
- package/dist/components/templates/CommonChat.js +218 -0
- package/dist/components/templates/GimiChatComponent.d.ts +4 -0
- package/dist/components/templates/GimiChatComponent.js +23 -0
- package/dist/components/templates/demo/demo.d.ts +2 -0
- package/dist/components/templates/demo/demo.js +109 -0
- package/dist/components/templates/index.module.css +109 -0
- package/dist/components/upload-list/index.d.ts +15 -0
- package/dist/components/upload-list/index.js +90 -0
- package/dist/components/upload-list/index.module.css +119 -0
- package/dist/components/voice-bars/index.d.ts +4 -0
- package/dist/components/voice-bars/index.js +174 -0
- package/dist/components/voice-check-dialog/index.d.ts +8 -0
- package/dist/components/voice-check-dialog/index.js +163 -0
- package/dist/components/voice-check-dialog/index.module.css +9 -0
- package/dist/components/voice-recording/index.d.ts +9 -0
- package/dist/components/voice-recording/index.js +54 -0
- package/dist/components/voice-recording/index.module.css +41 -0
- package/dist/components/work-flow-content/demo.d.ts +3 -0
- package/dist/components/work-flow-content/demo.js +11 -0
- package/dist/components/work-flow-content/index.d.ts +6 -0
- package/dist/components/work-flow-content/index.js +55 -0
- package/dist/components/work-flow-content/index.module.css +24 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +24 -0
- package/dist/hooks/useChatActions.d.ts +12 -0
- package/dist/hooks/useChatActions.js +207 -0
- package/dist/hooks/useChatHistory.d.ts +8 -0
- package/dist/hooks/useChatHistory.js +225 -0
- package/dist/hooks/useChatMessage.d.ts +49 -0
- package/dist/hooks/useChatMessage.js +87 -0
- package/dist/hooks/useChatRecommend.d.ts +8 -0
- package/dist/hooks/useChatRecommend.js +126 -0
- package/dist/hooks/useChatStream.d.ts +20 -0
- package/dist/hooks/useChatStream.js +244 -0
- package/dist/hooks/useChatUI.d.ts +32 -0
- package/dist/hooks/useChatUI.js +134 -0
- package/dist/hooks/useChatVoice.d.ts +11 -0
- package/dist/hooks/useChatVoice.js +379 -0
- package/dist/hooks/useCommonChatAPI.d.ts +27 -0
- package/dist/hooks/useCommonChatAPI.js +1276 -0
- package/dist/hooks/useFile.d.ts +13 -0
- package/dist/hooks/useFile.js +288 -0
- package/dist/hooks/useKnowledgeService.d.ts +17 -0
- package/dist/hooks/useKnowledgeService.js +210 -0
- package/dist/hooks/useLastEventId.d.ts +8 -0
- package/dist/hooks/useLastEventId.js +66 -0
- package/dist/hooks/useLongPoll.d.ts +3 -0
- package/dist/hooks/useLongPoll.js +111 -0
- package/dist/hooks/useScroll.d.ts +4 -0
- package/dist/hooks/useScroll.js +172 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/chatMessage.d.ts +139 -0
- package/dist/interfaces/fileInterface.d.ts +10 -0
- package/dist/interfaces/fileInterface.js +11 -0
- package/dist/interfaces/knowledgeTrace.d.ts +177 -0
- package/dist/store/hooks.d.ts +4 -0
- package/dist/store/hooks.js +3 -0
- package/dist/store/index.d.ts +7 -0
- package/dist/store/index.js +7 -0
- package/dist/store/slices/gimiMenuSlice.d.ts +95 -0
- package/dist/store/slices/gimiMenuSlice.js +251 -0
- package/dist/utils/chatInputUtil.d.ts +19 -0
- package/dist/utils/chatInputUtil.js +45 -0
- package/dist/utils/tools.d.ts +50 -0
- package/dist/utils/tools.js +474 -0
- package/dist/utils/voice-stream.d.ts +119 -0
- package/dist/utils/voice-stream.js +1162 -0
- package/package.json +5 -6
- package/LICENSE +0 -21
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FileItem } from '../types/file';
|
|
3
|
+
export declare const retryWithExponentialBackoff: <T>(fn: () => Promise<T>, options: {
|
|
4
|
+
maxRetries: number;
|
|
5
|
+
initialDelay: number;
|
|
6
|
+
factor: number;
|
|
7
|
+
onRetry?: ((attempt: number) => void) | undefined;
|
|
8
|
+
}) => Promise<T | undefined>;
|
|
9
|
+
export declare const useGimiFileUpload: () => {
|
|
10
|
+
fileUploadAbortRef: import("react").MutableRefObject<AbortController | null>;
|
|
11
|
+
handleSSEFileAnalyize: (file: FileItem, autoRetry?: boolean) => void;
|
|
12
|
+
fileUpload: (file: any, autoRetry?: boolean) => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
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; }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
10
|
+
import { useSelector, useDispatch } from 'react-redux';
|
|
11
|
+
import { setFileList } from "../store/slices/gimiMenuSlice";
|
|
12
|
+
import { useRef } from 'react';
|
|
13
|
+
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
14
|
+
// import { retryWithExponentialBackoff } from '../utils/tools';
|
|
15
|
+
import { Toast } from '@douyinfe/semi-ui';
|
|
16
|
+
import { FileStatus } from "../interfaces/fileInterface";
|
|
17
|
+
import { store } from "../store";
|
|
18
|
+
export var retryWithExponentialBackoff = /*#__PURE__*/function () {
|
|
19
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(fn, options) {
|
|
20
|
+
var maxRetries, initialDelay, factor, onRetry, attempt, delay, wait, response;
|
|
21
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
22
|
+
while (1) switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
maxRetries = options.maxRetries, initialDelay = options.initialDelay, factor = options.factor, onRetry = options.onRetry;
|
|
25
|
+
attempt = 0;
|
|
26
|
+
delay = initialDelay;
|
|
27
|
+
wait = function wait(delay) {
|
|
28
|
+
return new Promise(function (resolve) {
|
|
29
|
+
setTimeout(resolve, delay);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
case 4:
|
|
33
|
+
if (!(attempt <= maxRetries)) {
|
|
34
|
+
_context.next = 23;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
_context.prev = 5;
|
|
38
|
+
_context.next = 8;
|
|
39
|
+
return fn();
|
|
40
|
+
case 8:
|
|
41
|
+
response = _context.sent;
|
|
42
|
+
return _context.abrupt("return", response);
|
|
43
|
+
case 12:
|
|
44
|
+
_context.prev = 12;
|
|
45
|
+
_context.t0 = _context["catch"](5);
|
|
46
|
+
if (!(attempt === maxRetries)) {
|
|
47
|
+
_context.next = 16;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
throw _context.t0;
|
|
51
|
+
case 16:
|
|
52
|
+
if (onRetry) {
|
|
53
|
+
onRetry(attempt); // 调用重试回调
|
|
54
|
+
}
|
|
55
|
+
_context.next = 19;
|
|
56
|
+
return wait(delay);
|
|
57
|
+
case 19:
|
|
58
|
+
// 延迟
|
|
59
|
+
delay *= factor; // 指数增长
|
|
60
|
+
attempt++;
|
|
61
|
+
case 21:
|
|
62
|
+
_context.next = 4;
|
|
63
|
+
break;
|
|
64
|
+
case 23:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee, null, [[5, 12]]);
|
|
69
|
+
}));
|
|
70
|
+
return function retryWithExponentialBackoff(_x, _x2) {
|
|
71
|
+
return _ref.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}();
|
|
74
|
+
var parseStrToObj = function parseStrToObj(value) {
|
|
75
|
+
var result = value;
|
|
76
|
+
try {
|
|
77
|
+
while (typeof result === 'string') {
|
|
78
|
+
result = JSON.parse(result);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error('文件解析失败');
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
export var useGimiFileUpload = function useGimiFileUpload() {
|
|
86
|
+
var abortControllerRef = useRef(null);
|
|
87
|
+
var token = useSelector(function (state) {
|
|
88
|
+
return state.gimiMenu.token;
|
|
89
|
+
});
|
|
90
|
+
var baseUrl = useSelector(function (state) {
|
|
91
|
+
return state.gimiMenu.baseUrl;
|
|
92
|
+
});
|
|
93
|
+
var UPLOAD_URL = "https://".concat(baseUrl, "/mfilesvc/agentMessage/uploadFile");
|
|
94
|
+
var ANALYIZE_URL = "https://".concat(baseUrl, "/mbot/web/doc/realTimeParse");
|
|
95
|
+
var dispatch = useDispatch();
|
|
96
|
+
var changeFileStatus = function changeFileStatus(newStatus, file) {
|
|
97
|
+
var currentFileList = store.getState().gimiMenu.fileList || [];
|
|
98
|
+
var newFileList = currentFileList.map(function (item) {
|
|
99
|
+
if (item.uid === file.uid) {
|
|
100
|
+
return _objectSpread(_objectSpread({}, file), {}, {
|
|
101
|
+
status: newStatus
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return item;
|
|
105
|
+
});
|
|
106
|
+
dispatch(setFileList({
|
|
107
|
+
fileList: newFileList
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
var handleSSEFileAnalyize = function handleSSEFileAnalyize(file) {
|
|
111
|
+
var autoRetry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
112
|
+
var fetchSSE = function fetchSSE() {
|
|
113
|
+
changeFileStatus(FileStatus.PADDING, file);
|
|
114
|
+
if (abortControllerRef.current) {
|
|
115
|
+
abortControllerRef.current.abort();
|
|
116
|
+
}
|
|
117
|
+
var abortController = new AbortController();
|
|
118
|
+
abortControllerRef.current = abortController;
|
|
119
|
+
var params = {
|
|
120
|
+
fileType: file.fileType,
|
|
121
|
+
fileUrl: file.fileUrl,
|
|
122
|
+
fileSize: file.fileSize,
|
|
123
|
+
fileName: file.fileName
|
|
124
|
+
};
|
|
125
|
+
return new Promise(function (resolve, reject) {
|
|
126
|
+
fetchEventSource(ANALYIZE_URL, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
'Cache-Control': 'no-cache',
|
|
130
|
+
Connection: 'keep-alive',
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
Authorization: "Bearer ".concat(token)
|
|
133
|
+
},
|
|
134
|
+
body: JSON.stringify(params),
|
|
135
|
+
signal: abortController.signal,
|
|
136
|
+
onmessage: function onmessage(event) {
|
|
137
|
+
if (event.data === '[DONE]') {
|
|
138
|
+
resolve();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
var data = parseStrToObj(event.data);
|
|
143
|
+
if (!data.statusCode || data.statusCode === 'Success') {
|
|
144
|
+
var currentFileList = store.getState().gimiMenu.fileList || [];
|
|
145
|
+
var newFileList = currentFileList.map(function (item) {
|
|
146
|
+
if (item.uid === file.uid) {
|
|
147
|
+
return _objectSpread(_objectSpread({}, file), {}, {
|
|
148
|
+
status: data.statusCode === 'Success' ? FileStatus.ANALYSE_SUCCESS : FileStatus.PADDING,
|
|
149
|
+
process: data.process,
|
|
150
|
+
content: data.statusCode === 'Success' ? data.mdContent : ''
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return item;
|
|
154
|
+
});
|
|
155
|
+
dispatch(setFileList({
|
|
156
|
+
fileList: newFileList
|
|
157
|
+
}));
|
|
158
|
+
if (data.statusCode === 'Success') {
|
|
159
|
+
resolve();
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
reject(new Error(data.message || '文件解析失败'));
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
reject(new Error('文件解析失败'));
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
onclose: function onclose() {
|
|
169
|
+
abortControllerRef.current = null;
|
|
170
|
+
},
|
|
171
|
+
onerror: function onerror(error) {
|
|
172
|
+
abortController.abort();
|
|
173
|
+
abortControllerRef.current = null;
|
|
174
|
+
reject(new Error('文件解析失败')); // 将错误抛出以触发重试逻辑
|
|
175
|
+
throw error; // 抛出异常阻止默认的ES重连
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
if (autoRetry) {
|
|
181
|
+
retryWithExponentialBackoff(fetchSSE, {
|
|
182
|
+
maxRetries: 3,
|
|
183
|
+
initialDelay: 1000,
|
|
184
|
+
// 初始延迟 1 秒
|
|
185
|
+
factor: 2,
|
|
186
|
+
onRetry: function onRetry() {
|
|
187
|
+
changeFileStatus(FileStatus.RETRING, file);
|
|
188
|
+
}
|
|
189
|
+
}).catch(function () {
|
|
190
|
+
changeFileStatus(FileStatus.ANALYSE_FAILED, file);
|
|
191
|
+
abortControllerRef.current = null;
|
|
192
|
+
Toast.error('文件解析失败,已达到最大重试次数');
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
fetchSSE().catch(function () {
|
|
196
|
+
changeFileStatus(FileStatus.ANALYSE_FAILED, file);
|
|
197
|
+
abortControllerRef.current = null;
|
|
198
|
+
Toast.error('文件解析失败');
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var fileUpload = function fileUpload(file, autoRetry) {
|
|
203
|
+
var upload = /*#__PURE__*/function () {
|
|
204
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
205
|
+
var formData;
|
|
206
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
207
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
208
|
+
case 0:
|
|
209
|
+
formData = new FormData();
|
|
210
|
+
formData.append('file', file.originFileObj);
|
|
211
|
+
changeFileStatus(FileStatus.UPLOADING, file);
|
|
212
|
+
return _context2.abrupt("return", fetch(UPLOAD_URL, {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
headers: {
|
|
215
|
+
Authorization: "Bearer ".concat(token)
|
|
216
|
+
},
|
|
217
|
+
body: formData
|
|
218
|
+
}).then(function (response) {
|
|
219
|
+
return response.json();
|
|
220
|
+
}).then(function (response) {
|
|
221
|
+
var data = response[0];
|
|
222
|
+
var result = data === null || data === void 0 ? void 0 : data.result;
|
|
223
|
+
if ((data === null || data === void 0 ? void 0 : data.status) === 0 && result !== null && result !== void 0 && result.fileToken) {
|
|
224
|
+
Toast.success("".concat(file.name, " \u4E0A\u4F20\u6210\u529F"));
|
|
225
|
+
var responseObj = {
|
|
226
|
+
fileUrl: result.fileAddr,
|
|
227
|
+
fileName: result.fileName,
|
|
228
|
+
fileSize: result.fileSize,
|
|
229
|
+
fileToken: result.fileToken,
|
|
230
|
+
fileType: "".concat(result.fileName.split('.').pop())
|
|
231
|
+
};
|
|
232
|
+
// 更新文件列表,添加后端返回的信息
|
|
233
|
+
var currentFileList = store.getState().gimiMenu.fileList || [];
|
|
234
|
+
var newFileList = currentFileList.map(function (item) {
|
|
235
|
+
if (item.uid === file.uid) {
|
|
236
|
+
return _objectSpread(_objectSpread({}, item), responseObj);
|
|
237
|
+
}
|
|
238
|
+
return item;
|
|
239
|
+
});
|
|
240
|
+
dispatch(setFileList({
|
|
241
|
+
fileList: newFileList
|
|
242
|
+
}));
|
|
243
|
+
var pendingFile = currentFileList.find(function (item) {
|
|
244
|
+
return item.uid === file.uid;
|
|
245
|
+
});
|
|
246
|
+
handleSSEFileAnalyize(_objectSpread(_objectSpread({}, pendingFile), responseObj), true);
|
|
247
|
+
} else {
|
|
248
|
+
throw new Error('文件上传失败');
|
|
249
|
+
}
|
|
250
|
+
}).catch(function () {
|
|
251
|
+
throw new Error('文件上传失败');
|
|
252
|
+
}));
|
|
253
|
+
case 4:
|
|
254
|
+
case "end":
|
|
255
|
+
return _context2.stop();
|
|
256
|
+
}
|
|
257
|
+
}, _callee2);
|
|
258
|
+
}));
|
|
259
|
+
return function upload() {
|
|
260
|
+
return _ref2.apply(this, arguments);
|
|
261
|
+
};
|
|
262
|
+
}();
|
|
263
|
+
if (autoRetry) {
|
|
264
|
+
retryWithExponentialBackoff(upload, {
|
|
265
|
+
maxRetries: 2,
|
|
266
|
+
initialDelay: 2000,
|
|
267
|
+
// 初始延迟 1 秒
|
|
268
|
+
factor: 2,
|
|
269
|
+
onRetry: function onRetry() {
|
|
270
|
+
changeFileStatus(FileStatus.RETRING, file);
|
|
271
|
+
}
|
|
272
|
+
}).catch(function () {
|
|
273
|
+
changeFileStatus(FileStatus.UPLOAD_FAILED, file);
|
|
274
|
+
Toast.error('文件上传失败,已达到最大重试次数');
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
upload().catch(function (error) {
|
|
278
|
+
changeFileStatus(FileStatus.UPLOAD_FAILED, file);
|
|
279
|
+
Toast.error(error.message);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
fileUploadAbortRef: abortControllerRef,
|
|
285
|
+
handleSSEFileAnalyize: handleSSEFileAnalyize,
|
|
286
|
+
fileUpload: fileUpload
|
|
287
|
+
};
|
|
288
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IProduct, ITeachingModuleResource, IVideoResource } from "../components/knowledge-trace/interfaces";
|
|
2
|
+
import type { KonwledgeType } from "../components/knowledge-trace";
|
|
3
|
+
interface IProps {
|
|
4
|
+
type: KonwledgeType;
|
|
5
|
+
resources: {
|
|
6
|
+
id: string;
|
|
7
|
+
productIds?: number[];
|
|
8
|
+
}[];
|
|
9
|
+
qutoType?: 'teachModel' | 'product';
|
|
10
|
+
}
|
|
11
|
+
declare const useKnowledgeService: (props: IProps[]) => {
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
documentList: ITeachingModuleResource[];
|
|
14
|
+
videoSliceList: IVideoResource[];
|
|
15
|
+
productList: IProduct[];
|
|
16
|
+
};
|
|
17
|
+
export default useKnowledgeService;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
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
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
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
|
+
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; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
import React from "react";
|
|
17
|
+
import useApi from "../apis/useApi";
|
|
18
|
+
var useKnowledgeService = function useKnowledgeService(props) {
|
|
19
|
+
var _useApi = useApi(),
|
|
20
|
+
getProductList = _useApi.getProductList,
|
|
21
|
+
getFileResourceList = _useApi.getFileResourceList,
|
|
22
|
+
getVideoSliceList = _useApi.getVideoSliceList;
|
|
23
|
+
var _React$useState = React.useState(false),
|
|
24
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
25
|
+
isLoading = _React$useState2[0],
|
|
26
|
+
setIsloading = _React$useState2[1];
|
|
27
|
+
var _React$useState3 = React.useState([]),
|
|
28
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
29
|
+
productList = _React$useState4[0],
|
|
30
|
+
setProductList = _React$useState4[1];
|
|
31
|
+
var _React$useState5 = React.useState([]),
|
|
32
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
33
|
+
documentList = _React$useState6[0],
|
|
34
|
+
setDocumentList = _React$useState6[1];
|
|
35
|
+
var _React$useState7 = React.useState([]),
|
|
36
|
+
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
37
|
+
videoSliceList = _React$useState8[0],
|
|
38
|
+
setVideoSliceList = _React$useState8[1];
|
|
39
|
+
var getProducts = /*#__PURE__*/function () {
|
|
40
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item) {
|
|
41
|
+
var ids, res, _res$result;
|
|
42
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
43
|
+
while (1) switch (_context.prev = _context.next) {
|
|
44
|
+
case 0:
|
|
45
|
+
_context.prev = 0;
|
|
46
|
+
ids = item.resources.map(function (item) {
|
|
47
|
+
return item.id;
|
|
48
|
+
});
|
|
49
|
+
_context.next = 4;
|
|
50
|
+
return getProductList({
|
|
51
|
+
productIds: ids
|
|
52
|
+
});
|
|
53
|
+
case 4:
|
|
54
|
+
res = _context.sent;
|
|
55
|
+
if (res.status === 0 && res.result) {
|
|
56
|
+
setProductList((_res$result = res.result) === null || _res$result === void 0 ? void 0 : _res$result.map(function (item) {
|
|
57
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
58
|
+
isActive: false
|
|
59
|
+
});
|
|
60
|
+
}));
|
|
61
|
+
} else {
|
|
62
|
+
setProductList([]);
|
|
63
|
+
}
|
|
64
|
+
_context.next = 11;
|
|
65
|
+
break;
|
|
66
|
+
case 8:
|
|
67
|
+
_context.prev = 8;
|
|
68
|
+
_context.t0 = _context["catch"](0);
|
|
69
|
+
setProductList([]);
|
|
70
|
+
case 11:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context.stop();
|
|
73
|
+
}
|
|
74
|
+
}, _callee, null, [[0, 8]]);
|
|
75
|
+
}));
|
|
76
|
+
return function getProducts(_x) {
|
|
77
|
+
return _ref.apply(this, arguments);
|
|
78
|
+
};
|
|
79
|
+
}();
|
|
80
|
+
var getDocuments = /*#__PURE__*/function () {
|
|
81
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
|
|
82
|
+
var ids, res, _res$result2;
|
|
83
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
84
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
85
|
+
case 0:
|
|
86
|
+
_context2.prev = 0;
|
|
87
|
+
ids = item.resources.map(function (item) {
|
|
88
|
+
return item.id;
|
|
89
|
+
});
|
|
90
|
+
_context2.next = 4;
|
|
91
|
+
return getFileResourceList({
|
|
92
|
+
resourceIds: ids
|
|
93
|
+
});
|
|
94
|
+
case 4:
|
|
95
|
+
res = _context2.sent;
|
|
96
|
+
if (res.status === 0 && res.result) {
|
|
97
|
+
setDocumentList((_res$result2 = res.result) === null || _res$result2 === void 0 ? void 0 : _res$result2.map(function (item) {
|
|
98
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
99
|
+
isActive: false
|
|
100
|
+
});
|
|
101
|
+
}));
|
|
102
|
+
} else {
|
|
103
|
+
setDocumentList([]);
|
|
104
|
+
}
|
|
105
|
+
_context2.next = 11;
|
|
106
|
+
break;
|
|
107
|
+
case 8:
|
|
108
|
+
_context2.prev = 8;
|
|
109
|
+
_context2.t0 = _context2["catch"](0);
|
|
110
|
+
setDocumentList([]);
|
|
111
|
+
case 11:
|
|
112
|
+
case "end":
|
|
113
|
+
return _context2.stop();
|
|
114
|
+
}
|
|
115
|
+
}, _callee2, null, [[0, 8]]);
|
|
116
|
+
}));
|
|
117
|
+
return function getDocuments(_x2) {
|
|
118
|
+
return _ref2.apply(this, arguments);
|
|
119
|
+
};
|
|
120
|
+
}();
|
|
121
|
+
var getVideos = /*#__PURE__*/function () {
|
|
122
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
|
|
123
|
+
var params, res, _res$result3;
|
|
124
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
125
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
126
|
+
case 0:
|
|
127
|
+
_context3.prev = 0;
|
|
128
|
+
params = {
|
|
129
|
+
type: item.qutoType || 'product',
|
|
130
|
+
sliceQuotes: item.resources.map(function (resource) {
|
|
131
|
+
return {
|
|
132
|
+
resourceId: resource.productIds || [],
|
|
133
|
+
sliceId: resource.id
|
|
134
|
+
};
|
|
135
|
+
})
|
|
136
|
+
};
|
|
137
|
+
_context3.next = 4;
|
|
138
|
+
return getVideoSliceList(params);
|
|
139
|
+
case 4:
|
|
140
|
+
res = _context3.sent;
|
|
141
|
+
if (res.status === 0 && res.result) {
|
|
142
|
+
setVideoSliceList((_res$result3 = res.result) === null || _res$result3 === void 0 ? void 0 : _res$result3.map(function (item) {
|
|
143
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
144
|
+
isActive: false
|
|
145
|
+
});
|
|
146
|
+
}));
|
|
147
|
+
} else {
|
|
148
|
+
setVideoSliceList([]);
|
|
149
|
+
}
|
|
150
|
+
_context3.next = 11;
|
|
151
|
+
break;
|
|
152
|
+
case 8:
|
|
153
|
+
_context3.prev = 8;
|
|
154
|
+
_context3.t0 = _context3["catch"](0);
|
|
155
|
+
setVideoSliceList([]);
|
|
156
|
+
case 11:
|
|
157
|
+
case "end":
|
|
158
|
+
return _context3.stop();
|
|
159
|
+
}
|
|
160
|
+
}, _callee3, null, [[0, 8]]);
|
|
161
|
+
}));
|
|
162
|
+
return function getVideos(_x3) {
|
|
163
|
+
return _ref3.apply(this, arguments);
|
|
164
|
+
};
|
|
165
|
+
}();
|
|
166
|
+
React.useEffect(function () {
|
|
167
|
+
if ((props === null || props === void 0 ? void 0 : props.length) === 0) return;
|
|
168
|
+
var queryKnowledgeTraceList = /*#__PURE__*/function () {
|
|
169
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
170
|
+
var promiseList;
|
|
171
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
172
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
173
|
+
case 0:
|
|
174
|
+
setIsloading(true);
|
|
175
|
+
_context4.prev = 1;
|
|
176
|
+
promiseList = [];
|
|
177
|
+
props.forEach(function (item) {
|
|
178
|
+
var callFun = item.type === 'video' ? getVideos : item.type === 'document' ? getDocuments : getProducts;
|
|
179
|
+
promiseList.push(callFun(item));
|
|
180
|
+
});
|
|
181
|
+
_context4.next = 6;
|
|
182
|
+
return Promise.allSettled(promiseList);
|
|
183
|
+
case 6:
|
|
184
|
+
setIsloading(false);
|
|
185
|
+
_context4.next = 12;
|
|
186
|
+
break;
|
|
187
|
+
case 9:
|
|
188
|
+
_context4.prev = 9;
|
|
189
|
+
_context4.t0 = _context4["catch"](1);
|
|
190
|
+
console.error(_context4.t0);
|
|
191
|
+
case 12:
|
|
192
|
+
case "end":
|
|
193
|
+
return _context4.stop();
|
|
194
|
+
}
|
|
195
|
+
}, _callee4, null, [[1, 9]]);
|
|
196
|
+
}));
|
|
197
|
+
return function queryKnowledgeTraceList() {
|
|
198
|
+
return _ref4.apply(this, arguments);
|
|
199
|
+
};
|
|
200
|
+
}();
|
|
201
|
+
queryKnowledgeTraceList();
|
|
202
|
+
}, [props]);
|
|
203
|
+
return {
|
|
204
|
+
isLoading: isLoading,
|
|
205
|
+
documentList: documentList,
|
|
206
|
+
videoSliceList: videoSliceList,
|
|
207
|
+
productList: productList
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
export default useKnowledgeService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 管理 lastEventId 的 localStorage 操作
|
|
3
|
+
*/
|
|
4
|
+
export declare const useLastEventId: () => {
|
|
5
|
+
getLastEventId: (messageId: string | number) => number;
|
|
6
|
+
saveLastEventId: (messageId: string | number, eventId: string) => void;
|
|
7
|
+
removeLastEventId: (messageId: string | number) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 管理 lastEventId 的 localStorage 操作
|
|
3
|
+
*/
|
|
4
|
+
export var useLastEventId = function useLastEventId() {
|
|
5
|
+
/**
|
|
6
|
+
* 获取指定 messageId 的 lastEventId
|
|
7
|
+
*/
|
|
8
|
+
var getLastEventId = function getLastEventId(messageId) {
|
|
9
|
+
if (!messageId) {
|
|
10
|
+
console.error('❌ messageId未定义!无法获取lastEventId');
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
var lastEventObj = {};
|
|
14
|
+
try {
|
|
15
|
+
var storedStr = localStorage.getItem('lastEventId');
|
|
16
|
+
if (storedStr && storedStr.trim() !== '{}') {
|
|
17
|
+
lastEventObj = JSON.parse(storedStr);
|
|
18
|
+
}
|
|
19
|
+
} catch (parseErr) {
|
|
20
|
+
console.error('❌ 解析lastEventId失败(可能是存储格式异常):', parseErr);
|
|
21
|
+
localStorage.removeItem('lastEventId');
|
|
22
|
+
lastEventObj = {};
|
|
23
|
+
}
|
|
24
|
+
var targetKey = String(messageId);
|
|
25
|
+
return lastEventObj[targetKey] || 0;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 保存指定 messageId 的 lastEventId
|
|
30
|
+
*/
|
|
31
|
+
var saveLastEventId = function saveLastEventId(messageId, eventId) {
|
|
32
|
+
if (!messageId) return;
|
|
33
|
+
try {
|
|
34
|
+
var existingData = JSON.parse(localStorage.getItem('lastEventId') || '{}');
|
|
35
|
+
var targetKey = String(messageId);
|
|
36
|
+
existingData[targetKey] = eventId;
|
|
37
|
+
localStorage.setItem('lastEventId', JSON.stringify(existingData));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('❌ 保存lastEventId失败:', error);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 删除指定 messageId 的 lastEventId
|
|
45
|
+
*/
|
|
46
|
+
var removeLastEventId = function removeLastEventId(messageId) {
|
|
47
|
+
if (!messageId) return;
|
|
48
|
+
try {
|
|
49
|
+
var existingData = JSON.parse(localStorage.getItem('lastEventId') || '{}');
|
|
50
|
+
var targetKey = String(messageId);
|
|
51
|
+
delete existingData[targetKey];
|
|
52
|
+
if (Object.keys(existingData).length > 0) {
|
|
53
|
+
localStorage.setItem('lastEventId', JSON.stringify(existingData));
|
|
54
|
+
} else {
|
|
55
|
+
localStorage.removeItem('lastEventId');
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('❌ 删除lastEventId失败:', error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
getLastEventId: getLastEventId,
|
|
63
|
+
saveLastEventId: saveLastEventId,
|
|
64
|
+
removeLastEventId: removeLastEventId
|
|
65
|
+
};
|
|
66
|
+
};
|