@myun/gimi-chat 0.0.3 → 0.0.4

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.scss +272 -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.scss +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.scss +295 -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.scss +125 -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.scss +44 -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.scss +45 -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.scss +27 -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.scss +210 -0
  70. package/dist/components/excel-components/styles.module.scss +186 -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.scss +139 -0
  76. package/dist/components/file-preview/index.d.ts +3 -0
  77. package/dist/components/file-preview/index.js +229 -0
  78. package/dist/components/file-preview/index.module.scss +120 -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.scss +136 -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.scss +26 -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.scss +262 -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 +167 -0
  120. package/dist/components/message-list/index.module.scss +304 -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.scss +42 -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.scss +48 -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.scss +76 -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.scss +164 -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.scss +73 -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 +110 -0
  142. package/dist/components/templates/index.module.scss +119 -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.scss +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.scss +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.scss +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.scss +23 -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 +2 -3
  206. package/LICENSE +0 -21
@@ -0,0 +1,55 @@
1
+ import * as React from 'react';
2
+ import styles from "./index.module.scss";
3
+ import { Spin } from '@douyinfe/semi-ui';
4
+ import { LoadingOutlined, InfoCircleOutlined } from '@ant-design/icons';
5
+ var antIcon = /*#__PURE__*/React.createElement(LoadingOutlined, {
6
+ style: {
7
+ fontSize: 16
8
+ },
9
+ spin: true
10
+ });
11
+ var warnIcon = /*#__PURE__*/React.createElement(InfoCircleOutlined, {
12
+ style: {
13
+ fontSize: 16
14
+ }
15
+ });
16
+ var WorkFlowContent = function WorkFlowContent(_ref) {
17
+ var chatItem = _ref.chatItem;
18
+ // const isExecuting = chatItem.mcps.some((item: MCPItem) => !item.isFinished);
19
+ var mcp = chatItem.mcp;
20
+ return /*#__PURE__*/React.createElement("div", {
21
+ className: styles.layout
22
+ }, mcp.status === 'executeWorkflowByDescription' ? '正在查询可用工作流...' : mcp.status === 'interrupt' ? '运行终止' : "\u6B63\u5728\u8C03\u7528 ".concat(mcp.name || '工作流', "..."), mcp.status === 'interrupt' ? warnIcon : /*#__PURE__*/React.createElement(Spin, {
23
+ className: styles.spin,
24
+ indicator: antIcon
25
+ }));
26
+
27
+ // return (
28
+ // <Collapse
29
+ // bordered={false}
30
+ // defaultActiveKey={isExecuting ? ['1'] : []}
31
+ // expandIcon={({ isActive }) => <CaretRightOutlined rotate={isActive ? 90 : 0} />}
32
+ // className={styles.collapse}
33
+ // >
34
+ // <Panel header="工具流运行过程" key="1" className="site-collapse-custom-panel">
35
+ // {chatItem.mcps.map((mcp: MCPItem, index: number) => {
36
+ // return (
37
+ // <div className={styles.layout} key={index}>
38
+ // {
39
+ // mcp.isFinished ? `已调用 ${mcp.name}` :
40
+ // mcp.status === 'executeWorkflowByDescription' ? '正在查询可用工作流...'
41
+ // : mcp.status === 'interrupt' ? '运行终止' : `正在调用 ${mcp.name || 'MCP工具'}...`
42
+ // }
43
+ // {
44
+ // mcp.isFinished ? checkIcon :
45
+ // mcp.status === 'interrupt' ? warnIcon
46
+ // : <Spin className={styles.spin} indicator={antIcon} />
47
+ // }
48
+ // </div>
49
+ // )
50
+ // })}
51
+ // </Panel>
52
+ // </Collapse>
53
+ // )
54
+ };
55
+ export default WorkFlowContent;
@@ -0,0 +1,23 @@
1
+ .collapse {
2
+ border-radius: 8px;
3
+ margin-bottom: 10px;
4
+ }
5
+ .layout {
6
+ display: flex;
7
+ justify-content: start;
8
+ align-items: center;
9
+ width: fit-content;
10
+ gap: 10px;
11
+ padding: 5px 10px;
12
+ margin-bottom: 5px;
13
+ border: 1px solid #d9dce5;
14
+ border-radius: 8px;
15
+ font-family: 'PingFang SC';
16
+ font-weight: 400;
17
+ font-size: 14px;
18
+ line-height: 18px;
19
+ letter-spacing: 0px;
20
+ .spin {
21
+ color: #d9d9d9;
22
+ }
23
+ }
@@ -0,0 +1,24 @@
1
+ export declare const knowledgeConstants: {
2
+ VIDEO_ICON_ADDRESS: string;
3
+ VIDEO_ICON_KNOWLADGE_TRACE_ADDRESS: string;
4
+ DOCUMENT_ICON_ADDRESS: string;
5
+ CLASS_ICON_ADDRESS: string;
6
+ CLASS_ICON_BIG_ADDRESS: string;
7
+ VIDEO_ICON_WHITE_ADDRESS: string;
8
+ DOCUMENT_WHITE_ICON_ADDRESS: string;
9
+ CLASS_ICON_WHITE_ADDRESS: string;
10
+ VIDEO_PLAY_ICON_ADDRESS: string;
11
+ VIDEO_DEFAULT_COVER_ADDRESS: string;
12
+ };
13
+ export declare const documentConstants: {
14
+ txt: string;
15
+ xls: string;
16
+ xlsx: string;
17
+ docx: string;
18
+ doc: string;
19
+ default: string;
20
+ };
21
+ export declare const gimiConstants: {
22
+ GIMI_ICON_HEAD: string;
23
+ GIMI_ICON_HEAD_WITH_NAME: string;
24
+ };
@@ -0,0 +1,24 @@
1
+ export var knowledgeConstants = {
2
+ VIDEO_ICON_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/28/19116_20251128152844.png',
3
+ VIDEO_ICON_KNOWLADGE_TRACE_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202512/05/5dda1_20251205145434.png',
4
+ DOCUMENT_ICON_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/10/1c1a5_20251110100244.png',
5
+ CLASS_ICON_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/10/3c093_20251110102706.png',
6
+ CLASS_ICON_BIG_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/28/7c759_20251128153111.png',
7
+ VIDEO_ICON_WHITE_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/10/77cdc_20251110132223.png',
8
+ DOCUMENT_WHITE_ICON_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/10/fa3ea_20251110132431.png',
9
+ CLASS_ICON_WHITE_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/10/61fdf_20251110132334.png',
10
+ VIDEO_PLAY_ICON_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/19/1f688_20251119160747.png',
11
+ VIDEO_DEFAULT_COVER_ADDRESS: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/19/7a643_20251119160927.png'
12
+ };
13
+ export var documentConstants = {
14
+ txt: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/17/b46c7_20250917144926.png',
15
+ xls: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/17/0094f_20250917144837.png',
16
+ xlsx: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/17/0094f_20250917144837.png',
17
+ docx: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/07/8b9fd_20251107170539.png',
18
+ doc: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/07/8b9fd_20251107170539.png',
19
+ default: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/20/901c2_20251120162226.png'
20
+ };
21
+ export var gimiConstants = {
22
+ GIMI_ICON_HEAD: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/28/f6086_20251128163416.png',
23
+ GIMI_ICON_HEAD_WITH_NAME: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202511/28/576a3_20251128164232.png'
24
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { IChatMessageItem } from '../interfaces/chatMessage';
3
+ export declare const usePureChatActions: () => {
4
+ copyToClipboard: (value: IChatMessageItem, replaceTags?: string[]) => Promise<void>;
5
+ handleUnlove: (item: IChatMessageItem, type: 'love' | 'unlove') => Promise<void>;
6
+ };
7
+ declare const useChatActions: (showCopyId: number | null, inputModelRef: React.MutableRefObject<any>, handleSend: (val: string, agent?: any, isSystemAuto?: boolean) => void) => {
8
+ showOpera: (id: number) => boolean;
9
+ showCommend: (id: number) => boolean;
10
+ handleClickAskList: (item: any, operation: string, key: string, value?: string | undefined) => void;
11
+ };
12
+ export default useChatActions;
@@ -0,0 +1,207 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
+ 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; }
16
+ import React from 'react';
17
+ import { Toast } from "@douyinfe/semi-ui";
18
+ import { createFetch } from "../apis/fetch";
19
+ import { useAppSelector, useAppDispatch } from "../store/hooks";
20
+ import { setMessageList } from "../store/slices/gimiMenuSlice";
21
+ import { processString } from "../utils/tools";
22
+ import { debounce } from "../utils/chatInputUtil";
23
+ import useApi from "../apis/useApi";
24
+ var updateLastMessage = function updateLastMessage(chatList, updater) {
25
+ if (chatList.length === 0) return chatList;
26
+ return [].concat(_toConsumableArray(chatList.slice(0, -1)), [updater(chatList[chatList.length - 1])]);
27
+ };
28
+ export var usePureChatActions = function usePureChatActions() {
29
+ var _useApi = useApi(),
30
+ handleMark = _useApi.handleMark;
31
+ var baseUrl = useAppSelector(function (state) {
32
+ return state.gimiMenu.baseUrl;
33
+ });
34
+ var baseUrlRef = React.useRef(baseUrl);
35
+ baseUrlRef.current = baseUrl;
36
+ var messageList = useAppSelector(function (state) {
37
+ return state.gimiMenu.messageList;
38
+ });
39
+ var messageListRef = React.useRef(messageList);
40
+ messageListRef.current = messageList;
41
+ var dispatch = useAppDispatch();
42
+ var apiRef = React.useRef(createFetch({
43
+ baseURL: baseUrlRef.current,
44
+ timeout: 10000
45
+ }));
46
+ apiRef.current = createFetch({
47
+ baseURL: baseUrlRef.current,
48
+ timeout: 10000
49
+ });
50
+ var copyToClipboard = React.useCallback( /*#__PURE__*/function () {
51
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
52
+ var replaceTags,
53
+ text,
54
+ _value$moduleInfo,
55
+ _value$moduleInfo2,
56
+ _args = arguments;
57
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
58
+ while (1) switch (_context.prev = _context.next) {
59
+ case 0:
60
+ replaceTags = _args.length > 1 && _args[1] !== undefined ? _args[1] : ['knowledge', 'excel'];
61
+ if (value.moduleType === 'skill') {
62
+ text = ((_value$moduleInfo = value.moduleInfo) === null || _value$moduleInfo === void 0 ? void 0 : _value$moduleInfo.data.results.skillResult.message) || '';
63
+ } else if (value.moduleType === 'ask') {
64
+ text = ((_value$moduleInfo2 = value.moduleInfo) === null || _value$moduleInfo2 === void 0 ? void 0 : _value$moduleInfo2.data.results.askShowInfo.questionContent) || '';
65
+ } else if (value.moduleType === 'end' || value.moduleType === 'COMPLETED') {
66
+ text = value.content || '';
67
+ } else {
68
+ text = '';
69
+ }
70
+ text.replace(/<\*segmentNumber\*>([^<]+)<\/\*end\*>/g, '');
71
+ replaceTags.forEach(function (tag) {
72
+ text = text.replace(new RegExp("<".concat(tag, ">(.*?)</").concat(tag, ">"), 'g'), '');
73
+ });
74
+ _context.prev = 4;
75
+ _context.next = 7;
76
+ return navigator.clipboard.writeText(text);
77
+ case 7:
78
+ Toast.success('复制成功');
79
+ _context.next = 13;
80
+ break;
81
+ case 10:
82
+ _context.prev = 10;
83
+ _context.t0 = _context["catch"](4);
84
+ Toast.error('复制失败');
85
+ case 13:
86
+ case "end":
87
+ return _context.stop();
88
+ }
89
+ }, _callee, null, [[4, 10]]);
90
+ }));
91
+ return function (_x) {
92
+ return _ref.apply(this, arguments);
93
+ };
94
+ }(), []);
95
+ /**
96
+ * 点赞/点踩
97
+ */
98
+ var handleUnlove = React.useCallback( /*#__PURE__*/function () {
99
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item, type) {
100
+ var mark, params, newMessageList, res;
101
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
102
+ while (1) switch (_context2.prev = _context2.next) {
103
+ case 0:
104
+ mark = 0;
105
+ if (type === 'love') {
106
+ mark = item.mark === 2 ? 0 : 2;
107
+ } else if (type === 'unlove') {
108
+ mark = item.mark === 1 ? 0 : 1;
109
+ }
110
+ params = {
111
+ id: Number(item.questionId),
112
+ mark: mark
113
+ };
114
+ _context2.prev = 3;
115
+ // setChatList((prev) => prev.map((v) => (v.id === item.id ? { ...v, mark } : v)));
116
+ newMessageList = messageListRef.current.map(function (v) {
117
+ return v.id === item.id ? _objectSpread(_objectSpread({}, v), {}, {
118
+ mark: mark
119
+ }) : v;
120
+ });
121
+ dispatch(setMessageList({
122
+ messageList: newMessageList
123
+ }));
124
+ Toast.success(mark === 2 ? '已点赞' : mark === 1 ? '已点踩' : item.mark === 2 ? '取消点赞' : '取消点踩');
125
+ _context2.next = 9;
126
+ return handleMark(params);
127
+ case 9:
128
+ res = _context2.sent;
129
+ if (res.status !== 0) {
130
+ Toast.error(res.message);
131
+ }
132
+ _context2.next = 16;
133
+ break;
134
+ case 13:
135
+ _context2.prev = 13;
136
+ _context2.t0 = _context2["catch"](3);
137
+ Toast.error('操作失败');
138
+ case 16:
139
+ case "end":
140
+ return _context2.stop();
141
+ }
142
+ }, _callee2, null, [[3, 13]]);
143
+ }));
144
+ return function (_x2, _x3) {
145
+ return _ref2.apply(this, arguments);
146
+ };
147
+ }(), []);
148
+ return {
149
+ copyToClipboard: copyToClipboard,
150
+ handleUnlove: handleUnlove
151
+ };
152
+ };
153
+ var useChatActions = function useChatActions(showCopyId, inputModelRef, handleSend) {
154
+ var messageList = useAppSelector(function (state) {
155
+ return state.gimiMenu.messageList;
156
+ });
157
+ var messageListRef = React.useRef(messageList);
158
+ messageListRef.current = messageList;
159
+ var dispatch = useAppDispatch();
160
+ /**
161
+ * 判断是否显示复制操作
162
+ */
163
+ var showOpera = React.useCallback(function (id) {
164
+ var _messageList, _messageList2, _messageList3, _messageList4;
165
+ var messageList = messageListRef.current;
166
+ return id === showCopyId && id !== ((_messageList = messageList[messageList.length - 1]) === null || _messageList === void 0 ? void 0 : _messageList.id) || Boolean(id === ((_messageList2 = messageList[messageList.length - 1]) === null || _messageList2 === void 0 ? void 0 : _messageList2.id) && processString(((_messageList3 = messageList[messageList.length - 1]) === null || _messageList3 === void 0 ? void 0 : _messageList3.content) || '') && !((_messageList4 = messageList[messageList.length - 1]) !== null && _messageList4 !== void 0 && _messageList4.loading));
167
+ }, [showCopyId]);
168
+
169
+ /**
170
+ * 判断是否显示推荐
171
+ */
172
+ var showCommend = React.useCallback(function (id) {
173
+ var _messageList5, _messageList6, _messageList7;
174
+ var messageList = messageListRef.current;
175
+ return id === ((_messageList5 = messageList[messageList.length - 1]) === null || _messageList5 === void 0 ? void 0 : _messageList5.id) && Boolean(processString(((_messageList6 = messageList[messageList.length - 1]) === null || _messageList6 === void 0 ? void 0 : _messageList6.content) || '') && !((_messageList7 = messageList[messageList.length - 1]) !== null && _messageList7 !== void 0 && _messageList7.loading));
176
+ }, []);
177
+
178
+ /**
179
+ * 点击问询列表
180
+ */
181
+ var handleClickAskList = React.useMemo(function () {
182
+ return debounce(function (item, operation, key, value) {
183
+ var _messageList8;
184
+ var messageList = messageListRef.current;
185
+ if ((_messageList8 = messageList[messageList.length - 1]) !== null && _messageList8 !== void 0 && _messageList8.selectValue) {
186
+ return;
187
+ }
188
+ var _inputModel = _defineProperty({}, "".concat(item.id, ".").concat(operation), key);
189
+ inputModelRef.current = _inputModel;
190
+ var newMessageList = updateLastMessage(messageList, function (lastMessage) {
191
+ return _objectSpread(_objectSpread({}, lastMessage), {}, {
192
+ selectValue: key
193
+ });
194
+ });
195
+ dispatch(setMessageList({
196
+ messageList: newMessageList
197
+ }));
198
+ handleSend(value || '');
199
+ }, 100);
200
+ }, [handleSend, inputModelRef, dispatch]);
201
+ return {
202
+ showOpera: showOpera,
203
+ showCommend: showCommend,
204
+ handleClickAskList: handleClickAskList
205
+ };
206
+ };
207
+ export default useChatActions;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { IChatMessageItem } from '../interfaces/chatMessage';
3
+ declare const useChatHistory: (checkUnfinishedMessage: (chatList: IChatMessageItem[]) => Promise<void>, scrollBottomForce: () => void, containerRef: React.RefObject<HTMLDivElement>) => {
4
+ getContentMessageList: (pageIndex?: number, curPageSize?: number) => Promise<void>;
5
+ isMoreLoading: boolean;
6
+ hasMore: React.MutableRefObject<boolean>;
7
+ };
8
+ export default useChatHistory;
@@ -0,0 +1,225 @@
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ 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."); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ 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); } }
8
+ 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); }); }; }
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ 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); }
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 React, { useCallback, useEffect, useRef } from 'react';
21
+ import { useAppDispatch, useAppSelector } from "../store/hooks";
22
+ import { setMessageList } from "../store/slices/gimiMenuSlice";
23
+ import useApi from "../apis/useApi";
24
+ import { formatFields, updatedSkillResult } from "../utils/tools";
25
+ import { useChatRecommend } from "./useChatRecommend";
26
+ import { Toast } from '@douyinfe/semi-ui';
27
+ import { throttle } from 'lodash';
28
+ var useChatHistory = function useChatHistory(checkUnfinishedMessage, scrollBottomForce, containerRef) {
29
+ var dispatch = useAppDispatch();
30
+ var _useChatRecommend = useChatRecommend(),
31
+ rewriteRecommendListFormHistory = _useChatRecommend.rewriteRecommendListFormHistory;
32
+ var conversationId = useAppSelector(function (state) {
33
+ return state.gimiMenu.conversationId;
34
+ });
35
+ var bussinessParams = useAppSelector(function (state) {
36
+ return state.gimiMenu.bussinessParams;
37
+ });
38
+ var messageList = useAppSelector(function (state) {
39
+ return state.gimiMenu.messageList;
40
+ });
41
+ var agentObj = useAppSelector(function (state) {
42
+ return state.gimiMenu.agentObj;
43
+ });
44
+ var isMsgRecieving = useAppSelector(function (state) {
45
+ return state.gimiMenu.isMsgRecieving;
46
+ });
47
+ // 加载历史对话记录相关
48
+ var hasMore = React.useRef(false);
49
+ var _React$useState = React.useState(false),
50
+ _React$useState2 = _slicedToArray(_React$useState, 2),
51
+ isMoreLoading = _React$useState2[0],
52
+ setIsMoreLoading = _React$useState2[1];
53
+ var _React$useState3 = React.useState({
54
+ pageIndex: 1,
55
+ pageSize: 10
56
+ }),
57
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
58
+ param = _React$useState4[0],
59
+ setParam = _React$useState4[1];
60
+ var _useApi = useApi(),
61
+ getMessageList = _useApi.getMessageList;
62
+
63
+ // 使用 ref 存储最新的值,避免闭包陷阱
64
+ var messageListRef = useRef(messageList);
65
+ var agentObjRef = useRef(agentObj);
66
+ var isMoreLoadingRef = useRef(isMoreLoading);
67
+ var isMsgRecievingRef = useRef(isMsgRecieving);
68
+ var conversationIdRef = useRef(conversationId);
69
+ messageListRef.current = messageList;
70
+ isMsgRecievingRef.current = isMsgRecieving;
71
+ agentObjRef.current = agentObj;
72
+ isMoreLoadingRef.current = isMoreLoading;
73
+ conversationIdRef.current = conversationId;
74
+
75
+ // 处理滚动事件
76
+ useEffect(function () {
77
+ var container = containerRef.current;
78
+ if (!container) return;
79
+ var handleScroll = throttle(function () {
80
+ var scrollTop = container.scrollTop;
81
+ if (scrollTop < 50 && !isMoreLoadingRef.current && hasMore.current && !isMsgRecievingRef.current && conversationIdRef.current && !isMoreLoadingRef.current) {
82
+ setIsMoreLoading(true); // 加锁,防止重复请求
83
+ setParam(function (prev) {
84
+ var newPageIndex = prev.pageIndex + 1;
85
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
86
+ getContentMessageList(newPageIndex, prev.pageSize); // 使用新值
87
+ return _objectSpread(_objectSpread({}, prev), {}, {
88
+ pageIndex: newPageIndex
89
+ });
90
+ });
91
+ }
92
+ }, 200);
93
+ container.addEventListener('scroll', handleScroll);
94
+ return function () {
95
+ return container.removeEventListener('scroll', handleScroll);
96
+ };
97
+ }, []);
98
+
99
+ // 获取对话记录
100
+ var getContentMessageList = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
101
+ var pageIndex,
102
+ curPageSize,
103
+ currentMessageList,
104
+ currentAgentObj,
105
+ currentBussinessParams,
106
+ params,
107
+ res,
108
+ resData,
109
+ _newResData,
110
+ newChatList,
111
+ lastUserRequestMessage,
112
+ lastMessage,
113
+ _lastUserRequestMessa,
114
+ container,
115
+ prevScrollHeight,
116
+ prevScrollTop,
117
+ _args = arguments;
118
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
119
+ while (1) switch (_context.prev = _context.next) {
120
+ case 0:
121
+ pageIndex = _args.length > 0 && _args[0] !== undefined ? _args[0] : param.pageIndex;
122
+ curPageSize = _args.length > 1 && _args[1] !== undefined ? _args[1] : param.pageSize;
123
+ currentMessageList = messageListRef.current;
124
+ currentAgentObj = agentObjRef.current;
125
+ currentBussinessParams = _objectSpread({}, bussinessParams.bussinessParams);
126
+ _context.prev = 5;
127
+ params = {
128
+ pageIndex: pageIndex,
129
+ pageSize: curPageSize,
130
+ sort: 0,
131
+ where: _objectSpread({
132
+ conversationId: conversationIdRef.current,
133
+ botId: currentAgentObj === null || currentAgentObj === void 0 ? void 0 : currentAgentObj.botId
134
+ }, currentBussinessParams)
135
+ };
136
+ setIsMoreLoading(true);
137
+ _context.next = 10;
138
+ return getMessageList(params);
139
+ case 10:
140
+ res = _context.sent;
141
+ if (!(res && res.status === 0)) {
142
+ _context.next = 38;
143
+ break;
144
+ }
145
+ resData = formatFields(res.result.data, res.result.first ? [] : currentMessageList) || [];
146
+ _newResData = updatedSkillResult(resData);
147
+ newChatList = [].concat(_toConsumableArray(_newResData), _toConsumableArray(currentMessageList));
148
+ lastUserRequestMessage = null;
149
+ lastMessage = newChatList[newChatList.length - 1];
150
+ if ((newChatList === null || newChatList === void 0 ? void 0 : newChatList.length) > 0) {
151
+ lastUserRequestMessage = newChatList.filter(function (item) {
152
+ return item.role === 0;
153
+ }).slice(-1)[0];
154
+ }
155
+ hasMore.current = res.result.last === undefined ? false : !res.result.last;
156
+ if (!res.result.first) {
157
+ _context.next = 26;
158
+ break;
159
+ }
160
+ dispatch(setMessageList({
161
+ messageList: _newResData
162
+ }));
163
+ _context.next = 23;
164
+ return checkUnfinishedMessage(_newResData);
165
+ case 23:
166
+ setTimeout(function () {
167
+ scrollBottomForce();
168
+ }, 0);
169
+ _context.next = 36;
170
+ break;
171
+ case 26:
172
+ container = containerRef.current;
173
+ prevScrollHeight = (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0;
174
+ prevScrollTop = (container === null || container === void 0 ? void 0 : container.scrollTop) || 0; // 2. 更新数据
175
+ // 判断是否需要重写推荐列表
176
+ if (!((currentAgentObj === null || currentAgentObj === void 0 ? void 0 : currentAgentObj.isEnableRelated) === 1 && !((_lastUserRequestMessa = lastUserRequestMessage) !== null && _lastUserRequestMessa !== void 0 && _lastUserRequestMessa.relatedResourceList) && ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'end' || (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'COMPLETED'))) {
177
+ _context.next = 34;
178
+ break;
179
+ }
180
+ _context.next = 32;
181
+ return rewriteRecommendListFormHistory(newChatList, lastUserRequestMessage.chatId);
182
+ case 32:
183
+ _context.next = 35;
184
+ break;
185
+ case 34:
186
+ dispatch(setMessageList({
187
+ messageList: newChatList
188
+ }));
189
+ case 35:
190
+ // 3. 在下一帧补偿高度差
191
+ requestAnimationFrame(function () {
192
+ var newScrollHeight = (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0;
193
+ var heightDiff = newScrollHeight - prevScrollHeight;
194
+ if (container) {
195
+ container.scrollTop = prevScrollTop + heightDiff;
196
+ }
197
+ });
198
+ case 36:
199
+ _context.next = 39;
200
+ break;
201
+ case 38:
202
+ if (res.status === 1034) {
203
+ Toast.error(res.message || '获取历史记录失败');
204
+ }
205
+ case 39:
206
+ setIsMoreLoading(false);
207
+ _context.next = 45;
208
+ break;
209
+ case 42:
210
+ _context.prev = 42;
211
+ _context.t0 = _context["catch"](5);
212
+ console.error(_context.t0);
213
+ case 45:
214
+ case "end":
215
+ return _context.stop();
216
+ }
217
+ }, _callee, null, [[5, 42]]);
218
+ })), [conversationId, bussinessParams]);
219
+ return {
220
+ getContentMessageList: getContentMessageList,
221
+ isMoreLoading: isMoreLoading,
222
+ hasMore: hasMore
223
+ };
224
+ };
225
+ export default useChatHistory;