@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.
Files changed (206) hide show
  1. package/dist/apis/fetch.d.ts +64 -0
  2. package/dist/apis/fetch.js +512 -0
  3. package/dist/apis/useApi.d.ts +57 -0
  4. package/dist/apis/useApi.js +378 -0
  5. package/dist/assets/image/Subtract.png +0 -0
  6. package/dist/assets/image/ai-logo.png +0 -0
  7. package/dist/assets/image/copyIcon.png +0 -0
  8. package/dist/assets/image/deepthinkActive.png +0 -0
  9. package/dist/assets/image/empty-img-dark.png +0 -0
  10. package/dist/assets/image/empty-img.png +0 -0
  11. package/dist/assets/image/like_active.png +0 -0
  12. package/dist/assets/image/love.png +0 -0
  13. package/dist/assets/image/retry.png +0 -0
  14. package/dist/assets/image/soundOut.png +0 -0
  15. package/dist/assets/image/unlike_active.png +0 -0
  16. package/dist/assets/image/unlove.png +0 -0
  17. package/dist/assets/lottie/ai-bg.json +1704 -0
  18. package/dist/assets/lottie/ai-loading.json +192 -0
  19. package/dist/assets/lottie/ai-output-loading.json +272 -0
  20. package/dist/assets/lottie/ai-output-normal.json +17694 -0
  21. package/dist/assets/lottie/ai-output-strengthen.json +17321 -0
  22. package/dist/assets/lottie/ai-voice-play.json +1 -0
  23. package/dist/assets/lottie/living.json +705 -0
  24. package/dist/assets/lottie/myun-living.json +726 -0
  25. package/dist/assets/lottie/myun-loading.json +530 -0
  26. package/dist/components/ai-chat-dialogue/index.d.ts +16 -0
  27. package/dist/components/ai-chat-dialogue/index.js +1056 -0
  28. package/dist/components/ai-chat-dialogue/index.module.css +230 -0
  29. package/dist/components/ai-chat-dialogue/message-parser.d.ts +36 -0
  30. package/dist/components/ai-chat-dialogue/message-parser.js +52 -0
  31. package/dist/components/ai-chat-dialogue/tlv.d.ts +7 -0
  32. package/dist/components/ai-chat-dialogue/tlv.js +32 -0
  33. package/dist/components/ai-chat-dialogue/volc-voice-call-client.d.ts +47 -0
  34. package/dist/components/ai-chat-dialogue/volc-voice-call-client.js +246 -0
  35. package/dist/components/ai-correction/index.d.ts +5 -0
  36. package/dist/components/ai-correction/index.js +45 -0
  37. package/dist/components/ai-loading/index.d.ts +3 -0
  38. package/dist/components/ai-loading/index.js +14 -0
  39. package/dist/components/ai-loading/index.module.css +11 -0
  40. package/dist/components/answer-item/index.d.ts +27 -0
  41. package/dist/components/answer-item/index.js +194 -0
  42. package/dist/components/answer-item/index.module.css +266 -0
  43. package/dist/components/ask-card/index.d.ts +10 -0
  44. package/dist/components/ask-card/index.js +76 -0
  45. package/dist/components/ask-card/index.module.css +122 -0
  46. package/dist/components/chat-input/index.d.ts +31 -0
  47. package/dist/components/chat-input/index.js +433 -0
  48. package/dist/components/chat-input/index.module.css +42 -0
  49. package/dist/components/chat-voice/VoiceCommunication.d.ts +7 -0
  50. package/dist/components/chat-voice/VoiceCommunication.js +69 -0
  51. package/dist/components/chat-voice/VoiceRecord.d.ts +7 -0
  52. package/dist/components/chat-voice/VoiceRecord.js +34 -0
  53. package/dist/components/conversation-delete/index.d.ts +5 -0
  54. package/dist/components/conversation-delete/index.js +24 -0
  55. package/dist/components/dots-loading/index.d.ts +2 -0
  56. package/dist/components/dots-loading/index.js +11 -0
  57. package/dist/components/dots-loading/index.module.css +41 -0
  58. package/dist/components/empty/index.d.ts +9 -0
  59. package/dist/components/empty/index.js +32 -0
  60. package/dist/components/empty/index.module.css +24 -0
  61. package/dist/components/excel-components/ExcelCard.d.ts +11 -0
  62. package/dist/components/excel-components/ExcelCard.js +35 -0
  63. package/dist/components/excel-components/ExcelExcuting.d.ts +10 -0
  64. package/dist/components/excel-components/ExcelExcuting.js +263 -0
  65. package/dist/components/excel-components/ExcelFailCard.d.ts +9 -0
  66. package/dist/components/excel-components/ExcelFailCard.js +20 -0
  67. package/dist/components/excel-components/ExcelSuccessCard.d.ts +5 -0
  68. package/dist/components/excel-components/ExcelSuccessCard.js +50 -0
  69. package/dist/components/excel-components/index.module.css +212 -0
  70. package/dist/components/excel-components/styles.module.css +178 -0
  71. package/dist/components/file-card/fileCardSidebar.d.ts +8 -0
  72. package/dist/components/file-card/fileCardSidebar.js +56 -0
  73. package/dist/components/file-card/index.d.ts +15 -0
  74. package/dist/components/file-card/index.js +97 -0
  75. package/dist/components/file-card/index.module.css +139 -0
  76. package/dist/components/file-preview/index.d.ts +3 -0
  77. package/dist/components/file-preview/index.js +227 -0
  78. package/dist/components/file-preview/index.module.css +83 -0
  79. package/dist/components/file-upload/index.d.ts +16 -0
  80. package/dist/components/file-upload/index.js +238 -0
  81. package/dist/components/file-upload/uploadV1.d.ts +16 -0
  82. package/dist/components/file-upload/uploadV1.js +267 -0
  83. package/dist/components/gimi-sidebar/index.d.ts +17 -0
  84. package/dist/components/gimi-sidebar/index.js +41 -0
  85. package/dist/components/gimi-sidebar/index.module.css +118 -0
  86. package/dist/components/header/index.d.ts +5 -0
  87. package/dist/components/header/index.js +20 -0
  88. package/dist/components/header/index.module.css +19 -0
  89. package/dist/components/iconfont-com/index.d.ts +11 -0
  90. package/dist/components/iconfont-com/index.js +29 -0
  91. package/dist/components/index.d.ts +1 -0
  92. package/dist/components/index.js +1 -0
  93. package/dist/components/knowledge-trace/KnowledgeIconComponent.d.ts +7 -0
  94. package/dist/components/knowledge-trace/KnowledgeIconComponent.js +101 -0
  95. package/dist/components/knowledge-trace/classList.d.ts +6 -0
  96. package/dist/components/knowledge-trace/classList.js +72 -0
  97. package/dist/components/knowledge-trace/documentList.d.ts +6 -0
  98. package/dist/components/knowledge-trace/documentList.js +75 -0
  99. package/dist/components/knowledge-trace/index.d.ts +18 -0
  100. package/dist/components/knowledge-trace/index.js +155 -0
  101. package/dist/components/knowledge-trace/index.module.css +254 -0
  102. package/dist/components/knowledge-trace/interfaces.d.ts +166 -0
  103. package/dist/components/knowledge-trace/interfaces.js +1 -0
  104. package/dist/components/knowledge-trace/videoList.d.ts +6 -0
  105. package/dist/components/knowledge-trace/videoList.js +91 -0
  106. package/dist/components/lottie-img/index.d.ts +8 -0
  107. package/dist/components/lottie-img/index.js +99 -0
  108. package/dist/components/message-actions/CopyButton.d.ts +7 -0
  109. package/dist/components/message-actions/CopyButton.js +33 -0
  110. package/dist/components/message-actions/LikeButton.d.ts +7 -0
  111. package/dist/components/message-actions/LikeButton.js +34 -0
  112. package/dist/components/message-actions/RegenerateButton.d.ts +5 -0
  113. package/dist/components/message-actions/RegenerateButton.js +27 -0
  114. package/dist/components/message-actions/UnLikeButton.d.ts +7 -0
  115. package/dist/components/message-actions/UnLikeButton.js +34 -0
  116. package/dist/components/message-actions/VoicePlay.d.ts +10 -0
  117. package/dist/components/message-actions/VoicePlay.js +74 -0
  118. package/dist/components/message-list/index.d.ts +19 -0
  119. package/dist/components/message-list/index.js +164 -0
  120. package/dist/components/message-list/index.module.css +261 -0
  121. package/dist/components/no-microphone-root/index.d.ts +6 -0
  122. package/dist/components/no-microphone-root/index.js +36 -0
  123. package/dist/components/no-microphone-root/index.module.css +48 -0
  124. package/dist/components/preset-agent-content/index.d.ts +8 -0
  125. package/dist/components/preset-agent-content/index.js +24 -0
  126. package/dist/components/preset-agent-content/index.module.css +46 -0
  127. package/dist/components/quoted-content/index.d.ts +0 -0
  128. package/dist/components/quoted-content/index.js +171 -0
  129. package/dist/components/quoted-content/index.module.css +80 -0
  130. package/dist/components/reasoning-content/index.d.ts +6 -0
  131. package/dist/components/reasoning-content/index.js +116 -0
  132. package/dist/components/reasoning-content/index.module.css +169 -0
  133. package/dist/components/reference-content/index.d.ts +28 -0
  134. package/dist/components/reference-content/index.js +125 -0
  135. package/dist/components/reference-content/index.module.css +84 -0
  136. package/dist/components/templates/CommonChat.d.ts +5 -0
  137. package/dist/components/templates/CommonChat.js +218 -0
  138. package/dist/components/templates/GimiChatComponent.d.ts +4 -0
  139. package/dist/components/templates/GimiChatComponent.js +23 -0
  140. package/dist/components/templates/demo/demo.d.ts +2 -0
  141. package/dist/components/templates/demo/demo.js +109 -0
  142. package/dist/components/templates/index.module.css +109 -0
  143. package/dist/components/upload-list/index.d.ts +15 -0
  144. package/dist/components/upload-list/index.js +90 -0
  145. package/dist/components/upload-list/index.module.css +119 -0
  146. package/dist/components/voice-bars/index.d.ts +4 -0
  147. package/dist/components/voice-bars/index.js +174 -0
  148. package/dist/components/voice-check-dialog/index.d.ts +8 -0
  149. package/dist/components/voice-check-dialog/index.js +163 -0
  150. package/dist/components/voice-check-dialog/index.module.css +9 -0
  151. package/dist/components/voice-recording/index.d.ts +9 -0
  152. package/dist/components/voice-recording/index.js +54 -0
  153. package/dist/components/voice-recording/index.module.css +41 -0
  154. package/dist/components/work-flow-content/demo.d.ts +3 -0
  155. package/dist/components/work-flow-content/demo.js +11 -0
  156. package/dist/components/work-flow-content/index.d.ts +6 -0
  157. package/dist/components/work-flow-content/index.js +55 -0
  158. package/dist/components/work-flow-content/index.module.css +24 -0
  159. package/dist/constants.d.ts +24 -0
  160. package/dist/constants.js +24 -0
  161. package/dist/hooks/useChatActions.d.ts +12 -0
  162. package/dist/hooks/useChatActions.js +207 -0
  163. package/dist/hooks/useChatHistory.d.ts +8 -0
  164. package/dist/hooks/useChatHistory.js +225 -0
  165. package/dist/hooks/useChatMessage.d.ts +49 -0
  166. package/dist/hooks/useChatMessage.js +87 -0
  167. package/dist/hooks/useChatRecommend.d.ts +8 -0
  168. package/dist/hooks/useChatRecommend.js +126 -0
  169. package/dist/hooks/useChatStream.d.ts +20 -0
  170. package/dist/hooks/useChatStream.js +244 -0
  171. package/dist/hooks/useChatUI.d.ts +32 -0
  172. package/dist/hooks/useChatUI.js +134 -0
  173. package/dist/hooks/useChatVoice.d.ts +11 -0
  174. package/dist/hooks/useChatVoice.js +379 -0
  175. package/dist/hooks/useCommonChatAPI.d.ts +27 -0
  176. package/dist/hooks/useCommonChatAPI.js +1276 -0
  177. package/dist/hooks/useFile.d.ts +13 -0
  178. package/dist/hooks/useFile.js +288 -0
  179. package/dist/hooks/useKnowledgeService.d.ts +17 -0
  180. package/dist/hooks/useKnowledgeService.js +210 -0
  181. package/dist/hooks/useLastEventId.d.ts +8 -0
  182. package/dist/hooks/useLastEventId.js +66 -0
  183. package/dist/hooks/useLongPoll.d.ts +3 -0
  184. package/dist/hooks/useLongPoll.js +111 -0
  185. package/dist/hooks/useScroll.d.ts +4 -0
  186. package/dist/hooks/useScroll.js +172 -0
  187. package/dist/index.d.ts +1 -0
  188. package/dist/index.js +1 -0
  189. package/dist/interfaces/chatMessage.d.ts +139 -0
  190. package/dist/interfaces/fileInterface.d.ts +10 -0
  191. package/dist/interfaces/fileInterface.js +11 -0
  192. package/dist/interfaces/knowledgeTrace.d.ts +177 -0
  193. package/dist/store/hooks.d.ts +4 -0
  194. package/dist/store/hooks.js +3 -0
  195. package/dist/store/index.d.ts +7 -0
  196. package/dist/store/index.js +7 -0
  197. package/dist/store/slices/gimiMenuSlice.d.ts +95 -0
  198. package/dist/store/slices/gimiMenuSlice.js +251 -0
  199. package/dist/utils/chatInputUtil.d.ts +19 -0
  200. package/dist/utils/chatInputUtil.js +45 -0
  201. package/dist/utils/tools.d.ts +50 -0
  202. package/dist/utils/tools.js +474 -0
  203. package/dist/utils/voice-stream.d.ts +119 -0
  204. package/dist/utils/voice-stream.js +1162 -0
  205. package/package.json +5 -6
  206. package/LICENSE +0 -21
