@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,379 @@
|
|
|
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 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
|
+
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
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; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import VoiceRecorderEvent from "../utils/voice-stream";
|
|
12
|
+
import { useCallback, useState, useEffect, useRef, useMemo } from 'react';
|
|
13
|
+
import { Toast } from '@douyinfe/semi-ui';
|
|
14
|
+
import { useAppDispatch, useAppSelector } from "../store/hooks";
|
|
15
|
+
import { setShowMicWarning } from "../store/slices/gimiMenuSlice";
|
|
16
|
+
var useChatVoice = function useChatVoice() {
|
|
17
|
+
var _useState = useState(false),
|
|
18
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
19
|
+
isPlaying = _useState2[0],
|
|
20
|
+
setIsPlaying = _useState2[1];
|
|
21
|
+
var isPlayingRef = useRef(false);
|
|
22
|
+
var isRecordingRef = useRef(false);
|
|
23
|
+
var _useState3 = useState(false),
|
|
24
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
+
isRecording = _useState4[0],
|
|
26
|
+
setIsRecording = _useState4[1];
|
|
27
|
+
var _useState5 = useState(false),
|
|
28
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
+
isExecuting = _useState6[0],
|
|
30
|
+
setIsExecuting = _useState6[1];
|
|
31
|
+
var _useState7 = useState(''),
|
|
32
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
33
|
+
asrText = _useState8[0],
|
|
34
|
+
setAsrText = _useState8[1];
|
|
35
|
+
var _useState9 = useState(60),
|
|
36
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
37
|
+
recordingCount = _useState10[0],
|
|
38
|
+
setRecordingCount = _useState10[1]; // 录音时间,单位秒
|
|
39
|
+
var intervalRef = useRef(undefined);
|
|
40
|
+
var dispatch = useAppDispatch();
|
|
41
|
+
var agentObj = useAppSelector(function (state) {
|
|
42
|
+
return state.gimiMenu.agentObj;
|
|
43
|
+
});
|
|
44
|
+
var conversationId = useAppSelector(function (state) {
|
|
45
|
+
return state.gimiMenu.conversationId;
|
|
46
|
+
});
|
|
47
|
+
var voiceConfigs = useMemo(function () {
|
|
48
|
+
return (agentObj === null || agentObj === void 0 ? void 0 : agentObj.voiceConfigs) || [];
|
|
49
|
+
}, [agentObj]);
|
|
50
|
+
|
|
51
|
+
// 使用 ref 存储最新的状态值,避免闭包陷阱
|
|
52
|
+
var isPlayingStateRef = useRef(isPlaying);
|
|
53
|
+
var isRecordingStateRef = useRef(isRecording);
|
|
54
|
+
var isExecutingStateRef = useRef(isExecuting);
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
isPlayingStateRef.current = isPlaying;
|
|
57
|
+
}, [isPlaying]);
|
|
58
|
+
useEffect(function () {
|
|
59
|
+
isRecordingStateRef.current = isRecording;
|
|
60
|
+
}, [isRecording]);
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
isExecutingStateRef.current = isExecuting;
|
|
63
|
+
}, [isExecuting]);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 停止播放 TTS 语音
|
|
67
|
+
*/
|
|
68
|
+
var stopTTSByText = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
69
|
+
var _VoiceRecorderEvent$r, _VoiceRecorderEvent$d;
|
|
70
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
71
|
+
while (1) switch (_context.prev = _context.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
if (navigator.onLine) {
|
|
74
|
+
_context.next = 3;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
Toast.error('无法连接到网络');
|
|
78
|
+
return _context.abrupt("return");
|
|
79
|
+
case 3:
|
|
80
|
+
_context.prev = 3;
|
|
81
|
+
(_VoiceRecorderEvent$r = VoiceRecorderEvent.resetTTSPlayer) === null || _VoiceRecorderEvent$r === void 0 || _VoiceRecorderEvent$r.call(VoiceRecorderEvent);
|
|
82
|
+
_context.next = 7;
|
|
83
|
+
return (_VoiceRecorderEvent$d = VoiceRecorderEvent.disconnectHandler) === null || _VoiceRecorderEvent$d === void 0 ? void 0 : _VoiceRecorderEvent$d.call(VoiceRecorderEvent);
|
|
84
|
+
case 7:
|
|
85
|
+
setIsPlaying(false);
|
|
86
|
+
_context.next = 13;
|
|
87
|
+
break;
|
|
88
|
+
case 10:
|
|
89
|
+
_context.prev = 10;
|
|
90
|
+
_context.t0 = _context["catch"](3);
|
|
91
|
+
console.error("TTS \u64AD\u653E\u5173\u95ED\u5931\u8D25: ".concat(_context.t0.message || _context.t0), 'error');
|
|
92
|
+
case 13:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context.stop();
|
|
95
|
+
}
|
|
96
|
+
}, _callee, null, [[3, 10]]);
|
|
97
|
+
})), []);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 一句话录音
|
|
101
|
+
* @param ignoreMsg 是否忽略识别结果
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
var shortAsrClick = useCallback( /*#__PURE__*/function () {
|
|
105
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ignoreMsg) {
|
|
106
|
+
var currentIsPlaying, currentIsRecording, currentIsExecuting;
|
|
107
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
108
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
currentIsPlaying = isPlayingStateRef.current;
|
|
111
|
+
currentIsRecording = isRecordingStateRef.current;
|
|
112
|
+
currentIsExecuting = isExecutingStateRef.current;
|
|
113
|
+
_context2.prev = 3;
|
|
114
|
+
// 清空上一次识别结果
|
|
115
|
+
setAsrText('');
|
|
116
|
+
// 如果正在播放 TTS,先停止
|
|
117
|
+
if (currentIsPlaying) {
|
|
118
|
+
stopTTSByText();
|
|
119
|
+
}
|
|
120
|
+
// 开始一句话识别
|
|
121
|
+
if (currentIsRecording) {
|
|
122
|
+
_context2.next = 13;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
// 重置录音时间
|
|
126
|
+
setRecordingCount(60);
|
|
127
|
+
_context2.next = 10;
|
|
128
|
+
return VoiceRecorderEvent.recordingClick({
|
|
129
|
+
modeType: 'short_asr_only'
|
|
130
|
+
});
|
|
131
|
+
case 10:
|
|
132
|
+
setIsRecording(true);
|
|
133
|
+
_context2.next = 19;
|
|
134
|
+
break;
|
|
135
|
+
case 13:
|
|
136
|
+
setIsRecording(false);
|
|
137
|
+
// 识别中,不允许重复点击
|
|
138
|
+
if (!currentIsExecuting) {
|
|
139
|
+
_context2.next = 16;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
return _context2.abrupt("return");
|
|
143
|
+
case 16:
|
|
144
|
+
// 需要保存识别结果时,展示loading效果
|
|
145
|
+
if (!ignoreMsg) {
|
|
146
|
+
setIsExecuting(true);
|
|
147
|
+
}
|
|
148
|
+
// 结束一句话识别
|
|
149
|
+
_context2.next = 19;
|
|
150
|
+
return VoiceRecorderEvent.toggleTencentRecord({
|
|
151
|
+
engineModel: '16k_zh',
|
|
152
|
+
filterDirty: 1,
|
|
153
|
+
filterModal: 1,
|
|
154
|
+
filterPunc: 1,
|
|
155
|
+
convertNum: 1
|
|
156
|
+
}, function (res) {
|
|
157
|
+
if (ignoreMsg) {
|
|
158
|
+
setAsrText('');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (res !== null && res !== void 0 && res.success) {
|
|
162
|
+
if (!res.result) {
|
|
163
|
+
Toast.info('未识别到语音内容');
|
|
164
|
+
}
|
|
165
|
+
setAsrText(function (pre) {
|
|
166
|
+
return pre + res.result;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}).catch(function (err) {
|
|
170
|
+
Toast.error('转写失败,请重试');
|
|
171
|
+
console.error("\u4E00\u53E5\u8BDD\u5F55\u97F3\u8F6C\u5199\u5931\u8D25: ".concat(err.message));
|
|
172
|
+
}).finally(function () {
|
|
173
|
+
setIsExecuting(false);
|
|
174
|
+
});
|
|
175
|
+
case 19:
|
|
176
|
+
_context2.next = 27;
|
|
177
|
+
break;
|
|
178
|
+
case 21:
|
|
179
|
+
_context2.prev = 21;
|
|
180
|
+
_context2.t0 = _context2["catch"](3);
|
|
181
|
+
setIsRecording(false);
|
|
182
|
+
setIsExecuting(false);
|
|
183
|
+
if (_context2.t0.code === 'MIC_PERMISSION_DENIED') {
|
|
184
|
+
dispatch(setShowMicWarning({
|
|
185
|
+
showMicWarning: true
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
console.error("\u4E00\u53E5\u8BDD\u5F55\u97F3\u64CD\u4F5C\u5931\u8D25: ".concat(_context2.t0.message));
|
|
189
|
+
case 27:
|
|
190
|
+
case "end":
|
|
191
|
+
return _context2.stop();
|
|
192
|
+
}
|
|
193
|
+
}, _callee2, null, [[3, 21]]);
|
|
194
|
+
}));
|
|
195
|
+
return function (_x) {
|
|
196
|
+
return _ref2.apply(this, arguments);
|
|
197
|
+
};
|
|
198
|
+
}(), [stopTTSByText, dispatch]);
|
|
199
|
+
useEffect(function () {
|
|
200
|
+
// 录音时间倒计时
|
|
201
|
+
if (recordingCount === 60 && isRecording) {
|
|
202
|
+
if (intervalRef.current) {
|
|
203
|
+
clearInterval(intervalRef.current);
|
|
204
|
+
}
|
|
205
|
+
intervalRef.current = setInterval(function () {
|
|
206
|
+
setRecordingCount(function (prev) {
|
|
207
|
+
return prev - 1;
|
|
208
|
+
});
|
|
209
|
+
}, 1000);
|
|
210
|
+
}
|
|
211
|
+
// 倒计时结束,自动点击识别
|
|
212
|
+
if (recordingCount === 0 && isRecording) {
|
|
213
|
+
clearInterval(intervalRef.current);
|
|
214
|
+
shortAsrClick();
|
|
215
|
+
}
|
|
216
|
+
}, [recordingCount, isRecording, shortAsrClick]);
|
|
217
|
+
useEffect(function () {
|
|
218
|
+
isPlayingRef.current = isPlaying;
|
|
219
|
+
isRecordingRef.current = isRecording;
|
|
220
|
+
}, [isPlaying, isRecording]);
|
|
221
|
+
var cleanFunction = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
222
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
223
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
224
|
+
case 0:
|
|
225
|
+
if (!(!isPlayingRef.current && !isRecordingRef.current)) {
|
|
226
|
+
_context3.next = 2;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
return _context3.abrupt("return");
|
|
230
|
+
case 2:
|
|
231
|
+
_context3.prev = 2;
|
|
232
|
+
// 结束语音播报
|
|
233
|
+
if (isPlayingRef.current) {
|
|
234
|
+
stopTTSByText();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 结束一句话识别
|
|
238
|
+
if (!isRecordingRef.current) {
|
|
239
|
+
_context3.next = 8;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
setIsRecording(false);
|
|
243
|
+
_context3.next = 8;
|
|
244
|
+
return VoiceRecorderEvent.toggleTencentRecord({
|
|
245
|
+
engineModel: '16k_zh',
|
|
246
|
+
filterDirty: 1,
|
|
247
|
+
filterModal: 1,
|
|
248
|
+
filterPunc: 1,
|
|
249
|
+
convertNum: 1
|
|
250
|
+
});
|
|
251
|
+
case 8:
|
|
252
|
+
_context3.next = 13;
|
|
253
|
+
break;
|
|
254
|
+
case 10:
|
|
255
|
+
_context3.prev = 10;
|
|
256
|
+
_context3.t0 = _context3["catch"](2);
|
|
257
|
+
console.error("TTS \u64AD\u653E\u5173\u95ED\u5931\u8D25: ".concat(_context3.t0.message || _context3.t0), 'error');
|
|
258
|
+
case 13:
|
|
259
|
+
case "end":
|
|
260
|
+
return _context3.stop();
|
|
261
|
+
}
|
|
262
|
+
}, _callee3, null, [[2, 10]]);
|
|
263
|
+
})), [stopTTSByText]);
|
|
264
|
+
useEffect(function () {
|
|
265
|
+
// 如果离开当前页面/会话,立即停止正在使用的语音功能
|
|
266
|
+
if (conversationId) {
|
|
267
|
+
cleanFunction();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 监听 tab 切换事件
|
|
271
|
+
var handleVisibilityChange = function handleVisibilityChange() {
|
|
272
|
+
if (document.visibilityState === 'hidden') {
|
|
273
|
+
cleanFunction();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
277
|
+
return function () {
|
|
278
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
279
|
+
cleanFunction();
|
|
280
|
+
};
|
|
281
|
+
}, [conversationId, cleanFunction]);
|
|
282
|
+
useEffect(function () {
|
|
283
|
+
var handleMessage = function handleMessage(data) {
|
|
284
|
+
if (data.type === 'tts_play_end') {
|
|
285
|
+
setIsPlaying(false);
|
|
286
|
+
}
|
|
287
|
+
if (data.type === 'voice_error') {
|
|
288
|
+
Toast.info(data === null || data === void 0 ? void 0 : data.message);
|
|
289
|
+
setIsPlaying(false);
|
|
290
|
+
}
|
|
291
|
+
if (data.type === 'voice_info') {
|
|
292
|
+
Toast.success(data === null || data === void 0 ? void 0 : data.message);
|
|
293
|
+
setIsPlaying(true);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
VoiceRecorderEvent.setOnMessageCallback(handleMessage);
|
|
297
|
+
return function () {
|
|
298
|
+
VoiceRecorderEvent.setOnMessageCallback(handleMessage);
|
|
299
|
+
stopTTSByText();
|
|
300
|
+
};
|
|
301
|
+
}, [stopTTSByText]);
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 播放 TTS 语音
|
|
305
|
+
* @param text 要播放的文本
|
|
306
|
+
*/
|
|
307
|
+
var playTTSByText = useCallback( /*#__PURE__*/function () {
|
|
308
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(text) {
|
|
309
|
+
var currentIsRecording, _voiceConfigs$, _VoiceRecorderEvent$s, _VoiceRecorderEvent$r2, _VoiceRecorderEvent$d2, msgParams;
|
|
310
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
311
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
312
|
+
case 0:
|
|
313
|
+
currentIsRecording = isRecordingStateRef.current;
|
|
314
|
+
if (navigator.onLine) {
|
|
315
|
+
_context4.next = 4;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
Toast.error('无法连接到网络');
|
|
319
|
+
return _context4.abrupt("return");
|
|
320
|
+
case 4:
|
|
321
|
+
if (!currentIsRecording) {
|
|
322
|
+
_context4.next = 7;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
Toast.info('请先停止录音');
|
|
326
|
+
return _context4.abrupt("return");
|
|
327
|
+
case 7:
|
|
328
|
+
_context4.prev = 7;
|
|
329
|
+
if (!isPlayingRef.current) {
|
|
330
|
+
_context4.next = 12;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
(_VoiceRecorderEvent$r2 = VoiceRecorderEvent.resetTTSPlayer) === null || _VoiceRecorderEvent$r2 === void 0 || _VoiceRecorderEvent$r2.call(VoiceRecorderEvent);
|
|
334
|
+
_context4.next = 12;
|
|
335
|
+
return (_VoiceRecorderEvent$d2 = VoiceRecorderEvent.disconnectHandler) === null || _VoiceRecorderEvent$d2 === void 0 ? void 0 : _VoiceRecorderEvent$d2.call(VoiceRecorderEvent);
|
|
336
|
+
case 12:
|
|
337
|
+
// 2. 再启动这一次的 TTS 播放
|
|
338
|
+
msgParams = undefined;
|
|
339
|
+
if ((_voiceConfigs$ = voiceConfigs[0]) !== null && _voiceConfigs$ !== void 0 && _voiceConfigs$.voiceType) {
|
|
340
|
+
msgParams = {
|
|
341
|
+
tts: {
|
|
342
|
+
voiceType: voiceConfigs[0].voiceType
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
_context4.next = 16;
|
|
347
|
+
return (_VoiceRecorderEvent$s = VoiceRecorderEvent.startTTS) === null || _VoiceRecorderEvent$s === void 0 ? void 0 : _VoiceRecorderEvent$s.call(VoiceRecorderEvent, text, msgParams);
|
|
348
|
+
case 16:
|
|
349
|
+
setIsPlaying(true);
|
|
350
|
+
_context4.next = 24;
|
|
351
|
+
break;
|
|
352
|
+
case 19:
|
|
353
|
+
_context4.prev = 19;
|
|
354
|
+
_context4.t0 = _context4["catch"](7);
|
|
355
|
+
setIsPlaying(false);
|
|
356
|
+
Toast.error('语音播放失败');
|
|
357
|
+
console.error("TTS \u64AD\u653E\u5931\u8D25: ".concat(_context4.t0.message || _context4.t0), 'error');
|
|
358
|
+
case 24:
|
|
359
|
+
case "end":
|
|
360
|
+
return _context4.stop();
|
|
361
|
+
}
|
|
362
|
+
}, _callee4, null, [[7, 19]]);
|
|
363
|
+
}));
|
|
364
|
+
return function (_x2) {
|
|
365
|
+
return _ref4.apply(this, arguments);
|
|
366
|
+
};
|
|
367
|
+
}(), [voiceConfigs]);
|
|
368
|
+
return {
|
|
369
|
+
playTTSByText: playTTSByText,
|
|
370
|
+
stopTTSByText: stopTTSByText,
|
|
371
|
+
isPlaying: isPlaying,
|
|
372
|
+
isRecording: isRecording,
|
|
373
|
+
isExecuting: isExecuting,
|
|
374
|
+
recordingCount: recordingCount,
|
|
375
|
+
asrText: asrText,
|
|
376
|
+
shortAsrClick: shortAsrClick
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
export default useChatVoice;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare const useCommonChatAPI: (containerRef: React.RefObject<HTMLDivElement>, businessType: string, stopTTSByText?: () => void, isPlaying?: boolean, agentId?: number) => {
|
|
3
|
+
headerValue: string;
|
|
4
|
+
getHeaderValue: (conversationId: number) => Promise<void>;
|
|
5
|
+
msgLoading: boolean;
|
|
6
|
+
onSucessExcel: (value: any) => void;
|
|
7
|
+
onFailureExcel: (value: any, id: number) => void;
|
|
8
|
+
onRetryExcel: (value: any, id: number) => void;
|
|
9
|
+
disableSend: boolean;
|
|
10
|
+
inputModelRef: React.MutableRefObject<{
|
|
11
|
+
requestId?: any;
|
|
12
|
+
isRetry?: boolean | undefined;
|
|
13
|
+
} | null>;
|
|
14
|
+
handleInterrupt: () => Promise<void>;
|
|
15
|
+
getContentMessageList: (pageIndex?: number, curPageSize?: number) => Promise<void>;
|
|
16
|
+
hasMore: React.MutableRefObject<boolean>;
|
|
17
|
+
handleSend: (val: string, agent?: any, isSystemAuto?: boolean, conversationId?: number) => Promise<void>;
|
|
18
|
+
scrollBottomForce: (animate?: boolean | undefined) => void;
|
|
19
|
+
showBackBottom: boolean;
|
|
20
|
+
isScrolling: boolean;
|
|
21
|
+
isMoreLoading: boolean;
|
|
22
|
+
startConversationAndChat: (value: string) => Promise<string | undefined>;
|
|
23
|
+
deleteConversation: () => Promise<void>;
|
|
24
|
+
regenerate: () => void;
|
|
25
|
+
startAICorrection: (answerId: number, questionId: number) => Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
export default useCommonChatAPI;
|