@@ -0,0 +1,1276 @@
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ 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; }
12
+ 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); } }
13
+ 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); }); }; }
14
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
+ 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."); }
16
+ 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); }
17
+ 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; }
18
+ 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; } }
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
+ import useApi from "../apis/useApi";
21
+ import React, { useRef } from 'react';
22
+ import { Toast } from "@douyinfe/semi-ui";
23
+ import { useAppDispatch, useAppSelector } from "../store/hooks";
24
+ import { setMessageList, setFileList, setConversationId, setAgentDetail } from "../store/slices/gimiMenuSlice";
25
+ import { fileValidation, processString } from "../utils/tools";
26
+ import { filterPropmptFromUserInput } from "../utils/tools";
27
+ import { useChatMessage } from "./useChatMessage";
28
+ import { useChatStream } from "./useChatStream";
29
+ import { useLastEventId } from "./useLastEventId";
30
+ import useScroll from "./useScroll";
31
+ import { useChatRecommend } from "./useChatRecommend";
32
+ import { set, cloneDeep } from 'lodash';
33
+ import { FileStatus } from "../interfaces/fileInterface";
34
+ import useChatHistory from "./useChatHistory";
35
+ var useCommonChatAPI = function useCommonChatAPI(containerRef, businessType, stopTTSByText, isPlaying, agentId) {
36
+ var _useApi = useApi(),
37
+ getMessageTitle = _useApi.getMessageTitle,
38
+ stopStreamOut = _useApi.stopStreamOut,
39
+ createRoomId = _useApi.createRoomId,
40
+ getAgentDetail = _useApi.getAgentDetail,
41
+ deleteConversationById = _useApi.deleteConversationById,
42
+ getAiCorrection = _useApi.getAiCorrection;
43
+ var dispatch = useAppDispatch();
44
+ var _React$useState = React.useState(''),
45
+ _React$useState2 = _slicedToArray(_React$useState, 2),
46
+ headerValue = _React$useState2[0],
47
+ setHeaderValue = _React$useState2[1];
48
+ var _React$useState3 = React.useState(false),
49
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
50
+ msgLoading = _React$useState4[0],
51
+ setMsgLoading = _React$useState4[1];
52
+ var _React$useState5 = React.useState(false),
53
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
54
+ disableSend = _React$useState6[0],
55
+ setDisableSend = _React$useState6[1]; // 禁止编辑
56
+ var moduleInfoRef = React.useRef({});
57
+ var _React$useState7 = React.useState(0),
58
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
59
+ status = _React$useState8[0],
60
+ setStatus = _React$useState8[1]; // 0 没输入内容 1 正在输入 2 ai正在回复 3 ai即将回复
61
+ var valueRef = React.useRef(''); // 输入框的值
62
+ var vipLevelRef = React.useRef(null);
63
+ var isNewConversationRef = React.useRef(false);
64
+ var step = React.useRef(0); // 接口请求step
65
+ var controllerRef = React.useRef(null); // 发起对话接口controller
66
+ var inputModelRef = React.useRef(null);
67
+ var _useChatMessage = useChatMessage(),
68
+ createUserChat = _useChatMessage.createUserChat,
69
+ createAiChat = _useChatMessage.createAiChat;
70
+ var _useChatStream = useChatStream(),
71
+ fetchChatStreamHook = _useChatStream.fetchChatStream,
72
+ setIgnoreOnMessage = _useChatStream.setIgnoreOnMessage,
73
+ streamEsAbortRef = _useChatStream.esAbortRef;
74
+ var _useLastEventId = useLastEventId(),
75
+ removeLastEventId = _useLastEventId.removeLastEventId;
76
+ var _useScroll = useScroll(containerRef),
77
+ _useScroll2 = _slicedToArray(_useScroll, 6),
78
+ throttledScrollToBottom = _useScroll2[0],
79
+ scrollBottomForce = _useScroll2[1],
80
+ currentPosition = _useScroll2[2],
81
+ isScrolling = _useScroll2[5];
82
+ var _useChatRecommend = useChatRecommend(),
83
+ getRecommendList = _useChatRecommend.getRecommendList,
84
+ rewriteRecommendListFormHistory = _useChatRecommend.rewriteRecommendListFormHistory;
85
+ var messageList = useAppSelector(function (state) {
86
+ return state.gimiMenu.messageList;
87
+ });
88
+ var agentObj = useAppSelector(function (state) {
89
+ return state.gimiMenu.agentObj;
90
+ });
91
+ var isMsgRecieving = useAppSelector(function (state) {
92
+ return state.gimiMenu.isMsgRecieving;
93
+ });
94
+ var fileList = useAppSelector(function (state) {
95
+ return state.gimiMenu.fileList;
96
+ });
97
+ var conversationId = useAppSelector(function (state) {
98
+ return state.gimiMenu.conversationId;
99
+ });
100
+ var bussinessParams = useAppSelector(function (state) {
101
+ return state.gimiMenu.bussinessParams;
102
+ });
103
+ var quoteProductList = useAppSelector(function (state) {
104
+ return state.gimiMenu.quoteProductList;
105
+ });
106
+ var quoteTeachModelList = useAppSelector(function (state) {
107
+ return state.gimiMenu.quoteTeachModelList;
108
+ });
109
+ var historyList = useAppSelector(function (state) {
110
+ return state.gimiMenu.historyList;
111
+ });
112
+ var baseUrl = useAppSelector(function (state) {
113
+ return state.gimiMenu.baseUrl;
114
+ });
115
+ var token = useAppSelector(function (state) {
116
+ return state.gimiMenu.token;
117
+ });
118
+
119
+ // 使用 ref 存储最新的值,避免闭包陷阱
120
+ var messageListRef = useRef(messageList || []);
121
+ var statusRef = useRef(status);
122
+ var agentObjRef = useRef(agentObj || null);
123
+ var isMsgRecievingRef = useRef(isMsgRecieving);
124
+ var fileListRef = useRef(fileList || []);
125
+ var conversationIdRef = useRef(conversationId || -1);
126
+ var bussinessParamsRef = useRef(bussinessParams || {});
127
+ var quoteProductListRef = useRef(quoteProductList || []);
128
+ var quoteTeachModelListRef = useRef(quoteTeachModelList || []);
129
+ var historyListRef = useRef(historyList || []);
130
+ var baseUrlRef = useRef(baseUrl || '');
131
+ var tokenRef = useRef(token || '');
132
+
133
+ // 更细Ref的值
134
+ messageListRef.current = messageList;
135
+ statusRef.current = status;
136
+ agentObjRef.current = agentObj;
137
+ isMsgRecievingRef.current = isMsgRecieving;
138
+ fileListRef.current = fileList;
139
+ conversationIdRef.current = conversationId;
140
+ bussinessParamsRef.current = bussinessParams;
141
+ quoteProductListRef.current = quoteProductList;
142
+ quoteTeachModelListRef.current = quoteTeachModelList;
143
+ historyListRef.current = historyList;
144
+ baseUrlRef.current = baseUrl;
145
+ tokenRef.current = token;
146
+
147
+ // 错误处理ref(将在startChat和streamChat定义后初始化useChatError)
148
+ var errRef = React.useRef({
149
+ timer: null,
150
+ count: 0
151
+ });
152
+
153
+ // 重置与当前回话关联的Redux状态
154
+ // const clearQuotesFromRedux = () => {
155
+ // dispatch(updateState({
156
+ // fileList: [],
157
+ // showKonwledgeTrace: false,
158
+ // showSidebarFileList: false,
159
+ // filePreviewState: {
160
+ // show: false,
161
+ // url: '',
162
+ // filename: '',
163
+ // },
164
+ // // quoteProductList: [],
165
+ // // quoteTeachModelList: [],
166
+ // konwledgeTraceState: {
167
+ // type: 'video',
168
+ // resources: [],
169
+ // messageId: null,
170
+ // },
171
+ // }))
172
+ // };
173
+
174
+ var startAICorrection = React.useCallback( /*#__PURE__*/function () {
175
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(answerId, questionId) {
176
+ var res, _res$result, _res$result2, message, aiChat;
177
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
178
+ while (1) switch (_context.prev = _context.next) {
179
+ case 0:
180
+ _context.next = 2;
181
+ return getAiCorrection({
182
+ answerId: answerId,
183
+ questionId: questionId
184
+ });
185
+ case 2:
186
+ res = _context.sent;
187
+ if (res.status === 0) {
188
+ message = createUserChat((_res$result = res.result) === null || _res$result === void 0 ? void 0 : _res$result.title, '');
189
+ aiChat = createAiChat({});
190
+ dispatch(setMessageList({
191
+ messageList: [message, aiChat]
192
+ }));
193
+ dispatch(setAgentDetail({
194
+ agentDetail: {
195
+ botId: (_res$result2 = res.result) === null || _res$result2 === void 0 ? void 0 : _res$result2.botId
196
+ }
197
+ }));
198
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
199
+ streamAICorrectionChat();
200
+ } else {
201
+ Toast.error(res.message || '获取AI批改信息失败');
202
+ }
203
+ case 4:
204
+ case "end":
205
+ return _context.stop();
206
+ }
207
+ }, _callee);
208
+ }));
209
+ return function (_x, _x2) {
210
+ return _ref.apply(this, arguments);
211
+ };
212
+ }(), [getAiCorrection]);
213
+ var regenerate = React.useCallback(function () {
214
+ var _reverse$find;
215
+ var value = (_reverse$find = _toConsumableArray(messageListRef.current).reverse().find(function (item) {
216
+ return item.role === 0;
217
+ })) === null || _reverse$find === void 0 ? void 0 : _reverse$find.content;
218
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
219
+ handleSend(value || '');
220
+ }, []);
221
+ var deleteConversation = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
222
+ var res;
223
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
224
+ while (1) switch (_context2.prev = _context2.next) {
225
+ case 0:
226
+ if (conversationIdRef.current) {
227
+ _context2.next = 3;
228
+ break;
229
+ }
230
+ Toast.error('会话ID不存在');
231
+ return _context2.abrupt("return");
232
+ case 3:
233
+ _context2.next = 5;
234
+ return deleteConversationById(conversationIdRef.current);
235
+ case 5:
236
+ res = _context2.sent;
237
+ if (res.status === 0) {
238
+ Toast.success('删除会话成功');
239
+ // 清空Redux状态
240
+ dispatch(setMessageList({
241
+ messageList: []
242
+ }));
243
+ setHeaderValue('');
244
+ } else {
245
+ Toast.error(res.message || '删除会话失败');
246
+ }
247
+ case 7:
248
+ case "end":
249
+ return _context2.stop();
250
+ }
251
+ }, _callee2);
252
+ })), [dispatch]);
253
+
254
+ // 打断ai输出
255
+ var handleInterrupt = /*#__PURE__*/function () {
256
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
257
+ var uid, messageList, _item, newMessageList, _newMessageList;
258
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
259
+ while (1) switch (_context3.prev = _context3.next) {
260
+ case 0:
261
+ uid = 'msg_' + Date.now();
262
+ if (navigator.onLine) {
263
+ _context3.next = 4;
264
+ break;
265
+ }
266
+ Toast.error('无法连接到网络');
267
+ return _context3.abrupt("return");
268
+ case 4:
269
+ if (streamEsAbortRef.current) {
270
+ _context3.next = 7;
271
+ break;
272
+ }
273
+ Toast.error('没有可取消的请求');
274
+ return _context3.abrupt("return");
275
+ case 7:
276
+ streamEsAbortRef.current.abort();
277
+ streamEsAbortRef.current = null;
278
+ messageList = messageListRef.current;
279
+ if (step.current === 1) {
280
+ _item = {
281
+ role: 1,
282
+ type: 1,
283
+ content: '',
284
+ id: uid,
285
+ messageId: uid,
286
+ videoResourceList: [],
287
+ relatedCourseRecommendation: [],
288
+ loading: false,
289
+ reasoningLoading: false,
290
+ msgLoading: false,
291
+ reasoningStatus: 3,
292
+ expand: false,
293
+ // 是否展开
294
+ reasoningContent: '',
295
+ // 推理内容
296
+ stop: 1
297
+ };
298
+ if (messageList[messageList.length - 1].vipLevel === 1) {
299
+ newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), _item), {}, {
300
+ reasoningStatus: messageList[messageList.length - 1].content ? 2 : 3
301
+ })]);
302
+ dispatch(setMessageList({
303
+ messageList: newMessageList
304
+ }));
305
+ }
306
+ } else {
307
+ _newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
308
+ loading: false,
309
+ reasoningLoading: false,
310
+ stop: 1,
311
+ reasoningStatus: messageList[messageList.length - 1].content ? 2 : 3,
312
+ msgLoading: false,
313
+ relatedResourceList: [],
314
+ mcp: null
315
+ })]);
316
+ dispatch(setMessageList({
317
+ messageList: _newMessageList
318
+ }));
319
+ }
320
+ stopStreamOut({
321
+ messageId: "".concat(messageList[messageList.length - 1].chatId)
322
+ });
323
+ removeLastEventId("".concat(messageList[messageList.length - 1].chatId));
324
+ if (valueRef.current) {
325
+ setStatus(1);
326
+ } else {
327
+ setStatus(0);
328
+ }
329
+ setMsgLoading(false);
330
+ step.current = 0; // 重置步骤状态
331
+ case 16:
332
+ case "end":
333
+ return _context3.stop();
334
+ }
335
+ }, _callee3);
336
+ }));
337
+ return function handleInterrupt() {
338
+ return _ref3.apply(this, arguments);
339
+ };
340
+ }();
341
+ var handleMCPToolsStreamRs = React.useCallback(function (dataObj) {
342
+ setStatus(2);
343
+ var messageList = messageListRef.current;
344
+ var shouldIgnore = dataObj.status !== 'executeWorkflowByDescription' && dataObj.status !== 'notifyWorkflowStart';
345
+ var lastMessage = messageList[messageList.length - 1];
346
+ var newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, lastMessage), {}, {
347
+ moduleType: dataObj.moduleType,
348
+ mcp: shouldIgnore ? null : {
349
+ name: dataObj.name || '',
350
+ status: dataObj.status
351
+ }
352
+ })]);
353
+ dispatch(setMessageList({
354
+ messageList: newMessageList
355
+ }));
356
+ }, [dispatch]);
357
+
358
+ // 发起会话 - 使用新的hook简化逻辑
359
+ var fetchAICorrectionChatStream = React.useCallback( /*#__PURE__*/function () {
360
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
361
+ var fullResponse, reasoningResponse;
362
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
363
+ while (1) switch (_context4.prev = _context4.next) {
364
+ case 0:
365
+ setIgnoreOnMessage(false);
366
+ fullResponse = '';
367
+ reasoningResponse = '';
368
+ _context4.next = 5;
369
+ return fetchChatStreamHook('', {}, {
370
+ onSseOpen: function onSseOpen(response) {
371
+ _onSseOpen(response);
372
+ },
373
+ onDataReceived: function onDataReceived(response, type) {
374
+ setMsgLoading(false);
375
+ if (type === 'content') {
376
+ fullResponse = response;
377
+ moduleInfoRef.current = null;
378
+ } else if (type === 'reasoningContent') {
379
+ reasoningResponse = response;
380
+ vipLevelRef.current = 1;
381
+ }
382
+ _onDataReceived(response, type);
383
+ },
384
+ onComplete: function onComplete(response, type) {
385
+ if (type === 'end' || type === 'COMPLETED') {
386
+ if (businessType === 'correction') {
387
+ fullResponse = "<correction>".concat(fullResponse, "</correction>");
388
+ }
389
+ _onComplete(fullResponse, type, reasoningResponse);
390
+ } else {
391
+ moduleInfoRef.current = response;
392
+ _onComplete(response, type);
393
+ }
394
+ },
395
+ onErrorComplete: function onErrorComplete() {
396
+ _onErrorComplete();
397
+ },
398
+ onMCPToolsStream: function onMCPToolsStream(dataObj) {
399
+ handleMCPToolsStreamRs(dataObj);
400
+ }
401
+ }, 'POST', '/mbot/web/bot/chat/workflow');
402
+ case 5:
403
+ case "end":
404
+ return _context4.stop();
405
+ }
406
+ }, _callee4);
407
+ }));
408
+ return function (_x3, _x4, _x5, _x6) {
409
+ return _ref4.apply(this, arguments);
410
+ };
411
+ }(), [fetchChatStreamHook, setIgnoreOnMessage, dispatch, removeLastEventId, handleMCPToolsStreamRs]);
412
+
413
+ // 发起会话 - 使用新的hook简化逻辑
414
+ var fetchChatStream = React.useCallback( /*#__PURE__*/function () {
415
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id, reSumeInfo, _onSseOpen2, _onDataReceived2, _onComplete2, _onErrorComplete2) {
416
+ var fullResponse, reasoningResponse;
417
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
418
+ while (1) switch (_context5.prev = _context5.next) {
419
+ case 0:
420
+ setIgnoreOnMessage(false);
421
+ fullResponse = Object.keys(reSumeInfo).length > 0 ? reSumeInfo.content : '';
422
+ reasoningResponse = Object.keys(reSumeInfo).length > 0 ? reSumeInfo.reasoningContent : '';
423
+ _context5.next = 5;
424
+ return fetchChatStreamHook(id, reSumeInfo, {
425
+ onSseOpen: function onSseOpen(response) {
426
+ _onSseOpen2(response);
427
+ // if (historyListRef.current.findIndex((item: any) => item.id === conversationIdRef.current) !== 0) {
428
+ // dispatch(getChatHistoryList({ pageIndex: 1, pageSize: 50, loadMore: false }));
429
+ // }
430
+ },
431
+ onDataReceived: function onDataReceived(response, type) {
432
+ setMsgLoading(false);
433
+ if (type === 'content') {
434
+ fullResponse = response;
435
+ moduleInfoRef.current = null;
436
+ } else if (type === 'reasoningContent') {
437
+ reasoningResponse = response;
438
+ vipLevelRef.current = 1;
439
+ }
440
+ _onDataReceived2(response, type);
441
+ },
442
+ onComplete: function onComplete(response, type) {
443
+ if (type === 'end' || type === 'COMPLETED') {
444
+ removeLastEventId(id);
445
+ _onComplete2(fullResponse, type, reasoningResponse);
446
+ } else {
447
+ moduleInfoRef.current = response;
448
+ _onComplete2(response, type);
449
+ }
450
+ },
451
+ onErrorComplete: function onErrorComplete() {
452
+ _onErrorComplete2();
453
+ },
454
+ onMCPToolsStream: function onMCPToolsStream(dataObj) {
455
+ handleMCPToolsStreamRs(dataObj);
456
+ }
457
+ });
458
+ case 5:
459
+ case "end":
460
+ return _context5.stop();
461
+ }
462
+ }, _callee5);
463
+ }));
464
+ return function (_x7, _x8, _x9, _x10, _x11, _x12) {
465
+ return _ref5.apply(this, arguments);
466
+ };
467
+ }(), [fetchChatStreamHook, setIgnoreOnMessage, dispatch, removeLastEventId, handleMCPToolsStreamRs]);
468
+
469
+ // AI批改流式输出开始
470
+ var streamAICorrectionChat = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
471
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
472
+ while (1) switch (_context7.prev = _context7.next) {
473
+ case 0:
474
+ step.current = 2;
475
+ _context7.next = 3;
476
+ return fetchAICorrectionChatStream(function () {
477
+ setStatus(1);
478
+ var currentMessageList = messageListRef.current;
479
+ var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
480
+ loading: false,
481
+ reasoningLoading: false,
482
+ stop: 0
483
+ })]);
484
+ dispatch(setMessageList({
485
+ messageList: newMessageList
486
+ }));
487
+ }, function (response, type) {
488
+ // if (isSystemAuto) return;
489
+ setStatus(2);
490
+ var currentMessageList = messageListRef.current;
491
+ var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, type, response || ''), "loading", true), "msgLoading", false), "vipLevel", vipLevelRef.current), "reasoningLoading", type === 'content' ? false : true), "reasoningStatus", type === 'content' ? 2 : 1), "moduleInfo", null), "moduleType", 'end'), "mcp", null))]);
492
+ dispatch(setMessageList({
493
+ messageList: newMessageList
494
+ }));
495
+ }, /*#__PURE__*/function () {
496
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(Response, type, reasoningResponse) {
497
+ var currentMessageList, newMessageList;
498
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
499
+ while (1) switch (_context6.prev = _context6.next) {
500
+ case 0:
501
+ // if (isSystemAuto) return;
502
+ setIgnoreOnMessage(true);
503
+ currentMessageList = messageListRef.current;
504
+ newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
505
+ moduleType: type
506
+ }, type === 'end' ? 'content' : 'moduleInfo', Response), "reasoningResponse", type === 'end' ? reasoningResponse : ''), "loading", false), "reasoningLoading", false), "mcp", null))]);
507
+ dispatch(setMessageList({
508
+ messageList: newMessageList
509
+ }));
510
+ if (type === 'ask' || type === 'skill') {
511
+ scrollBottomForce();
512
+ }
513
+ setStatus(1);
514
+ setMsgLoading(false);
515
+ case 7:
516
+ case "end":
517
+ return _context6.stop();
518
+ }
519
+ }, _callee6);
520
+ }));
521
+ return function (_x13, _x14, _x15) {
522
+ return _ref7.apply(this, arguments);
523
+ };
524
+ }(), function () {
525
+ setIgnoreOnMessage(true);
526
+ var currentMessageList = messageListRef.current;
527
+ var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
528
+ loading: false,
529
+ reasoningLoading: false,
530
+ stop: 0,
531
+ reasoningStatus: 3,
532
+ msgLoading: false,
533
+ mcp: null
534
+ })]);
535
+ dispatch(setMessageList({
536
+ messageList: newMessageList
537
+ }));
538
+ if (valueRef.current) {
539
+ setStatus(1);
540
+ } else {
541
+ setStatus(0);
542
+ }
543
+ setMsgLoading(false);
544
+ });
545
+ case 3:
546
+ case "end":
547
+ return _context7.stop();
548
+ }
549
+ }, _callee7);
550
+ })), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList]);
551
+
552
+ // 流式输出开始
553
+ var streamChat = React.useCallback( /*#__PURE__*/function () {
554
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(lastId, again) {
555
+ var reSumeInfo,
556
+ agentInfo,
557
+ _args9 = arguments;
558
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
559
+ while (1) switch (_context9.prev = _context9.next) {
560
+ case 0:
561
+ reSumeInfo = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
562
+ agentInfo = _args9.length > 3 ? _args9[3] : undefined;
563
+ step.current = 2;
564
+ _context9.next = 5;
565
+ return fetchChatStream(lastId, reSumeInfo, function () {
566
+ if (!again) {
567
+ errRef.current = {
568
+ count: 0,
569
+ timer: null
570
+ };
571
+ } else {
572
+ if (valueRef.current) {
573
+ setStatus(1);
574
+ } else {
575
+ setStatus(0);
576
+ }
577
+ var currentMessageList = messageListRef.current;
578
+ var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
579
+ loading: false,
580
+ reasoningLoading: false,
581
+ stop: 0
582
+ })]);
583
+ dispatch(setMessageList({
584
+ messageList: newMessageList
585
+ }));
586
+ }
587
+ }, function (response, type) {
588
+ // if (isSystemAuto) return;
589
+ setStatus(2);
590
+ var currentMessageList = messageListRef.current;
591
+ var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, type, response || ''), "loading", again ? false : true), "msgLoading", false), "vipLevel", vipLevelRef.current), "reasoningLoading", type === 'content' ? false : again ? false : true), "reasoningStatus", type === 'content' ? 2 : 1), "moduleInfo", null), "moduleType", 'end'), "mcp", null))]);
592
+ dispatch(setMessageList({
593
+ messageList: newMessageList
594
+ }));
595
+ }, /*#__PURE__*/function () {
596
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(Response, type, reasoningResponse) {
597
+ var currentMessageList, newMessageList, agentDetail;
598
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
599
+ while (1) switch (_context8.prev = _context8.next) {
600
+ case 0:
601
+ // if (isSystemAuto) return;
602
+ setIgnoreOnMessage(true);
603
+ currentMessageList = messageListRef.current;
604
+ newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
605
+ moduleType: type
606
+ }, type === 'end' ? 'content' : 'moduleInfo', Response), "reasoningResponse", type === 'end' ? reasoningResponse : ''), "loading", false), "reasoningLoading", false), "mcp", null))]);
607
+ dispatch(setMessageList({
608
+ messageList: newMessageList
609
+ }));
610
+ if (type === 'ask' || type === 'skill') {
611
+ scrollBottomForce();
612
+ }
613
+ setMsgLoading(true);
614
+
615
+ // 获取最新的agent详情,防止redux异步更新
616
+ agentDetail = agentInfo || agentObjRef.current;
617
+ if (!((agentDetail === null || agentDetail === void 0 ? void 0 : agentDetail.isEnableRelated) === 1 && (type === 'end' || type === 'COMPLETED'))) {
618
+ _context8.next = 10;
619
+ break;
620
+ }
621
+ _context8.next = 10;
622
+ return getRecommendList(newMessageList, lastId, statusRef.current);
623
+ case 10:
624
+ if (valueRef.current) {
625
+ setStatus(1);
626
+ } else {
627
+ setStatus(0);
628
+ }
629
+ setMsgLoading(false);
630
+ case 12:
631
+ case "end":
632
+ return _context8.stop();
633
+ }
634
+ }, _callee8);
635
+ }));
636
+ return function (_x18, _x19, _x20) {
637
+ return _ref9.apply(this, arguments);
638
+ };
639
+ }(), function () {
640
+ setIgnoreOnMessage(true);
641
+ var currentMessageList = messageListRef.current;
642
+ var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
643
+ loading: false,
644
+ reasoningLoading: false,
645
+ stop: 0,
646
+ reasoningStatus: 3,
647
+ msgLoading: false,
648
+ mcp: null
649
+ })]);
650
+ dispatch(setMessageList({
651
+ messageList: newMessageList
652
+ }));
653
+ if (valueRef.current) {
654
+ setStatus(1);
655
+ } else {
656
+ setStatus(0);
657
+ }
658
+ setMsgLoading(false);
659
+ });
660
+ case 5:
661
+ case "end":
662
+ return _context9.stop();
663
+ }
664
+ }, _callee9);
665
+ }));
666
+ return function (_x16, _x17) {
667
+ return _ref8.apply(this, arguments);
668
+ };
669
+ }(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList]);
670
+
671
+ // 单独的断点续传
672
+ var checkUnfinishedMessage = React.useCallback( /*#__PURE__*/function () {
673
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(chatList) {
674
+ var lastMessage, newMessageList, _agentObjRef$current, lastUserRequestMessage;
675
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
676
+ while (1) switch (_context10.prev = _context10.next) {
677
+ case 0:
678
+ lastMessage = chatList[chatList.length - 1]; // 检查最后一条消息是否为未完成的AI消息
679
+ if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 0 && lastMessage.chatId) {
680
+ newMessageList = [].concat(_toConsumableArray(chatList.slice(0, -1)), [_objectSpread(_objectSpread({}, lastMessage), {}, {
681
+ expand: true,
682
+ stop: 0
683
+ })]);
684
+ dispatch(setMessageList({
685
+ messageList: newMessageList
686
+ }));
687
+ setMsgLoading(lastMessage.content || lastMessage.reasoningContent ? false : true);
688
+ streamChat(lastMessage.chatId, false, {
689
+ content: processString(lastMessage.content || ''),
690
+ reasoningContent: processString(lastMessage.reasoningContent || '')
691
+ }, agentObjRef.current); // 调用续传接口
692
+ }
693
+ if (!((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 1)) {
694
+ _context10.next = 8;
695
+ break;
696
+ }
697
+ removeLastEventId("".concat(lastMessage.chatId));
698
+ // 判断是否需要重写推荐列表
699
+ lastUserRequestMessage = chatList.filter(function (item) {
700
+ return item.role === 0;
701
+ }).slice(-1)[0];
702
+ if (!(((_agentObjRef$current = agentObjRef.current) === null || _agentObjRef$current === void 0 ? void 0 : _agentObjRef$current.isEnableRelated) === 1 && !(lastUserRequestMessage !== null && lastUserRequestMessage !== void 0 && lastUserRequestMessage.relatedResourceList) && ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'end' || (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'COMPLETED') && lastMessage.stop === 0)) {
703
+ _context10.next = 8;
704
+ break;
705
+ }
706
+ _context10.next = 8;
707
+ return rewriteRecommendListFormHistory(chatList, "".concat(lastUserRequestMessage.chatId));
708
+ case 8:
709
+ case "end":
710
+ return _context10.stop();
711
+ }
712
+ }, _callee10);
713
+ }));
714
+ return function (_x21) {
715
+ return _ref10.apply(this, arguments);
716
+ };
717
+ }(), [dispatch, streamChat, removeLastEventId, rewriteRecommendListFormHistory]);
718
+ var _useChatHistory = useChatHistory(checkUnfinishedMessage, scrollBottomForce, containerRef),
719
+ getContentMessageList = _useChatHistory.getContentMessageList,
720
+ isMoreLoading = _useChatHistory.isMoreLoading,
721
+ hasMore = _useChatHistory.hasMore;
722
+ React.useEffect(function () {
723
+ if (!isMoreLoading && messageList.length > 0) {
724
+ if (messageList[messageList.length - 1].type === 1) {
725
+ throttledScrollToBottom();
726
+ } else {
727
+ scrollBottomForce();
728
+ }
729
+ }
730
+ }, [messageList, isMoreLoading, throttledScrollToBottom, scrollBottomForce]);
731
+
732
+ // 获取对话标题
733
+ var getHeaderValue = /*#__PURE__*/function () {
734
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(conversationId) {
735
+ var res, _res$result3;
736
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
737
+ while (1) switch (_context11.prev = _context11.next) {
738
+ case 0:
739
+ if (conversationId) {
740
+ _context11.next = 2;
741
+ break;
742
+ }
743
+ return _context11.abrupt("return");
744
+ case 2:
745
+ _context11.prev = 2;
746
+ _context11.next = 5;
747
+ return getMessageTitle("".concat(conversationId));
748
+ case 5:
749
+ res = _context11.sent;
750
+ if ((res === null || res === void 0 ? void 0 : res.status) === 0) {
751
+ setHeaderValue(res === null || res === void 0 || (_res$result3 = res.result) === null || _res$result3 === void 0 ? void 0 : _res$result3.title);
752
+ }
753
+ _context11.next = 12;
754
+ break;
755
+ case 9:
756
+ _context11.prev = 9;
757
+ _context11.t0 = _context11["catch"](2);
758
+ Toast.error('网络异常');
759
+ case 12:
760
+ case "end":
761
+ return _context11.stop();
762
+ }
763
+ }, _callee11, null, [[2, 9]]);
764
+ }));
765
+ return function getHeaderValue(_x22) {
766
+ return _ref11.apply(this, arguments);
767
+ };
768
+ }();
769
+ React.useEffect(function () {
770
+ if (conversationId && !isNewConversationRef.current) {
771
+ getContentMessageList();
772
+ getHeaderValue(conversationId);
773
+ }
774
+ }, [conversationId]);
775
+
776
+ // 开始会话
777
+ var startChat = React.useCallback( /*#__PURE__*/function () {
778
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(messageList) {
779
+ var _reverse$find2, _bussinessParamsRef$c;
780
+ var isSystemAuto,
781
+ conversationId,
782
+ isAskFileSend,
783
+ val,
784
+ signal,
785
+ currentBussinessParams,
786
+ _agentObjRef$current2,
787
+ _quoteProductListRef$,
788
+ _quoteTeachModelListR,
789
+ params,
790
+ _fileList,
791
+ _response,
792
+ responseMsg,
793
+ result,
794
+ aiChat,
795
+ _args12 = arguments;
796
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
797
+ while (1) switch (_context12.prev = _context12.next) {
798
+ case 0:
799
+ isSystemAuto = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
800
+ conversationId = _args12.length > 2 ? _args12[2] : undefined;
801
+ isAskFileSend = _args12.length > 3 ? _args12[3] : undefined;
802
+ // 如果是ask卡片的file上传,发送content为''
803
+ val = isAskFileSend ? '' : (_reverse$find2 = _toConsumableArray(messageList).reverse().find(function (item) {
804
+ return item.role === 0;
805
+ })) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.content;
806
+ if (controllerRef.current) {
807
+ controllerRef.current.abort();
808
+ }
809
+ if (streamEsAbortRef.current) {
810
+ streamEsAbortRef.current.abort();
811
+ }
812
+ controllerRef.current = new AbortController();
813
+ signal = controllerRef.current.signal;
814
+ step.current = 1;
815
+ currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c = bussinessParamsRef.current) === null || _bussinessParamsRef$c === void 0 ? void 0 : _bussinessParamsRef$c.bussinessParams) || {});
816
+ _context12.prev = 10;
817
+ params = _objectSpread({
818
+ content: val,
819
+ conversationId: conversationId || conversationIdRef.current,
820
+ conversationType: (_agentObjRef$current2 = agentObjRef.current) === null || _agentObjRef$current2 === void 0 ? void 0 : _agentObjRef$current2.conversationType
821
+ }, currentBussinessParams);
822
+ _fileList = fileListRef.current;
823
+ if ((_fileList === null || _fileList === void 0 ? void 0 : _fileList.length) > 0) {
824
+ params.fileName = _fileList[0].fileName;
825
+ params.fileAddr = _fileList[0].fileUrl;
826
+ params.fileSize = _fileList[0].fileSize;
827
+ params.fileParsingResult = _fileList[0].content;
828
+ }
829
+ if (((_quoteProductListRef$ = quoteProductListRef.current) === null || _quoteProductListRef$ === void 0 ? void 0 : _quoteProductListRef$.length) > 0) {
830
+ params.quoteProductId = quoteProductListRef.current.map(function (item) {
831
+ return item.productId;
832
+ });
833
+ }
834
+ if (((_quoteTeachModelListR = quoteTeachModelListRef.current) === null || _quoteTeachModelListR === void 0 ? void 0 : _quoteTeachModelListR.length) > 0) {
835
+ params.quoteTeachModelId = quoteTeachModelListRef.current.map(function (item) {
836
+ return item.teachModelId;
837
+ });
838
+ }
839
+ if (inputModelRef.current) {
840
+ params.inputModel = inputModelRef.current;
841
+ }
842
+ if (isSystemAuto) {
843
+ params.isSystemAuto = 1;
844
+ }
845
+ _context12.next = 20;
846
+ return fetch("https://".concat(baseUrlRef.current, "/mbot/web/agent-message"), {
847
+ method: 'POST',
848
+ headers: {
849
+ 'Content-Type': 'application/json',
850
+ Authorization: "Bearer ".concat(tokenRef.current)
851
+ },
852
+ signal: signal,
853
+ body: JSON.stringify(params)
854
+ });
855
+ case 20:
856
+ _response = _context12.sent;
857
+ if (!_response.ok) {
858
+ _context12.next = 27;
859
+ break;
860
+ }
861
+ _context12.next = 24;
862
+ return _response.json();
863
+ case 24:
864
+ responseMsg = _context12.sent;
865
+ // 清空发送时的引用
866
+ dispatch(setFileList({
867
+ fileList: []
868
+ }));
869
+ if (responseMsg.status === 0) {
870
+ result = responseMsg.result;
871
+ aiChat = createAiChat(result); // 根据isSystemAuto决定是否添加AI消息到列表
872
+ // if (!isSystemAuto) {
873
+ dispatch(setMessageList({
874
+ messageList: [].concat(_toConsumableArray(messageList), [aiChat])
875
+ }));
876
+ // }
877
+ // 继续流式处理聊天
878
+ streamChat(result.id, false, isSystemAuto);
879
+ } else {
880
+ Toast.error(responseMsg.message);
881
+ setMsgLoading(false);
882
+ if (valueRef.current) {
883
+ setStatus(1);
884
+ } else {
885
+ setStatus(0);
886
+ }
887
+ }
888
+ case 27:
889
+ _context12.next = 32;
890
+ break;
891
+ case 29:
892
+ _context12.prev = 29;
893
+ _context12.t0 = _context12["catch"](10);
894
+ if (_context12.t0.name === 'AbortError') {
895
+ setMsgLoading(false);
896
+ if (valueRef.current) {
897
+ setStatus(1);
898
+ } else {
899
+ setStatus(0);
900
+ }
901
+ } else {
902
+ Toast.error('网络异常');
903
+ setMsgLoading(false);
904
+ if (valueRef.current) {
905
+ setStatus(1);
906
+ } else {
907
+ setStatus(0);
908
+ }
909
+ }
910
+ case 32:
911
+ case "end":
912
+ return _context12.stop();
913
+ }
914
+ }, _callee12, null, [[10, 29]]);
915
+ }));
916
+ return function (_x23) {
917
+ return _ref12.apply(this, arguments);
918
+ };
919
+ }(), [dispatch]);
920
+ var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
921
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(agentId) {
922
+ var res;
923
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
924
+ while (1) switch (_context13.prev = _context13.next) {
925
+ case 0:
926
+ _context13.prev = 0;
927
+ _context13.next = 3;
928
+ return getAgentDetail(agentId);
929
+ case 3:
930
+ res = _context13.sent;
931
+ if (!(res.status === 0)) {
932
+ _context13.next = 9;
933
+ break;
934
+ }
935
+ dispatch(setAgentDetail({
936
+ agentDetail: res.result
937
+ }));
938
+ return _context13.abrupt("return", res.result);
939
+ case 9:
940
+ Toast.error(res.message);
941
+ return _context13.abrupt("return", null);
942
+ case 11:
943
+ _context13.next = 17;
944
+ break;
945
+ case 13:
946
+ _context13.prev = 13;
947
+ _context13.t0 = _context13["catch"](0);
948
+ console.log('error', _context13.t0);
949
+ return _context13.abrupt("return", null);
950
+ case 17:
951
+ case "end":
952
+ return _context13.stop();
953
+ }
954
+ }, _callee13, null, [[0, 13]]);
955
+ }));
956
+ return function (_x24) {
957
+ return _ref13.apply(this, arguments);
958
+ };
959
+ }(), []);
960
+ var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
961
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(value) {
962
+ var _agentObjRef$current3, _bussinessParamsRef$c2;
963
+ var currentBussinessParams, params, res;
964
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
965
+ while (1) switch (_context14.prev = _context14.next) {
966
+ case 0:
967
+ if ((_agentObjRef$current3 = agentObjRef.current) !== null && _agentObjRef$current3 !== void 0 && _agentObjRef$current3.agentId) {
968
+ _context14.next = 2;
969
+ break;
970
+ }
971
+ return _context14.abrupt("return", Toast.error('请先关联智能体'));
972
+ case 2:
973
+ currentBussinessParams = _objectSpread({}, ((_bussinessParamsRef$c2 = bussinessParamsRef.current) === null || _bussinessParamsRef$c2 === void 0 ? void 0 : _bussinessParamsRef$c2.bussinessParams) || {});
974
+ params = _objectSpread({
975
+ content: value,
976
+ conversationType: agentObjRef.current.conversationType,
977
+ botId: agentObjRef.current.botId
978
+ }, currentBussinessParams);
979
+ isNewConversationRef.current = true;
980
+ _context14.prev = 5;
981
+ setMsgLoading(true);
982
+ _context14.next = 9;
983
+ return createRoomId(params);
984
+ case 9:
985
+ res = _context14.sent;
986
+ if (res.status === 0) {
987
+ dispatch(setConversationId({
988
+ conversationId: res.result
989
+ }));
990
+ getHeaderValue(res.result);
991
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
992
+ handleSend(value, agentObjRef.current, false, res.result);
993
+ } else {
994
+ Toast.error(res.message);
995
+ }
996
+ _context14.next = 17;
997
+ break;
998
+ case 13:
999
+ _context14.prev = 13;
1000
+ _context14.t0 = _context14["catch"](5);
1001
+ console.log('error', _context14.t0);
1002
+ setMsgLoading(false);
1003
+ case 17:
1004
+ case "end":
1005
+ return _context14.stop();
1006
+ }
1007
+ }, _callee14, null, [[5, 13]]);
1008
+ }));
1009
+ return function (_x25) {
1010
+ return _ref14.apply(this, arguments);
1011
+ };
1012
+ }(), [fetchAgentDetail]);
1013
+ React.useEffect(function () {
1014
+ if (agentId && baseUrl) {
1015
+ fetchAgentDetail(agentId);
1016
+ }
1017
+ }, [agentId, baseUrl]);
1018
+ var handleSend = React.useCallback( /*#__PURE__*/function () {
1019
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(val) {
1020
+ var agent,
1021
+ isSystemAuto,
1022
+ conversationId,
1023
+ value,
1024
+ fileValidationMsg,
1025
+ cleanVal,
1026
+ userChat,
1027
+ prevChatList,
1028
+ _prevChatList,
1029
+ lastItem,
1030
+ newChatList,
1031
+ _args15 = arguments;
1032
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1033
+ while (1) switch (_context15.prev = _context15.next) {
1034
+ case 0:
1035
+ agent = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : agentObjRef.current;
1036
+ isSystemAuto = _args15.length > 2 && _args15[2] !== undefined ? _args15[2] : false;
1037
+ conversationId = _args15.length > 3 ? _args15[3] : undefined;
1038
+ value = val.trim();
1039
+ if (!(!value && !isSystemAuto)) {
1040
+ _context15.next = 6;
1041
+ break;
1042
+ }
1043
+ return _context15.abrupt("return");
1044
+ case 6:
1045
+ if (navigator.onLine) {
1046
+ _context15.next = 9;
1047
+ break;
1048
+ }
1049
+ Toast.error('无法连接到网络');
1050
+ return _context15.abrupt("return");
1051
+ case 9:
1052
+ if (!(status === 2 || isMsgRecievingRef.current)) {
1053
+ _context15.next = 12;
1054
+ break;
1055
+ }
1056
+ Toast.error('AI正在输出中,请稍后');
1057
+ return _context15.abrupt("return");
1058
+ case 12:
1059
+ fileValidationMsg = fileValidation(fileListRef.current);
1060
+ if (!fileValidationMsg) {
1061
+ _context15.next = 16;
1062
+ break;
1063
+ }
1064
+ Toast.error(fileValidationMsg);
1065
+ return _context15.abrupt("return");
1066
+ case 16:
1067
+ if (isPlaying) {
1068
+ // 点击发送按钮时,先停止播放
1069
+ stopTTSByText === null || stopTTSByText === void 0 || stopTTSByText();
1070
+ }
1071
+ valueRef.current = '';
1072
+ cleanVal = filterPropmptFromUserInput(agent.defaultPrompt, val);
1073
+ userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current));
1074
+ vipLevelRef.current = null;
1075
+
1076
+ // 根据isSystemAuto决定是否添加用户消息到列表
1077
+ prevChatList = messageListRef.current.slice();
1078
+ if (!isSystemAuto) {
1079
+ setMsgLoading(true);
1080
+ if (((_prevChatList = prevChatList) === null || _prevChatList === void 0 ? void 0 : _prevChatList.length) > 1) {
1081
+ lastItem = prevChatList[prevChatList.length - 1];
1082
+ if (lastItem.moduleType === 'ask') {
1083
+ prevChatList = [].concat(_toConsumableArray(prevChatList.slice(0, -1)), [_objectSpread(_objectSpread({}, prevChatList[prevChatList.length - 1]), {}, {
1084
+ disableUploadFile: true
1085
+ })]);
1086
+ }
1087
+ }
1088
+ newChatList = [].concat(_toConsumableArray(prevChatList), [userChat]);
1089
+ dispatch(setMessageList({
1090
+ messageList: newChatList
1091
+ }));
1092
+ startChat(newChatList, isSystemAuto, conversationId);
1093
+ } else {
1094
+ setMsgLoading(true);
1095
+ // 系统自动上传,直接开始会话,不更新列表
1096
+ startChat([].concat(_toConsumableArray(prevChatList), [userChat]), isSystemAuto, conversationId);
1097
+ }
1098
+ case 23:
1099
+ case "end":
1100
+ return _context15.stop();
1101
+ }
1102
+ }, _callee15);
1103
+ }));
1104
+ return function (_x26) {
1105
+ return _ref15.apply(this, arguments);
1106
+ };
1107
+ }(), [dispatch, startChat]);
1108
+ var handleSendFile = React.useCallback(function (messageList) {
1109
+ if (!navigator.onLine) {
1110
+ Toast.error('无法连接到网络');
1111
+ return;
1112
+ }
1113
+ if (status === 2 || msgLoading) {
1114
+ Toast.error('AI正在输出中,请稍后');
1115
+ return;
1116
+ }
1117
+ valueRef.current = '';
1118
+ setMsgLoading(true);
1119
+ startChat(messageList, false, undefined, true);
1120
+ }, [dispatch, startChat, status, msgLoading]);
1121
+ React.useEffect(function () {
1122
+ var _fileListRef$current;
1123
+ var hasValidFile = ((_fileListRef$current = fileListRef.current) === null || _fileListRef$current === void 0 ? void 0 : _fileListRef$current.length) > 0;
1124
+ var messageList = messageListRef.current || [];
1125
+ var lastMessage = messageList[messageList.length - 1];
1126
+ if (hasValidFile && lastMessage) {
1127
+ setDisableSend(true);
1128
+ var uploadFile = fileList[0];
1129
+ var isLastMessageEmptyUserChat = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'ask'; // 空内容
1130
+ if (!isLastMessageEmptyUserChat) {
1131
+ var _fileList$, _messageList;
1132
+ var shouldEnableUpload = uploadFile.status === FileStatus.UPLOAD_FAILED || uploadFile.status === FileStatus.ANALYSE_FAILED;
1133
+ var newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -2)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 2]), {}, {
1134
+ disableUploadFile: !shouldEnableUpload
1135
+ }), _objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
1136
+ messageFiles: uploadFile
1137
+ })]);
1138
+ dispatch(setMessageList({
1139
+ messageList: newMessageList
1140
+ }));
1141
+ // 当有文件内容时处理请求
1142
+ if ((_fileList$ = fileList[0]) !== null && _fileList$ !== void 0 && _fileList$.content && ((_messageList = messageList[messageList.length - 2]) === null || _messageList === void 0 ? void 0 : _messageList.moduleType) === 'ask') {
1143
+ var _reverse$find3, _messageListRef$curre;
1144
+ var moduleInfo = (_reverse$find3 = _toConsumableArray(messageList).reverse().find(function (v) {
1145
+ return v.moduleType === 'ask';
1146
+ })) === null || _reverse$find3 === void 0 ? void 0 : _reverse$find3.moduleInfo;
1147
+ var _inputModel = _defineProperty({}, "".concat(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.id, ".input"), '');
1148
+ inputModelRef.current = _inputModel;
1149
+ if (((_messageListRef$curre = messageListRef.current) === null || _messageListRef$curre === void 0 ? void 0 : _messageListRef$curre.length) > 0) {
1150
+ handleSendFile(newMessageList);
1151
+ }
1152
+ }
1153
+ } else {
1154
+ var _newMessageList2 = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
1155
+ disableUploadFile: true
1156
+ }), createUserChat('', "".concat(conversationIdRef.current))]);
1157
+ dispatch(setMessageList({
1158
+ messageList: _newMessageList2
1159
+ }));
1160
+ }
1161
+ }
1162
+ }, [fileList, dispatch]);
1163
+ var onSucessExcel = React.useCallback(function (value) {
1164
+ // setDisableSend(true);
1165
+ setMsgLoading(false);
1166
+ var messageList = messageListRef.current || [];
1167
+ var index = messageList.findIndex(function (v) {
1168
+ var _v$moduleInfo;
1169
+ return v.moduleType === 'skill' && value.requestId === ((_v$moduleInfo = v.moduleInfo) === null || _v$moduleInfo === void 0 || (_v$moduleInfo = _v$moduleInfo.data) === null || _v$moduleInfo === void 0 || (_v$moduleInfo = _v$moduleInfo.results) === null || _v$moduleInfo === void 0 || (_v$moduleInfo = _v$moduleInfo.skillResult) === null || _v$moduleInfo === void 0 ? void 0 : _v$moduleInfo.requestId);
1170
+ });
1171
+ if (index !== -1) {
1172
+ var newMessageList = messageList.slice(0, -1);
1173
+ dispatch(setMessageList({
1174
+ messageList: newMessageList
1175
+ }));
1176
+ messageListRef.current = newMessageList;
1177
+ var _inputModel = {
1178
+ requestId: value.requestId,
1179
+ isRetry: false
1180
+ };
1181
+ inputModelRef.current = _inputModel;
1182
+ setDisableSend(true);
1183
+ handleSend('', agentObjRef.current, true);
1184
+ }
1185
+ }, [dispatch]);
1186
+ React.useEffect(function () {
1187
+ if ((messageList === null || messageList === void 0 ? void 0 : messageList.length) > 0) {
1188
+ var _chatItem$moduleInfo, _chatItem$moduleInfo2;
1189
+ // 设置输入框是否可点击
1190
+ var chatItem = messageList[messageList.length - 1];
1191
+ if (chatItem.moduleType === 'ask' && (chatItem === null || chatItem === void 0 || (_chatItem$moduleInfo = chatItem.moduleInfo) === null || _chatItem$moduleInfo === void 0 || (_chatItem$moduleInfo = _chatItem$moduleInfo.data) === null || _chatItem$moduleInfo === void 0 || (_chatItem$moduleInfo = _chatItem$moduleInfo.results) === null || _chatItem$moduleInfo === void 0 ? void 0 : _chatItem$moduleInfo.askShowInfo.answerType) === 1) {
1192
+ setDisableSend(true);
1193
+ } else if (chatItem.moduleType === 'skill' && (chatItem === null || chatItem === void 0 || (_chatItem$moduleInfo2 = chatItem.moduleInfo) === null || _chatItem$moduleInfo2 === void 0 || (_chatItem$moduleInfo2 = _chatItem$moduleInfo2.data) === null || _chatItem$moduleInfo2 === void 0 || (_chatItem$moduleInfo2 = _chatItem$moduleInfo2.results) === null || _chatItem$moduleInfo2 === void 0 ? void 0 : _chatItem$moduleInfo2.skillResult.requestStatus) !== 1) {
1194
+ setDisableSend(true);
1195
+ } else if (chatItem.mcp && !chatItem.content && !chatItem.reasoningContent) {
1196
+ // mcp工具调用中,但没有end输出时,不能被终止
1197
+ setDisableSend(true);
1198
+ } else {
1199
+ setDisableSend(false);
1200
+ }
1201
+ }
1202
+ if ((messageList === null || messageList === void 0 ? void 0 : messageList.length) > 0) {
1203
+ var _chatItem$moduleInfo3;
1204
+ var _chatItem = messageList[messageList.length - 1];
1205
+ if (_chatItem.moduleType === 'skill' && (_chatItem === null || _chatItem === void 0 || (_chatItem$moduleInfo3 = _chatItem.moduleInfo) === null || _chatItem$moduleInfo3 === void 0 || (_chatItem$moduleInfo3 = _chatItem$moduleInfo3.data) === null || _chatItem$moduleInfo3 === void 0 || (_chatItem$moduleInfo3 = _chatItem$moduleInfo3.results) === null || _chatItem$moduleInfo3 === void 0 ? void 0 : _chatItem$moduleInfo3.skillResult.requestStatus) === 1) {
1206
+ onSucessExcel(_chatItem.skillResult);
1207
+ }
1208
+ }
1209
+ }, [messageList, onSucessExcel]);
1210
+ var onFailureExcel = React.useCallback(function (value, id) {
1211
+ // setDisableSend(true);
1212
+ var index = messageListRef.current.findIndex(function (v) {
1213
+ return v.id === id;
1214
+ });
1215
+ if (index !== -1) {
1216
+ var newMessageList = messageListRef.current.slice();
1217
+ newMessageList.map(function (item, i) {
1218
+ if (i === index) {
1219
+ // 使用 _.set 来设置深层属性
1220
+ var updatedItem = cloneDeep(item); // 先深拷贝避免修改原对象
1221
+ set(updatedItem, 'moduleInfo.data.results.skillResult', value);
1222
+ moduleInfoRef.current = updatedItem.moduleInfo;
1223
+ return _objectSpread(_objectSpread({}, updatedItem), {}, {
1224
+ reTryed: false
1225
+ });
1226
+ }
1227
+ return item;
1228
+ });
1229
+ dispatch(setMessageList({
1230
+ messageList: newMessageList
1231
+ }));
1232
+ }
1233
+ }, [dispatch]);
1234
+ var onRetryExcel = React.useCallback(function (value, id) {
1235
+ var newMessageList = messageListRef.current.map(function (item) {
1236
+ return (
1237
+ // 找到id匹配的项,更新reTryed为true,其他项保持不变
1238
+ item.id === id ? _objectSpread(_objectSpread({}, item), {}, {
1239
+ reTryed: true
1240
+ }) : item
1241
+ );
1242
+ });
1243
+ dispatch(setMessageList({
1244
+ messageList: newMessageList
1245
+ }));
1246
+ var _inputModel = {
1247
+ requestId: value.requestId,
1248
+ isRetry: true
1249
+ };
1250
+ inputModelRef.current = _inputModel;
1251
+ handleSend('重试');
1252
+ }, []);
1253
+ return {
1254
+ headerValue: headerValue,
1255
+ getHeaderValue: getHeaderValue,
1256
+ msgLoading: msgLoading,
1257
+ onSucessExcel: onSucessExcel,
1258
+ onFailureExcel: onFailureExcel,
1259
+ onRetryExcel: onRetryExcel,
1260
+ disableSend: disableSend,
1261
+ inputModelRef: inputModelRef,
1262
+ handleInterrupt: handleInterrupt,
1263
+ getContentMessageList: getContentMessageList,
1264
+ hasMore: hasMore,
1265
+ handleSend: handleSend,
1266
+ scrollBottomForce: scrollBottomForce,
1267
+ showBackBottom: currentPosition > 100,
1268
+ isScrolling: isScrolling,
1269
+ isMoreLoading: isMoreLoading,
1270
+ startConversationAndChat: startConversationAndChat,
1271
+ deleteConversation: deleteConversation,
1272
+ regenerate: regenerate,
1273
+ startAICorrection: startAICorrection
1274
+ };
1275
+ };
1276
+ export default useCommonChatAPI;