@gientech/modual 1.9.3 → 1.9.4-fix.1

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 (442) hide show
  1. package/.editorconfig +38 -0
  2. package/.prettierignore +16 -0
  3. package/.prettierrc +17 -0
  4. package/USAGE.md +247 -0
  5. package/bash.exe.stackdump +40 -0
  6. package/components.json +21 -0
  7. package/dist/README.md +643 -0
  8. package/dist/assets/GientechStreamReader-DydY9Vu3.js +449 -0
  9. package/{assets/index-D72cKELw.js → dist/assets/index-4Ac00q5P.js} +1 -1
  10. package/{assets/index-BKe5FgcC.js → dist/assets/index-7FYeBShT.js} +1 -1
  11. package/dist/assets/index-B2rczyCX.js +1393 -0
  12. package/{assets/index-j0kQJd0a.js → dist/assets/index-CQMGllKT.js} +1 -1
  13. package/{assets/index-JwQuPQqQ.js → dist/assets/index-CwGOSlVC.js} +5 -5
  14. package/{assets/index-DwoTKC3G.js → dist/assets/index-DBPtDW8Y.js} +1 -1
  15. package/{assets/index-x8IlxRuv.js → dist/assets/index-DJPAws60.js} +72 -72
  16. package/{assets/index-g-SUxfJH.js → dist/assets/index-antI2hFx.js} +45 -45
  17. package/{assets/index-DdVFXD_y.js → dist/assets/index-q0nZjKAG.js} +1 -1
  18. package/{assets/index-CIwaLPGb.js → dist/assets/index-rkRJ-e_U.js} +1 -1
  19. package/{assets/plus-V9zUoSq6.js → dist/assets/plus-qlmqrjBc.js} +1 -1
  20. package/{assets/style-CGmZ5osp.js → dist/assets/style-BeYL_E4J.js} +1 -1
  21. package/dist/assets/style.css +1 -0
  22. package/dist/assets/style4.css +1 -0
  23. package/{assets/x-CnaaLGJF.js → dist/assets/x-DxuhxSb6.js} +1 -1
  24. package/dist/assistantConfig.js +1 -0
  25. package/dist/chat.js +815 -0
  26. package/{database.js → dist/database.js} +2 -2
  27. package/dist/databaseId.js +1 -0
  28. package/{databaseTable.js → dist/databaseTable.js} +1 -1
  29. package/dist/index.js +1 -0
  30. package/dist/modelManage.js +1 -0
  31. package/dist/package.json +68 -0
  32. package/{sensitive.js → dist/sensitive.js} +1 -1
  33. package/dist/streamFilesReader.js +1 -0
  34. package/doc_assets/2.png +0 -0
  35. package/doc_assets/demo.md +27 -0
  36. package/doc_assets/demos/dist-app/assets/index.Dh-ZAS9Z.css +2 -0
  37. package/doc_assets/demos/dist-app/assets/index.Dv8KVW18.js +23699 -0
  38. package/doc_assets/demos/dist-app/assets/index.Dv8KVW18.js.map +1 -0
  39. package/doc_assets/demos/dist-app/index.html +14 -0
  40. package/doc_assets/demos/dist-app/vite.svg +1 -0
  41. package/doc_assets/images/1.png +0 -0
  42. package/doc_assets/images/3.png +0 -0
  43. package/doc_assets/images/component-screenshot.png +1 -0
  44. package/doc_assets/install.md +5 -0
  45. package/doc_assets//346/226/271/346/241/210//344/274/230/345/214/226/346/226/271/346/241/210-/345/244/232/344/274/232/350/257/235SSE/350/277/236/346/216/245/347/256/241/347/220/206.md +504 -0
  46. package/eslint.config.js +92 -0
  47. package/index.html +13 -0
  48. package/package.json +106 -43
  49. package/package.json.demo-backup +109 -0
  50. package/postcss.config.cjs +19 -0
  51. package/public/icons/answerAwartar.png +0 -0
  52. package/public/icons/docx-file.png +0 -0
  53. package/public/icons/folder.png +0 -0
  54. package/public/icons/html.png +0 -0
  55. package/public/icons/image.png +0 -0
  56. package/public/icons/jpg-file.png +0 -0
  57. package/public/icons/json.png +0 -0
  58. package/public/icons/md.png +0 -0
  59. package/public/icons/pdf.png +0 -0
  60. package/public/icons/pptx.png +0 -0
  61. package/public/icons/questionAwartar.png +0 -0
  62. package/public/icons/sheets.png +0 -0
  63. package/public/icons/txt.png +0 -0
  64. package/public/icons/xlsx.png +0 -0
  65. package/public/vite.svg +1 -0
  66. package/public/worker/pdf.worker.min.js +22 -0
  67. package/rag/assets/Doris.3ZRHc3Fu.png +0 -0
  68. package/rag/assets/PostgreSQL.DuLqLAFX.png +0 -0
  69. package/rag/assets/SQLServer.CWyNu24v.png +0 -0
  70. package/rag/assets/empty.BfkDKJsb.png +0 -0
  71. package/rag/assets/homeBg.Mr_kGuA9.png +0 -0
  72. package/rag/assets/index.Bd0tNzw0.js +2797 -0
  73. package/rag/assets/index.D6t67hlu.css +1 -0
  74. package/rag/assets/left.KBHV5h7q.jpg +0 -0
  75. package/rag/assets/logoImg.Gmp_tdkD.png +0 -0
  76. package/rag/assets/worker-BbpylX7l.DptbXke_.js +13 -0
  77. package/rag/icons/answerAwartar.png +0 -0
  78. package/rag/icons/docx-file.png +0 -0
  79. package/rag/icons/folder.png +0 -0
  80. package/rag/icons/html.png +0 -0
  81. package/rag/icons/image.png +0 -0
  82. package/rag/icons/jpg-file.png +0 -0
  83. package/rag/icons/json.png +0 -0
  84. package/rag/icons/md.png +0 -0
  85. package/rag/icons/pdf.png +0 -0
  86. package/rag/icons/pptx.png +0 -0
  87. package/rag/icons/questionAwartar.png +0 -0
  88. package/rag/icons/sheets.png +0 -0
  89. package/rag/icons/txt.png +0 -0
  90. package/rag/icons/xlsx.png +0 -0
  91. package/scripts/README.md +133 -0
  92. package/scripts/build-demo.js +88 -0
  93. package/scripts/decrypt-api-key.js +95 -0
  94. package/scripts/demo-selector.js +216 -0
  95. package/scripts/dev-demo.js +76 -0
  96. package/scripts/preview-demo.js +130 -0
  97. package/scripts/run-demo.bat +34 -0
  98. package/src/assets/img/close.png +0 -0
  99. package/src/assets/img/database.png +0 -0
  100. package/src/assets/img/downArrow.png +0 -0
  101. package/src/assets/img/downLoad.png +0 -0
  102. package/src/assets/img/excel.png +0 -0
  103. package/src/assets/img/graphIcon.png +0 -0
  104. package/src/assets/img/img.png +0 -0
  105. package/src/assets/img/pdf.png +0 -0
  106. package/src/assets/img/ppt.png +0 -0
  107. package/src/assets/img/singleQa.png +0 -0
  108. package/src/assets/img/txt.png +0 -0
  109. package/src/assets/img/webSearch.png +0 -0
  110. package/src/assets/img/word.png +0 -0
  111. package/src/assets/login/homeBg.png +0 -0
  112. package/src/assets/login/left.jpg +0 -0
  113. package/src/assets/login/logoImg.png +0 -0
  114. package/src/examples/ConversationAssistantPage/index.tsx +41 -0
  115. package/src/examples/Demo/index.tsx +12 -0
  116. package/src/examples/LoginPage/index.tsx +18 -0
  117. package/src/examples/chat/components/DrawerGraphPreview.tsx +78 -0
  118. package/src/examples/chat/index.tsx +162 -0
  119. package/src/examples/chat/logo03.png +0 -0
  120. package/src/examples/gientechStreamFilesReader/index.tsx +951 -0
  121. package/src/examples/headlessChat/index.tsx +218 -0
  122. package/src/examples/ragDatabaseDataPage/index.tsx +40 -0
  123. package/src/examples/ragDatabaseIdPage/index.tsx +47 -0
  124. package/src/examples/ragDatabasePage/index.tsx +36 -0
  125. package/src/examples/ragModelManagePage/index.tsx +37 -0
  126. package/src/examples/ragSearchPage/index.tsx +0 -0
  127. package/src/examples/ragSensitiveWordsPage/index.tsx +32 -0
  128. package/src/examples/streamFiles/index.tsx +417 -0
  129. package/src/lib_enter.ts +43 -0
  130. package/src/main.tsx +5 -0
  131. package/src/main.tsx.backup +5 -0
  132. package/src/modules/assistantConfig/assets/databse.svg +6 -0
  133. package/src/modules/assistantConfig/assets/empty.png +0 -0
  134. package/src/modules/assistantConfig/assets/graph.svg +4 -0
  135. package/src/modules/assistantConfig/assets/knowledge.svg +4 -0
  136. package/src/modules/assistantConfig/assets/sensitive.svg +5 -0
  137. package/src/modules/assistantConfig/components/Database.tsx +171 -0
  138. package/src/modules/assistantConfig/components/Graph.tsx +177 -0
  139. package/src/modules/assistantConfig/components/Knowledge.tsx +276 -0
  140. package/src/modules/assistantConfig/components/NotFoundContent.tsx +21 -0
  141. package/src/modules/assistantConfig/components/Paragraph.tsx +51 -0
  142. package/src/modules/assistantConfig/components/ParamsItem.tsx +39 -0
  143. package/src/modules/assistantConfig/components/ResourceBinderItem.tsx +133 -0
  144. package/src/modules/assistantConfig/components/SearchableSelector.tsx +500 -0
  145. package/src/modules/assistantConfig/components/Sensitive.tsx +221 -0
  146. package/src/modules/assistantConfig/components/SliderInput.tsx +65 -0
  147. package/src/modules/assistantConfig/constants.tsx +75 -0
  148. package/src/modules/assistantConfig/index.tsx +706 -0
  149. package/src/modules/assistantConfig/server.ts +262 -0
  150. package/src/modules/chat/Conversations/Item.tsx +167 -0
  151. package/src/modules/chat/Conversations/List.tsx +210 -0
  152. package/src/modules/chat/Conversations/groupByTime.ts +39 -0
  153. package/src/modules/chat/Conversations/index.tsx +252 -0
  154. package/src/modules/chat/ReferenceBar.tsx +622 -0
  155. package/src/modules/chat/constants.tsx +56 -0
  156. package/src/modules/chat/data.txt +82 -0
  157. package/src/modules/chat/index.tsx +2087 -0
  158. package/src/modules/chat/referenceCom/DeleteModal.tsx +75 -0
  159. package/src/modules/chat/referenceCom/DrawerContent.tsx +136 -0
  160. package/src/modules/chat/referenceCom/DrawerDatabase.tsx +102 -0
  161. package/src/modules/chat/referenceCom/DrawerGraphPreview.tsx +86 -0
  162. package/src/modules/chat/referenceCom/DrawerPreview.tsx +73 -0
  163. package/src/modules/chat/referenceCom/DrawerTitle.tsx +26 -0
  164. package/src/modules/chat/referenceCom/RenameModal.tsx +86 -0
  165. package/src/modules/chat/referenceCom/TagCom.tsx +30 -0
  166. package/src/modules/chat/style.less +3 -0
  167. package/src/modules/chat/types.ts +17 -0
  168. package/src/modules/chat/utils/index.ts +348 -0
  169. package/src/modules/database/CreateModal.tsx +403 -0
  170. package/src/modules/database/assets/Doris.png +0 -0
  171. package/src/modules/database/assets/PostgreSQL.png +0 -0
  172. package/src/modules/database/assets/SQLServer.png +0 -0
  173. package/src/modules/database/assets/database.svg +11 -0
  174. package/src/modules/database/assets/database_add.svg +53 -0
  175. package/src/modules/database/assets/database_connect.svg +66 -0
  176. package/src/modules/database/assets/database_upload.svg +29 -0
  177. package/src/modules/database/assets/empty.png +0 -0
  178. package/src/modules/database/assets/mysql.svg +14 -0
  179. package/src/modules/database/index.tsx +477 -0
  180. package/src/modules/database/server.ts +196 -0
  181. package/src/modules/databaseId/CustomCom.tsx +156 -0
  182. package/src/modules/databaseId/EditConfig.tsx +280 -0
  183. package/src/modules/databaseId/UploadDrawer.tsx +535 -0
  184. package/src/modules/databaseId/assets/aiOptimize.svg +10 -0
  185. package/src/modules/databaseId/assets/empty.png +0 -0
  186. package/src/modules/databaseId/assets/template.svg +6 -0
  187. package/src/modules/databaseId/assets/upload.svg +9 -0
  188. package/src/modules/databaseId/assets/useTemp.svg +6 -0
  189. package/src/modules/databaseId/index.tsx +769 -0
  190. package/src/modules/databaseId/server.ts +286 -0
  191. package/src/modules/databaseId/style.css +5 -0
  192. package/src/modules/databaseTable/EditRowDrawer.tsx +124 -0
  193. package/src/modules/databaseTable/index.tsx +359 -0
  194. package/src/modules/databaseTable/server.ts +180 -0
  195. package/src/modules/headlessChat/ReferenceBar.tsx +783 -0
  196. package/src/modules/headlessChat/constants.tsx +32 -0
  197. package/src/modules/headlessChat/index.tsx +1411 -0
  198. package/src/modules/headlessChat/referenceCom/DeleteModal.tsx +75 -0
  199. package/src/modules/headlessChat/referenceCom/DrawerContent.tsx +136 -0
  200. package/src/modules/headlessChat/referenceCom/DrawerDatabase.tsx +102 -0
  201. package/src/modules/headlessChat/referenceCom/DrawerGraphPreview.tsx +86 -0
  202. package/src/modules/headlessChat/referenceCom/DrawerPreview.tsx +73 -0
  203. package/src/modules/headlessChat/referenceCom/DrawerTitle.tsx +26 -0
  204. package/src/modules/headlessChat/referenceCom/RenameModal.tsx +86 -0
  205. package/src/modules/headlessChat/referenceCom/TagCom.tsx +30 -0
  206. package/src/modules/headlessChat/style.less +3 -0
  207. package/src/modules/headlessChat/types.ts +23 -0
  208. package/src/modules/headlessChat/utils/index.ts +348 -0
  209. package/src/modules/login/components/Login/LoginBox/index.tsx +102 -0
  210. package/src/modules/login/components/Login/RegisterBox/index.tsx +180 -0
  211. package/src/modules/login/components/Login/index.tsx +100 -0
  212. package/src/modules/login/index.tsx +106 -0
  213. package/src/modules/login/style.css +3 -0
  214. package/src/modules/login/useServices.ts +53 -0
  215. package/src/modules/login/utils.ts +42 -0
  216. package/src/modules/modelManage/ConfigDrawer.tsx +249 -0
  217. package/src/modules/modelManage/ReplaceModal.tsx +124 -0
  218. package/src/modules/modelManage/assets/empty.png +0 -0
  219. package/src/modules/modelManage/const.ts +51 -0
  220. package/src/modules/modelManage/index.tsx +599 -0
  221. package/src/modules/modelManage/server.ts +223 -0
  222. package/src/modules/nodegraph/index.tsx +1 -0
  223. package/src/modules/search/assets/Icon-history.svg +8 -0
  224. package/src/modules/search/assets/answerAwartar.png +0 -0
  225. package/src/modules/search/assets/doc.png +0 -0
  226. package/src/modules/search/assets/genera.gif +0 -0
  227. package/src/modules/search/assets/icon-robot.svg +9 -0
  228. package/src/modules/search/assets/icon-search-bar.svg +14 -0
  229. package/src/modules/search/assets/icon-sub-title.svg +3 -0
  230. package/src/modules/search/assets/icon-title.svg +9 -0
  231. package/src/modules/search/assets/icon-zoomOut.svg +9 -0
  232. package/src/modules/search/assets/iconAi.svg +9 -0
  233. package/src/modules/search/assets/pdf.png +0 -0
  234. package/src/modules/search/assets/ppt.png +0 -0
  235. package/src/modules/search/assets/search.svg +3 -0
  236. package/src/modules/search/assets/selected.svg +4 -0
  237. package/src/modules/search/assets/txt.png +0 -0
  238. package/src/modules/search/assets/xls.png +0 -0
  239. package/src/modules/search/components/AssisSelect.tsx +137 -0
  240. package/src/modules/search/components/Editor/ChatViewEditor.tsx +261 -0
  241. package/src/modules/search/components/Editor/aichat.css +1 -0
  242. package/src/modules/search/components/Editor/constant.ts +13 -0
  243. package/src/modules/search/components/Editor/index.tsx +113 -0
  244. package/src/modules/search/components/Editor/plugins/autofomatRules.ts +332 -0
  245. package/src/modules/search/components/Editor/plugins/convertImgPlugins.tsx +20 -0
  246. package/src/modules/search/components/Editor/plugins/createIndexes.tsx +38 -0
  247. package/src/modules/search/components/Editor/plugins/displayer.ts +298 -0
  248. package/src/modules/search/components/Editor/plugins/imageClick.tsx +32 -0
  249. package/src/modules/search/components/Editor/plugins/myplugin.tsx +98 -0
  250. package/src/modules/search/components/Editor/ui/avatar.tsx +19 -0
  251. package/src/modules/search/components/Editor/ui/blockquote-element.tsx +21 -0
  252. package/src/modules/search/components/Editor/ui/button.tsx +58 -0
  253. package/src/modules/search/components/Editor/ui/calendar.tsx +68 -0
  254. package/src/modules/search/components/Editor/ui/caption.tsx +46 -0
  255. package/src/modules/search/components/Editor/ui/checkbox.tsx +27 -0
  256. package/src/modules/search/components/Editor/ui/code-block-combobox.tsx +188 -0
  257. package/src/modules/search/components/Editor/ui/code-block-element.css +434 -0
  258. package/src/modules/search/components/Editor/ui/code-block-element.tsx +39 -0
  259. package/src/modules/search/components/Editor/ui/code-leaf.tsx +24 -0
  260. package/src/modules/search/components/Editor/ui/code-line-element.tsx +10 -0
  261. package/src/modules/search/components/Editor/ui/code-syntax-leaf.tsx +21 -0
  262. package/src/modules/search/components/Editor/ui/column-element.tsx +30 -0
  263. package/src/modules/search/components/Editor/ui/column-group-element.tsx +94 -0
  264. package/src/modules/search/components/Editor/ui/command.tsx +75 -0
  265. package/src/modules/search/components/Editor/ui/comment-avatar.tsx +22 -0
  266. package/src/modules/search/components/Editor/ui/comment-create-form.tsx +37 -0
  267. package/src/modules/search/components/Editor/ui/comment-item.tsx +74 -0
  268. package/src/modules/search/components/Editor/ui/comment-leaf.tsx +49 -0
  269. package/src/modules/search/components/Editor/ui/comment-more-dropdown.tsx +42 -0
  270. package/src/modules/search/components/Editor/ui/comment-reply-items.tsx +22 -0
  271. package/src/modules/search/components/Editor/ui/comment-resolve-button.tsx +32 -0
  272. package/src/modules/search/components/Editor/ui/comment-value.tsx +34 -0
  273. package/src/modules/search/components/Editor/ui/comments-popover.tsx +63 -0
  274. package/src/modules/search/components/Editor/ui/date-element.tsx +83 -0
  275. package/src/modules/search/components/Editor/ui/dialog.tsx +63 -0
  276. package/src/modules/search/components/Editor/ui/draggable.tsx +177 -0
  277. package/src/modules/search/components/Editor/ui/dropdown-menu.tsx +180 -0
  278. package/src/modules/search/components/Editor/ui/emoji-input-element.tsx +85 -0
  279. package/src/modules/search/components/Editor/ui/excalidraw-element.tsx +28 -0
  280. package/src/modules/search/components/Editor/ui/fixed-toolbar-buttons.tsx +76 -0
  281. package/src/modules/search/components/Editor/ui/fixed-toolbar.tsx +8 -0
  282. package/src/modules/search/components/Editor/ui/floating-toolbar-buttons.tsx +51 -0
  283. package/src/modules/search/components/Editor/ui/floating-toolbar.tsx +77 -0
  284. package/src/modules/search/components/Editor/ui/heading-element.tsx +48 -0
  285. package/src/modules/search/components/Editor/ui/highlight-leaf.tsx +17 -0
  286. package/src/modules/search/components/Editor/ui/hr-element.tsx +30 -0
  287. package/src/modules/search/components/Editor/ui/icons.tsx +267 -0
  288. package/src/modules/search/components/Editor/ui/image-element.tsx +74 -0
  289. package/src/modules/search/components/Editor/ui/inline-combobox.tsx +368 -0
  290. package/src/modules/search/components/Editor/ui/input.tsx +25 -0
  291. package/src/modules/search/components/Editor/ui/insert-dropdown-menu.tsx +218 -0
  292. package/src/modules/search/components/Editor/ui/kbd-leaf.tsx +20 -0
  293. package/src/modules/search/components/Editor/ui/link-element.tsx +29 -0
  294. package/src/modules/search/components/Editor/ui/link-floating-toolbar.tsx +161 -0
  295. package/src/modules/search/components/Editor/ui/list-element.tsx +30 -0
  296. package/src/modules/search/components/Editor/ui/mark-toolbar-button.tsx +24 -0
  297. package/src/modules/search/components/Editor/ui/media-embed-element.tsx +133 -0
  298. package/src/modules/search/components/Editor/ui/media-popover.tsx +97 -0
  299. package/src/modules/search/components/Editor/ui/mention-element.tsx +43 -0
  300. package/src/modules/search/components/Editor/ui/mention-input-element.tsx +141 -0
  301. package/src/modules/search/components/Editor/ui/mode-dropdown-menu.tsx +93 -0
  302. package/src/modules/search/components/Editor/ui/more-dropdown-menu.tsx +67 -0
  303. package/src/modules/search/components/Editor/ui/paragraph-element.tsx +4 -0
  304. package/src/modules/search/components/Editor/ui/placeholder.tsx +52 -0
  305. package/src/modules/search/components/Editor/ui/popover.tsx +32 -0
  306. package/src/modules/search/components/Editor/ui/resizable.tsx +66 -0
  307. package/src/modules/search/components/Editor/ui/separator.tsx +25 -0
  308. package/src/modules/search/components/Editor/ui/style.less +12 -0
  309. package/src/modules/search/components/Editor/ui/table-cell-element.tsx +143 -0
  310. package/src/modules/search/components/Editor/ui/table-element.tsx +243 -0
  311. package/src/modules/search/components/Editor/ui/table-row-element.tsx +22 -0
  312. package/src/modules/search/components/Editor/ui/tableValue.tsx +135 -0
  313. package/src/modules/search/components/Editor/ui/todo-list-element.tsx +43 -0
  314. package/src/modules/search/components/Editor/ui/toggle-element.tsx +31 -0
  315. package/src/modules/search/components/Editor/ui/toolbar.tsx +157 -0
  316. package/src/modules/search/components/Editor/ui/tooltip.tsx +65 -0
  317. package/src/modules/search/components/Editor/ui/turn-into-dropdown-menu.tsx +160 -0
  318. package/src/modules/search/components/Editor/ui/with-draggables.tsx +175 -0
  319. package/src/modules/search/components/FileList.tsx +287 -0
  320. package/src/modules/search/components/ImageGroupView/index.tsx +85 -0
  321. package/src/modules/search/components/ResultContent.tsx +232 -0
  322. package/src/modules/search/components/SearchInput.tsx +232 -0
  323. package/src/modules/search/components/SearchLanding.tsx +74 -0
  324. package/src/modules/search/components/SearchView.tsx +563 -0
  325. package/src/modules/search/components/SimpleEditor.tsx +158 -0
  326. package/src/modules/search/components/SimpleFileList.tsx +215 -0
  327. package/src/modules/search/index.tsx +10 -0
  328. package/src/modules/search/reademe.md +1 -0
  329. package/src/modules/search/servers/apis.tsx +19 -0
  330. package/src/modules/search/servers/index.ts +184 -0
  331. package/src/modules/search/style.less +503 -0
  332. package/src/modules/search/type.ts +22 -0
  333. package/src/modules/search/utils.ts +34 -0
  334. package/src/modules/sensitive/index.tsx +313 -0
  335. package/src/modules/sensitive/server.ts +122 -0
  336. package/src/modules/streamFilesReader/GientechStreamReader.tsx +1625 -0
  337. package/src/modules/streamFilesReader/components/Header/Toolbar.tsx +0 -0
  338. package/src/modules/streamFilesReader/components/Header/index.tsx +297 -0
  339. package/src/modules/streamFilesReader/index.tsx +3 -0
  340. package/src/style.css +6 -0
  341. package/src/type.d.ts +0 -0
  342. package/src/utils/commonFn.tsx +111 -0
  343. package/src/utils/decryptApiKey.ts +40 -0
  344. package/src/utils/gientechCommon/components/AppError.tsx +32 -0
  345. package/src/utils/gientechCommon/components/AppLoading.tsx +75 -0
  346. package/src/utils/gientechCommon/components/DeleteModal.tsx +75 -0
  347. package/src/utils/gientechCommon/components/DisplayError.tsx +33 -0
  348. package/src/utils/gientechCommon/components/DisplayLoading.tsx +38 -0
  349. package/src/utils/gientechCommon/components/FeedBackModal.tsx +318 -0
  350. package/src/utils/gientechCommon/components/FileCardCommon.tsx +82 -0
  351. package/src/utils/gientechCommon/components/FileManager/index.tsx +390 -0
  352. package/src/utils/gientechCommon/components/FileManager/style.css +5 -0
  353. package/src/utils/gientechCommon/components/Messages/GientechNewChatWelcome.tsx +581 -0
  354. package/src/utils/gientechCommon/components/Messages/ReferenceCard.tsx +339 -0
  355. package/src/utils/gientechCommon/components/Messages/RetriveItem.tsx +245 -0
  356. package/src/utils/gientechCommon/components/Messages/WebRetriveItem.tsx +209 -0
  357. package/src/utils/gientechCommon/components/Messages/defaultBot.png +0 -0
  358. package/src/utils/gientechCommon/components/Messages/defaultStyleSet.tsx +148 -0
  359. package/src/utils/gientechCommon/components/Messages/defaultWeLogo.svg +14 -0
  360. package/src/utils/gientechCommon/components/RenameModal.tsx +86 -0
  361. package/src/utils/gientechCommon/components/style.less +11 -0
  362. package/src/utils/gientechCommon/configs/commonConfig.ts +2 -0
  363. package/src/utils/gientechCommon/configs/senderConfig.ts +0 -0
  364. package/src/utils/gientechCommon/configs/stylesConfig.ts +142 -0
  365. package/src/utils/gientechCommon/hooks/AichatUseController.tsx +417 -0
  366. package/src/utils/gientechCommon/slate/converters/deserializers.ts +763 -0
  367. package/src/utils/gientechCommon/slate/converters/mockData.ts +232 -0
  368. package/src/utils/gientechCommon/slate/converters/slateConverters.ts +258 -0
  369. package/src/utils/gientechCommon/slate/richElements/index.tsx +499 -0
  370. package/src/utils/gientechCommon/utils/request.ts +37 -0
  371. package/src/utils/gientechCommon/utils/serverFn.ts +172 -0
  372. package/src/utils/index.tsx +132 -0
  373. package/src/utils/testconfigs/demologin/index.tsx +32 -0
  374. package/src/utils/testconfigs/index.ts +59 -0
  375. package/src/vite-env.d.ts +11 -0
  376. package/stats.html +4949 -0
  377. package/tailwind.config.js +170 -0
  378. package/tsconfig.app.json +30 -0
  379. package/tsconfig.app.tsbuildinfo +11 -0
  380. package/tsconfig.json +13 -0
  381. package/tsconfig.node.json +22 -0
  382. package/tsconfig.node.tsbuildinfo +1 -0
  383. package/vite.config.app.ts +93 -0
  384. package/vite.config.ts +231 -0
  385. package/workflows/release.yml +60 -0
  386. package//346/215/242/350/241/214/346/240/274/345/274/217/344/277/235/346/214/201/344/274/230/345/214/226/346/226/271/346/241/210.md +359 -0
  387. package/assets/GientechStreamReader-DqJjNXCO.js +0 -449
  388. package/assets/index-BO-w4FPz.js +0 -1088
  389. package/assets/style.css +0 -1
  390. package/assets/style4.css +0 -1
  391. package/assistantConfig.js +0 -1
  392. package/chat.js +0 -829
  393. package/databaseId.js +0 -1
  394. package/index.js +0 -1
  395. package/modelManage.js +0 -1
  396. package/streamFilesReader.js +0 -1
  397. /package/{assets → dist/assets}/Doris.png +0 -0
  398. /package/{assets → dist/assets}/PostgreSQL.png +0 -0
  399. /package/{assets → dist/assets}/SQLServer.png +0 -0
  400. /package/{assets → dist/assets}/database.svg +0 -0
  401. /package/{assets → dist/assets}/database_add.svg +0 -0
  402. /package/{assets → dist/assets}/database_connect.svg +0 -0
  403. /package/{assets → dist/assets}/database_upload.svg +0 -0
  404. /package/{assets → dist/assets}/databse.svg +0 -0
  405. /package/{assets → dist/assets}/defaultWeLogo.svg +0 -0
  406. /package/{assets → dist/assets}/empty.png +0 -0
  407. /package/{assets → dist/assets}/graph.svg +0 -0
  408. /package/{assets → dist/assets}/homeBg.png +0 -0
  409. /package/{assets → dist/assets}/index-CpW6Dhpp.js +0 -0
  410. /package/{assets → dist/assets}/knowledge.svg +0 -0
  411. /package/{assets → dist/assets}/left.jpg +0 -0
  412. /package/{assets → dist/assets}/logoImg.png +0 -0
  413. /package/{assets/MySQL.svg → dist/assets/mysql.svg} +0 -0
  414. /package/{assets → dist/assets}/sensitive.svg +0 -0
  415. /package/{assets → dist/assets}/style2.css +0 -0
  416. /package/{assets → dist/assets}/style3.css +0 -0
  417. /package/{assets → dist/assets}/worker-BbpylX7l.js +0 -0
  418. /package/{assistantConfig.d.ts → dist/assistantConfig.d.ts} +0 -0
  419. /package/{chat.d.ts → dist/chat.d.ts} +0 -0
  420. /package/{database.d.ts → dist/database.d.ts} +0 -0
  421. /package/{databaseId.d.ts → dist/databaseId.d.ts} +0 -0
  422. /package/{databaseTable.d.ts → dist/databaseTable.d.ts} +0 -0
  423. /package/{icons → dist/icons}/answerAwartar.png +0 -0
  424. /package/{icons → dist/icons}/docx-file.png +0 -0
  425. /package/{icons → dist/icons}/folder.png +0 -0
  426. /package/{icons → dist/icons}/html.png +0 -0
  427. /package/{icons → dist/icons}/image.png +0 -0
  428. /package/{icons → dist/icons}/jpg-file.png +0 -0
  429. /package/{icons → dist/icons}/json.png +0 -0
  430. /package/{icons → dist/icons}/md.png +0 -0
  431. /package/{icons → dist/icons}/pdf.png +0 -0
  432. /package/{icons → dist/icons}/pptx.png +0 -0
  433. /package/{icons → dist/icons}/questionAwartar.png +0 -0
  434. /package/{icons → dist/icons}/sheets.png +0 -0
  435. /package/{icons → dist/icons}/txt.png +0 -0
  436. /package/{icons → dist/icons}/xlsx.png +0 -0
  437. /package/{index.d.ts → dist/index.d.ts} +0 -0
  438. /package/{modelManage.d.ts → dist/modelManage.d.ts} +0 -0
  439. /package/{sensitive.d.ts → dist/sensitive.d.ts} +0 -0
  440. /package/{streamFilesReader.d.ts → dist/streamFilesReader.d.ts} +0 -0
  441. /package/{vite.svg → dist/vite.svg} +0 -0
  442. /package/{worker → dist/worker}/pdf.worker.min.js +0 -0
@@ -0,0 +1,1411 @@
1
+ import React, { useEffect, useState, useMemo, useRef } from 'react';
2
+ import { AiChat, AppStatusManager } from '@mxmweb/aichat';
3
+ import { ChatMessageAdapter } from '@mxmweb/rtext';
4
+ import request from '../../utils/gientechCommon/utils/request';
5
+ import { registerPDFWorker } from '../streamFilesReader';
6
+ registerPDFWorker('/worker/pdf.worker.min.js');
7
+ import {
8
+ getFeedbackList,
9
+ handleCancelFeedBack,
10
+ handleFeedBack,
11
+ removeFilefromTempUpload,
12
+ } from '../../utils/gientechCommon/utils/serverFn';
13
+ import { getFileTypeByName, toCopy } from '../../utils/commonFn';
14
+ import { uid } from 'uid';
15
+ import GientechNewChatWelcome from '../../utils/gientechCommon/components/Messages/GientechNewChatWelcome';
16
+ import AichatUseController from '../../utils/gientechCommon/hooks/AichatUseController';
17
+ import FeedBackModal from '../../utils/gientechCommon/components/FeedBackModal';
18
+ import { ConfigProvider, Drawer, message } from 'antd';
19
+ import FileManager from '../../utils/gientechCommon/components/FileManager';
20
+ import AppLoading from '../../utils/gientechCommon/components/AppLoading';
21
+ import DisplayLoading from '../../utils/gientechCommon/components/DisplayLoading';
22
+ import AppError from '../../utils/gientechCommon/components/AppError';
23
+ import DisplayError from '../../utils/gientechCommon/components/DisplayError';
24
+ import { DefaultSenderConfig } from './constants';
25
+ import { maxPollCount, maxPollInterval } from '../../utils/gientechCommon/configs/commonConfig';
26
+ import '@mxmweb/rtext/style.css';
27
+ import '@mxmweb/aichat/style.css';
28
+ import '@mxmweb/zui/style.css';
29
+ import { ReferenceBar } from './ReferenceBar';
30
+ import { DrawerType } from '../chat';
31
+ import { getMarkExcludeType, TempBaseUrl } from './utils';
32
+ import { DrawerContent } from './referenceCom/DrawerContent';
33
+
34
+ interface HeadlessChatAdopterProps {
35
+ token: string;
36
+ url?: string;
37
+ configId?: string;
38
+ useLogin?: boolean;
39
+ styles?: any;
40
+ welcomeContent?: string;
41
+ onError?: (ems: any) => void;
42
+ eventsEmit?: (eventName: string, data: any) => void;
43
+ [key: string]: any;
44
+ }
45
+
46
+ export default function withHeadLessChatAdopter(
47
+ WrappedComponent: React.ComponentType<any> = AiChat as any
48
+ ) {
49
+ /**
50
+ * GientechChatAdopter 高阶组件
51
+ * 封装了与Gientech后端服务的接口对接、状态管理、事件处理等核心业务逻辑
52
+ * @param {React.ComponentType} WrappedComponent - 需要包裹的基础聊天组件,默认为 AiChat
53
+ */
54
+ return function GientechChatAdopter({
55
+ token,
56
+ url = 'http://localhost:8888',
57
+ welcomeContent = '欢迎来到小鲸智能助手,有什么能帮你的么?',
58
+ styles,
59
+ eventsEmit,
60
+ onError,
61
+ configId,
62
+ ...rest
63
+ }: HeadlessChatAdopterProps) {
64
+ const [open, setOpen] = useState(false);
65
+ const [content, setContent] = useState<
66
+ | {
67
+ title: '';
68
+ file_type: '';
69
+ metadata: { offset: [] };
70
+ }
71
+ | any
72
+ >(null);
73
+ const [drawerType, setDrawerType] = useState<string>('mark');
74
+ const [curFileInfo, setCurFileInfo] = useState({
75
+ url: '',
76
+ parse_url: '',
77
+ file_type: '',
78
+ file_name: '',
79
+ });
80
+ // =================================================================
81
+ // State Management - 状态管理
82
+ // =================================================================
83
+ const [conversationList, setConversationList] = useState<any[]>([]); // 对话列表
84
+ const [chatData, setChatData] = useState<any[]>([]); // 所有对话的聊天记录
85
+ const [activeSessionId, setActiveSessionId] = useState<string | undefined>(undefined); // 当前激活的对话ID
86
+ const [recommandQuestions, setRecommandQuestions] = useState<any[]>([]); // 推荐问题列表
87
+ const [assistantList] = useState<any[]>([]); // 智能体(助手)列表
88
+ const [fileManagerOpen, setFileManagerOpen] = useState<boolean>(false); // 文件管理器抽屉的开关状态
89
+ const [appStatus, setAppStatus] = useState<AppStatusManager>({
90
+ display: 'ready', // 主聊天区域状态: ready, loading, processing, error, uploading
91
+ sender: 'ready', // 发送器状态: ready, processing, error, uploading
92
+ app: 'initializing', // 应用整体状态: initializing, ready, error
93
+ });
94
+ const [pendingFiles, setPendingFiles] = useState<any[]>([]); // 准备上传的文件列表
95
+ const [dynamicSenderConfig, setDynamicSenderConfig] = useState(DefaultSenderConfig); // 动态的发送器配置
96
+ const [fileStatuses, setFileStatuses] = useState<any[]>([]); // 用于跟踪每个上传文件的状态
97
+ const [fileManagerData, setFileManagerData] = useState<{ uploadedFiles: any[] }>({
98
+ uploadedFiles: [],
99
+ });
100
+
101
+ // 新增:记录 sender switchs 的选中状态
102
+ const [senderSwitchValues, setSenderSwitchValues] = useState<{ [key: string]: boolean }>({});
103
+
104
+ // =================================================================
105
+ // Refs - 引用
106
+ // =================================================================
107
+ const prevActiveSessionId = useRef<string | undefined>(undefined); // 记录上一个激活的对话ID,用于对比变化
108
+ const setUploadedFilesRef = useRef<(files: any[]) => void>(undefined); // 引用核心组件的文件上传方法
109
+ const removeFileRef = useRef<(fileObj: any, idx: number, _type: string) => void>(undefined); // 引用核心组件的文件移除方法
110
+
111
+ const [feedParam, setFeedParam] = useState<{
112
+ queryId?: number | string | undefined;
113
+ restult?: number;
114
+ }>({});
115
+ const [openFeed, setOpenFeed] = useState(false);
116
+ const [feedBackList, setFeedBackList] = useState<any>([]);
117
+ const stoppedRef = useRef(false);
118
+
119
+ // =================================================================
120
+ // Custom Hooks - 自定义钩子
121
+ // =================================================================
122
+ // 引入SSE控制器,封装了流式请求、消息管理等复杂逻辑
123
+ const { api_startChat_re, addEmptyMessage, setLastEmptyMessage, stopStream } =
124
+ AichatUseController({
125
+ baseUrl: url,
126
+ token,
127
+ setChatData,
128
+ activeSessionId,
129
+ setAppStatus,
130
+ setConversationList,
131
+ });
132
+
133
+ // =================================================================
134
+ // Memoized Values - 缓存计算值
135
+ // =================================================================
136
+
137
+ // welcomeContent 伪消息唯一 id/time/queryId
138
+ const welcomeMsgId = useRef(uid(32));
139
+ const welcomeMsgQueryId = useRef(uid(32));
140
+ const welcomeMsgTime = useRef(Date.now());
141
+
142
+ /**
143
+ * 将智能体列表转换为以ID为键的Map,便于快速查找
144
+ */
145
+ const assistantMap = useMemo(() => {
146
+ const map: Record<string, any> = {};
147
+ (assistantList || []).forEach(item => {
148
+ map[item.id] = item;
149
+ });
150
+ return map;
151
+ }, [assistantList]);
152
+
153
+ /**
154
+ * 根据 activeSessionId 从 chatData 中筛选出当前对话的数据, 并合并智能体信息
155
+ */
156
+ const currentChatData = useMemo(() => {
157
+ let data = chatData.find((c: any) => c.id === activeSessionId) || {
158
+ id: activeSessionId,
159
+ messages: [],
160
+ };
161
+ let messages = data.messages || [];
162
+ // 检查第一条是否已经是 welcome 消息,如果不是则插入
163
+ if (welcomeContent && (messages.length === 0 || !messages[0]?.isDefault)) {
164
+ messages = [
165
+ {
166
+ istype: 'ai',
167
+ content: welcomeContent,
168
+ time: welcomeMsgTime.current,
169
+ clientSideId: welcomeMsgId.current,
170
+ isWelcome: true,
171
+ isDefault: true,
172
+ queryId: welcomeMsgQueryId.current,
173
+ },
174
+ ...messages,
175
+ ];
176
+ }
177
+ // 如果第一条已经是 isDefault: true 的欢迎消息,确保它的 isWelcome 字段存在
178
+ if (messages[0]?.isDefault && !messages[0]?.isWelcome) {
179
+ messages[0].isWelcome = true;
180
+ }
181
+ const assistantInfo = data.configId ? assistantMap[data.configId] : null;
182
+ return {
183
+ ...data,
184
+ messages,
185
+ assistantInfo,
186
+ };
187
+ }, [chatData, activeSessionId, assistantMap, welcomeContent]);
188
+
189
+ // 合并文件工具,避免重复,且保证每个文件有 file 字段
190
+ function mergeFiles(oldFiles: any[], newFiles: any[]) {
191
+ const map = new Map();
192
+ oldFiles.forEach(f => map.set(f.uid, normalizeFileItem(f)));
193
+ newFiles.forEach(f => map.set(f.uid, normalizeFileItem(f)));
194
+ return Array.from(map.values());
195
+ }
196
+
197
+ // 文件结构标准化,保证有 file 字段
198
+ function normalizeFileItem(f: any) {
199
+ if (!f) return f;
200
+ if (f.file && f.file.name) return f;
201
+ // 兼容后端返回的扁平对象,优先 name,其次 fileName
202
+ const name = f.name || f.fileName || '';
203
+ return {
204
+ ...f,
205
+ url: f.filePath || '',
206
+ uid: f.uid || '',
207
+ file: {
208
+ name,
209
+ size:
210
+ typeof f.size === 'string' && f.size.endsWith('MB')
211
+ ? Number(f.size.replace('MB', '')) * 1024 * 1024
212
+ : f.size || 0,
213
+ type: f.type || '',
214
+ },
215
+ name, // 兜底 name 字段,供 UI 使用
216
+ };
217
+ }
218
+
219
+ /**
220
+ * 用 useEffect 监听 currentChatData 自动同步
221
+ */
222
+ useEffect(() => {
223
+ if (!activeSessionId) return;
224
+ const conv = chatData.find((c: any) => c.id === activeSessionId);
225
+ let uploaded: any[] = [];
226
+ let hasReference = false;
227
+ if (conv && conv.messages) {
228
+ const lastAiMsg = [...(conv.messages || [])]
229
+ .reverse()
230
+ .find((msg: any) => msg.istype === 'ai');
231
+ if (lastAiMsg?.reference && lastAiMsg.resultType === 5) {
232
+ hasReference = true;
233
+ try {
234
+ const fileList = JSON.parse(lastAiMsg.reference);
235
+ uploaded = fileList.map((f: any) => normalizeFileItem(f));
236
+ } catch (e) {}
237
+ }
238
+ }
239
+ if (hasReference) {
240
+ setFileManagerData({ uploadedFiles: uploaded });
241
+ }
242
+ // 否则不动,保持原有 uploadedFiles
243
+ }, [chatData]);
244
+
245
+ useEffect(() => {
246
+ setFileManagerData({ uploadedFiles: [] });
247
+ }, [activeSessionId]);
248
+
249
+ // =================================================================
250
+ // Side Effects (useEffect) - 副作用钩子
251
+ // =================================================================
252
+
253
+ /**
254
+ * 跟踪 activeSessionId 的变化:
255
+ * 1. 清理上一个无消息的临时会话
256
+ * 2. 更新推荐问题
257
+ */
258
+ useEffect(() => {
259
+ // 切换会话时,检查上一个会话是否为临时且无消息
260
+ if (prevActiveSessionId.current && prevActiveSessionId.current !== activeSessionId) {
261
+ const prevId = prevActiveSessionId.current;
262
+ const prevConv = conversationList.find(c => c.sessionId === prevId && c.isNew);
263
+ const prevChat = chatData.find(c => c.id === prevId && c.isNew);
264
+ const prevHasMsg = prevChat && prevChat.messages && prevChat.messages.length > 0;
265
+ // 如果是临时的且没有消息,则自动删除
266
+ if (prevConv && !prevHasMsg) {
267
+ setConversationList(list => list.filter(c => c.sessionId !== prevId));
268
+ setChatData(list => list.filter(c => c.id !== prevId));
269
+ }
270
+ }
271
+ prevActiveSessionId.current = activeSessionId;
272
+
273
+ // 更新推荐问题为当前对话的最后一个推荐问题
274
+ const historyRQ =
275
+ currentChatData.messages && currentChatData.messages.length > 0
276
+ ? currentChatData.messages[currentChatData.messages.length - 1].recommendQuestion
277
+ : [];
278
+ setRecommandQuestions(historyRQ);
279
+ }, [activeSessionId, conversationList, chatData, currentChatData.messages]);
280
+
281
+ /**
282
+ * 1. useEffect 只拉助手列表,自动新建会话
283
+ */
284
+ useEffect(() => {
285
+ setAppStatus(prev => ({ ...prev, app: 'initializing' }));
286
+
287
+ if (token) {
288
+ handleConversationCreate({ configId });
289
+ }
290
+ setAppStatus(prev => ({ ...prev, app: 'ready' }));
291
+ }, [url, token, configId]);
292
+
293
+ /**
294
+ * 当 activeSessionId 变化时,获取对应的聊天记录
295
+ */
296
+ useEffect(() => {
297
+ if (!activeSessionId) return;
298
+ setAppStatus(prev => ({ ...prev, display: 'loading' }));
299
+
300
+ setAppStatus(prev => ({ ...prev, display: 'ready' }));
301
+ }, [activeSessionId, url, token]);
302
+
303
+ /**
304
+ * 监听文件数据变化,更新Sender上的角标
305
+ */
306
+ useEffect(() => {
307
+ const totalFiles = fileManagerData.uploadedFiles.length;
308
+ setDynamicSenderConfig(prev => {
309
+ const newConfig = {
310
+ ...prev,
311
+ actions: prev.actions.map(action =>
312
+ action.name === 'history' ? { ...action, badgeCount: totalFiles } : action
313
+ ),
314
+ };
315
+ return newConfig;
316
+ });
317
+ }, [fileManagerData.uploadedFiles]);
318
+ useEffect(() => {
319
+ getFeedbackList({ url, token }, data => {
320
+ setFeedBackList(data);
321
+ });
322
+ }, []);
323
+ // =================================================================
324
+ // Core Functions - 核心功能函数
325
+ // =================================================================
326
+
327
+ // 1. 在组件作用域定义控制器和轮询停止标志
328
+ let uploadController: AbortController | null = null;
329
+ let stopPoll: (() => void) | null = null;
330
+
331
+ /**
332
+ * 轮询文件解析状态
333
+ * @param {string[]} uids - 文件UID列表
334
+ * @param {(serverStatuses: any[]) => void} onStatusUpdate - 每次获取到新状态后的回调
335
+ * @param {() => void} onComplete - 所有文件解析完成后的回调
336
+ * @param {(errorMsg: string) => void} onFail - 轮询失败或超时的回调
337
+ */
338
+ const pollFileStatus = (
339
+ uids: string[],
340
+ onStatusUpdate: (serverStatuses: any[]) => void,
341
+ onComplete: () => void,
342
+ onFail: (errorMsg: string) => void
343
+ ) => {
344
+ const uidsString = uids.join(',');
345
+ let pollCount = 0;
346
+ //const maxPollCount = maxPollCount;
347
+ stopPoll = () => {
348
+ stoppedRef.current = true;
349
+ };
350
+
351
+ const checkStatus = async () => {
352
+ if (stoppedRef.current) return;
353
+ if (pollCount >= maxPollCount) {
354
+ if (!stoppedRef.current) onFail('文件解析超时,请稍后重试');
355
+ return;
356
+ }
357
+ pollCount++;
358
+ try {
359
+ const res = await request.get(
360
+ `${url}/index/knowledgeBase/file/getFileStatusByUids?uids=${uidsString}`,
361
+ {
362
+ headers: { Authorization: token },
363
+ }
364
+ );
365
+ if (stoppedRef.current) return;
366
+ if (res.data.success) {
367
+ const statuses = res.data.data;
368
+ if (!stoppedRef.current) onStatusUpdate(statuses);
369
+ const allDone = statuses.every((file: any) => file.status === 3);
370
+ if (allDone) {
371
+ if (!stoppedRef.current) onComplete();
372
+ } else {
373
+ if (!stoppedRef.current) setTimeout(checkStatus, maxPollInterval);
374
+ }
375
+ } else {
376
+ if (!stoppedRef.current) onFail(res.data.errorMsg || '查询文件状态失败');
377
+ }
378
+ } catch (error) {
379
+ onError?.(error);
380
+ if (stoppedRef.current) return;
381
+ onFail('查询文件状态时发生网络错误');
382
+ }
383
+ };
384
+ checkStatus();
385
+ };
386
+
387
+ /**
388
+ * 设置消息的反馈结果(赞/踩)
389
+ * @param {string} queryId - 消息ID
390
+ * @param {number} result - 反馈结果 (1: 赞, -1: 踩)
391
+ */
392
+ const setFeed = (queryId: any, restult: any) => {
393
+ setChatData(chatList => {
394
+ const newList = [...chatList];
395
+ if (!newList[0]) return newList;
396
+ newList[0] = {
397
+ ...newList[0],
398
+ messages: newList[0].messages.map((item: any) => {
399
+ if (item.queryId === queryId) {
400
+ return {
401
+ ...item,
402
+ feedbackResult: restult,
403
+ };
404
+ }
405
+ return item;
406
+ }),
407
+ };
408
+ return newList;
409
+ });
410
+ };
411
+
412
+ /**
413
+ * 获取指定queryId的推荐问题
414
+ * @param {string} queryId - 消息ID
415
+ */
416
+ const fetchRecommendQuestions = async (queryId: string) => {
417
+ if (!queryId) return;
418
+ try {
419
+ const res = await request.get(`${url}/qa/ai/recommendQuestion?queryId=${queryId}`, {
420
+ headers: { Authorization: token },
421
+ });
422
+ setRecommandQuestions(res.data?.data || []);
423
+ } catch (e) {
424
+ onError?.(e);
425
+ setRecommandQuestions([]);
426
+ }
427
+ };
428
+
429
+ /**
430
+ * 处理重新发送消息逻辑
431
+ */
432
+ function handleReSenderSend(data: any) {
433
+ const { content, audioUrl, filePaths, queryId } = data;
434
+ if (!content) return;
435
+ const _fileUids = (
436
+ typeof filePaths === 'string' && filePaths ? JSON.parse(filePaths) : filePaths || []
437
+ ).map((item: any) => item.uid);
438
+ const now = Date.now();
439
+ setLastEmptyMessage({ now });
440
+ if (!activeSessionId) return;
441
+ setAppStatus(pre => {
442
+ return {
443
+ ...pre,
444
+ display: 'processing',
445
+ sender: 'processing',
446
+ };
447
+ });
448
+
449
+ data.clearFn && data.clearFn();
450
+ setConversationList(list =>
451
+ list.map(c => (c.sessionId === activeSessionId ? { ...c, gmtModified: now } : c))
452
+ );
453
+ api_startChat_re(
454
+ {
455
+ configId: configId || currentChatData.configId,
456
+ content,
457
+ fileUids: _fileUids,
458
+ lastDate: now,
459
+ name: currentChatData.label || '',
460
+ queryId: queryId,
461
+ sessionId: activeSessionId,
462
+ type: audioUrl ? 'audioUrl' : 'text',
463
+ audioUrl,
464
+ sysType: 'TEMPORARY',
465
+ enableThinking: !!senderSwitchValues.reasoning,
466
+ enableWebsearch: !!senderSwitchValues.netSearch,
467
+ qaChannel: senderSwitchValues.qaChannel,
468
+ } as any,
469
+ () => {
470
+ fetchRecommendQuestions(queryId);
471
+ }
472
+ );
473
+ }
474
+
475
+ /**
476
+ * 处理消息发送(核心逻辑)
477
+ * 1. 包含文件:先上传文件,成功后再发消息
478
+ * 2. 新建会话:先调用创建会话接口,成功后再发消息
479
+ * 3. 普通消息:直接发送
480
+ * @param {object} data - 消息数据
481
+ */
482
+ async function handleSenderSend(data: any, clearFn: () => void) {
483
+ const queryId = 'query-' + uid(32);
484
+ // 1. 立即插入空壳消息
485
+ let localCurrentFiles = undefined;
486
+ if (data.files && data.files.length > 0) {
487
+ localCurrentFiles = data.files.map((fileItem: any) => ({
488
+ name: fileItem.file.name,
489
+ size: fileItem.file.size,
490
+ type: fileItem.file.type,
491
+ filePath: fileItem.filePath || '',
492
+ convertedFilePath: fileItem.convertedFilePath || '',
493
+ uid: fileItem.uid || '',
494
+ }));
495
+ }
496
+ addEmptyMessage({
497
+ content: data.content || data.text || '',
498
+ queryId,
499
+ currentFiles: localCurrentFiles,
500
+ filePaths: localCurrentFiles ? JSON.stringify(localCurrentFiles) : undefined,
501
+ });
502
+ setConversationList(list => {
503
+ const newList = list
504
+ .map(c =>
505
+ c.sessionId === activeSessionId ? { ...c, isNew: false, gmtModified: Date.now() } : c
506
+ )
507
+ .sort((a, b) => b.gmtModified - a.gmtModified);
508
+ setTimeout(() => {
509
+ setActiveSessionId(activeSessionId);
510
+ }, 300);
511
+ return newList;
512
+ });
513
+ // 2. 有文件时,先上传并轮询,全部解析成功后再发起AI请求
514
+ if (data.files && data.files.length > 0) {
515
+ setAppStatus(pre => ({ ...pre, sender: 'uploading', display: 'uploading' }));
516
+ uploadController = new AbortController();
517
+ stoppedRef.current = false;
518
+ const clientFileUids = data.files.map(
519
+ () => `rc-upload-${Date.now()}-${Math.random().toString(36).slice(2)}`
520
+ );
521
+ const initialFileStatuses = data.files.map((fileItem: any, index: number) => ({
522
+ ...fileItem,
523
+ uid: clientFileUids[index],
524
+ status: 'uploading',
525
+ }));
526
+ setFileStatuses(initialFileStatuses);
527
+ const formData = new FormData();
528
+ data.files.forEach((fileItem: any) => {
529
+ formData.append('files', fileItem.file);
530
+ });
531
+ const sessionIdStr = activeSessionId ? String(activeSessionId) : '';
532
+ formData.append('sessionId', sessionIdStr);
533
+ formData.append('uids', clientFileUids.join(','));
534
+ try {
535
+ const response = await request.post(
536
+ `${url}/index/knowledgeBase/file/uploadFiles`,
537
+ formData,
538
+ {
539
+ headers: {
540
+ Authorization: token,
541
+ 'Content-Type': 'multipart/form-data',
542
+ },
543
+ signal: uploadController.signal,
544
+ }
545
+ );
546
+ if (stoppedRef.current) return;
547
+ if (
548
+ response.data.success &&
549
+ Array.isArray(response.data.data) &&
550
+ response.data.data.length > 0
551
+ ) {
552
+ // === 新增:合并后端返回字段到 fileStatuses ===
553
+ setFileStatuses(prev => {
554
+ return prev.map(localFile => {
555
+ const serverFile = response.data.data.find((f: any) => f.uid === localFile.uid);
556
+ return serverFile ? { ...localFile, ...serverFile } : localFile;
557
+ });
558
+ });
559
+ setAppStatus(pre => ({ ...pre, sender: 'processing', display: 'analyzing' }));
560
+ setFileStatuses(prev => prev.map(f => ({ ...f, status: 'parsing' })));
561
+ const uploadedFilesData = response.data.data;
562
+ const serverUids = uploadedFilesData.map((f: any) => f.uid);
563
+ pollFileStatus(
564
+ serverUids,
565
+ serverStatuses => {
566
+ setFileStatuses(currentLocalStatuses => {
567
+ return currentLocalStatuses.map(localFile => {
568
+ const correspondingServerFile = serverStatuses.find(
569
+ (sf: any) => sf.uid === localFile.uid
570
+ );
571
+ if (correspondingServerFile) {
572
+ switch (correspondingServerFile.status) {
573
+ case 3:
574
+ return { ...localFile, status: 'done' };
575
+ case 4:
576
+ return { ...localFile, status: 'error' };
577
+ case 1:
578
+ case 2:
579
+ default:
580
+ return { ...localFile, status: 'parsing' };
581
+ }
582
+ }
583
+ return localFile;
584
+ });
585
+ });
586
+ // === 新增:全部完成时清空 sender 区 ===
587
+ const allDone =
588
+ serverStatuses.length > 0 &&
589
+ serverStatuses.every((file: any) => file.status === 3);
590
+ if (allDone) {
591
+ setFileStatuses([]);
592
+ }
593
+ },
594
+ // onComplete: 全部解析成功后才发起AI请求
595
+ () => {
596
+ clearFn?.();
597
+ setAppStatus(pre => ({ ...pre, sender: 'processing', display: 'processing' }));
598
+ // === 新增:回填 filePath 到 fileStatuses ===
599
+ setFileStatuses(prev => {
600
+ return prev.map(localFile => {
601
+ const serverFile = uploadedFilesData.find((f: any) => f.uid === localFile.uid);
602
+
603
+ if (serverFile) {
604
+ return {
605
+ ...localFile,
606
+ ...serverFile, // 合并后端所有字段
607
+ url: serverFile.filePath, // 兼容 url 字段
608
+ filePath: serverFile.filePath,
609
+ name: serverFile.fileName || localFile.name,
610
+ convertedFilePath:
611
+ serverFile.convertedFilePath || localFile.convertedFilePath,
612
+ };
613
+ }
614
+ return localFile;
615
+ });
616
+ });
617
+ // === 同步 currentFiles 字段到 chatData ===
618
+ setChatData(chatList => {
619
+ if (!chatList[0]) return chatList;
620
+ const { messages } = chatList[0];
621
+ for (let i = messages.length - 1; i >= 0; i--) {
622
+ if (messages[i].istype === 'user') {
623
+ const oldFiles = messages[i].currentFiles || [];
624
+ messages[i].currentFiles = oldFiles.map((localFile: any) => {
625
+ const serverFile = uploadedFilesData.find(
626
+ (f: any) => f.uid === localFile.uid
627
+ );
628
+ return serverFile ? { ...localFile, ...serverFile } : localFile;
629
+ });
630
+ break;
631
+ }
632
+ }
633
+ return [...chatList];
634
+ });
635
+ // === 全部完成时清空 sender 区并合并文件 ===
636
+ setFileStatuses([]);
637
+ // 上传完成后合并新文件到 uploadedFiles,保证结构统一
638
+ const map = new Map();
639
+ (uploadedFilesData || []).forEach((item: any) => {
640
+ map.set(item.id, item);
641
+ });
642
+ setFileManagerData(prev => {
643
+ const r = mergeFiles(prev.uploadedFiles, uploadedFilesData);
644
+
645
+ return {
646
+ uploadedFiles: r.map(item => {
647
+ return {
648
+ ...item,
649
+ pdfPages: map.get(item.id)?.pdfPages || 0, // 保留后端返回的 pdfPages 字段
650
+ };
651
+ }),
652
+ };
653
+ });
654
+ const now = Date.now();
655
+ api_startChat_re(
656
+ {
657
+ configId: configId || currentChatData.configId,
658
+ content: data.content || data.text || '',
659
+ fileUids: serverUids,
660
+ lastDate: now,
661
+ name: currentChatData.label || '',
662
+ queryId: queryId,
663
+ sessionId: String(activeSessionId || ''),
664
+ type: 'text',
665
+ audioUrl: '',
666
+ sysType: 'TEMPORARY',
667
+ enableThinking: !!senderSwitchValues.reasoning,
668
+ enableWebsearch: !!senderSwitchValues.netSearch,
669
+ qaChannel: senderSwitchValues.qaChannel,
670
+ } as any,
671
+ () => {
672
+ fetchRecommendQuestions(queryId);
673
+ }
674
+ );
675
+ },
676
+ (errorMsg: string) => {
677
+ setAppStatus(pre => ({ ...pre, display: 'ready', sender: 'ready' }));
678
+ setFileStatuses(prev =>
679
+ prev.map(f => ({ ...f, status: 'error', message: errorMsg }))
680
+ );
681
+ }
682
+ );
683
+ } else {
684
+ const errorMsg = response.data.errorMsg || '文件上传失败';
685
+ setAppStatus(pre => ({ ...pre, display: 'error', sender: 'ready' }));
686
+ setFileStatuses(prev => prev.map(f => ({ ...f, status: 'error', message: errorMsg })));
687
+ }
688
+ } catch (error) {
689
+ setAppStatus(pre => ({ ...pre, display: 'error', sender: 'ready' }));
690
+ setFileStatuses(prev => prev.map(f => ({ ...f, status: 'error', message: '网络错误' })));
691
+ }
692
+ return;
693
+ }
694
+ // 3. 无文件,直接发起AI请求
695
+ if (!activeSessionId) return;
696
+ setAppStatus(pre => ({ ...pre, display: 'processing', sender: 'processing' }));
697
+ const now = Date.now();
698
+ setConversationList(list =>
699
+ list.map(c => (c.sessionId === activeSessionId ? { ...c, gmtModified: now } : c))
700
+ );
701
+ clearFn?.();
702
+ api_startChat_re(
703
+ {
704
+ configId: configId || currentChatData.configId,
705
+ content: data.content || data.text || '',
706
+ fileUids: [],
707
+ lastDate: now,
708
+ name: currentChatData.label || '',
709
+ queryId: queryId,
710
+ sessionId: activeSessionId,
711
+ type: 'text',
712
+ audioUrl: '',
713
+ sysType: 'TEMPORARY',
714
+ enableThinking: !!senderSwitchValues.reasoning,
715
+ enableWebsearch: !!senderSwitchValues.netSearch,
716
+ qaChannel: senderSwitchValues.qaChannel,
717
+ } as any,
718
+ () => {
719
+ fetchRecommendQuestions(queryId);
720
+ }
721
+ );
722
+ }
723
+
724
+ // =================================================================
725
+ // Event Handlers - 事件处理器
726
+ // =================================================================
727
+
728
+ /**
729
+ * 处理点赞反馈
730
+ */
731
+ function handleThumbsup(data: any) {
732
+ if (data.restult == 1) {
733
+ handleCancelFeedBack({ url, token }, { queryId: data.queryId }, () => {
734
+ setFeed(data.queryId, null);
735
+ });
736
+ } else {
737
+ handleFeedBack({ url, token }, { restult: 1, queryId: data.queryId }, () => {
738
+ setFeed(data.queryId, 1);
739
+ });
740
+ }
741
+ }
742
+
743
+ /**
744
+ * 处理新建一个临时会话
745
+ */
746
+ function handleConversationCreate(data: any) {
747
+ const sessionId = uid(32);
748
+ // 优先用 props.configId
749
+ const effectiveConfigId = configId || data?.configId || '';
750
+ const newConversation = {
751
+ sessionId,
752
+ label: '未命名会话',
753
+ gmtModified: Date.now(),
754
+ searchConfigDTO: {},
755
+ filePath: '',
756
+ configId: effectiveConfigId,
757
+ isNew: true,
758
+ };
759
+ setConversationList(list => [{ ...newConversation, messages: [] }, ...list]);
760
+ setChatData(list => [{ id: sessionId, messages: [], ...newConversation }, ...list]);
761
+ setActiveSessionId(sessionId);
762
+ // 自动触发新建会话接口
763
+
764
+ if (token && url) {
765
+ request
766
+ .post(
767
+ `${url}/qa/dialogue/create`,
768
+ {
769
+ configId: effectiveConfigId,
770
+ label: `来自内嵌应用${uid(8)}`,
771
+ sessionId,
772
+ sysType: 'TEMPORARY',
773
+ },
774
+ {
775
+ headers: { Authorization: token },
776
+ }
777
+ )
778
+ .then(res => {
779
+ const newSession = res.data.data;
780
+ if (newSession?.sessionId) {
781
+ setConversationList(list => [
782
+ { ...newSession, messages: [] },
783
+ ...list.filter(c => c.sessionId !== sessionId),
784
+ ]);
785
+ setChatData(list => [
786
+ { id: newSession.sessionId, messages: [], ...newSession },
787
+ ...list.filter(c => c.id !== sessionId),
788
+ ]);
789
+ setActiveSessionId(newSession.sessionId);
790
+ }
791
+ })
792
+ .catch(err => {
793
+ onError?.(err);
794
+ });
795
+ }
796
+ }
797
+
798
+ /**
799
+ * 文件管理器:处理文件选择后的上传
800
+ */
801
+ const handleFileManagerUpload = (fileList: FileList) => {
802
+ // 1. 收集所有已经存在的文件名
803
+ const existingFileNames = new Set<string>([
804
+ ...fileManagerData.uploadedFiles.map((f: any) => f.file.name as string),
805
+ ...pendingFiles.map((f: any) => f.file.name as string),
806
+ ]);
807
+
808
+ const newFiles: { file: File; type: string; status: string; preview?: string }[] = [];
809
+ const duplicateFileNames = new Set<string>();
810
+
811
+ // 2. 遍历新选择的文件,筛选出重复项和有效项
812
+ Array.from(fileList).forEach(file => {
813
+ if (existingFileNames.has(file.name)) {
814
+ duplicateFileNames.add(file.name);
815
+ } else {
816
+ newFiles.push({
817
+ file,
818
+ type: getFileTypeByName(file.name),
819
+ status: 'pending',
820
+ preview: file.type.startsWith('image') ? URL.createObjectURL(file) : undefined,
821
+ });
822
+ existingFileNames.add(file.name); // 添加到Set中,以防本次上传的文件之间有重复
823
+ }
824
+ });
825
+
826
+ // 3. 如果有重复,发出警告
827
+ if (duplicateFileNames.size > 0) {
828
+ message.warning(`不能上传同名文件: ${Array.from(duplicateFileNames).join(', ')}`);
829
+ }
830
+
831
+ // 4. 将有效的文件添加到待上传列表
832
+ if (newFiles.length > 0) {
833
+ setPendingFiles(prev => [...prev, ...newFiles]);
834
+ // 直接同步到核心发送器组件
835
+ setUploadedFilesRef.current?.(newFiles);
836
+ }
837
+ };
838
+
839
+ /**
840
+ * 文件管理器:处理文件移除
841
+ */
842
+ const handleFileManagerRemove = (fileObj: any, idx: number, _type: string) => {
843
+ removeFileRef.current?.(fileObj, idx, _type);
844
+ };
845
+
846
+ const is_download = useMemo(() => {
847
+ if (currentChatData.configId && assistantMap) {
848
+ const curAssist = assistantMap[currentChatData.configId];
849
+ if (curAssist?.configJson) {
850
+ const config = JSON.parse(curAssist.configJson);
851
+ return config.is_download;
852
+ }
853
+ return false;
854
+ } else {
855
+ return false;
856
+ }
857
+ }, [currentChatData.configId, assistantMap]);
858
+
859
+ /**
860
+ * 处理会话列表项点击
861
+ */
862
+ function handleItemClick(data: any) {
863
+ if (data?.sessionId && data.sessionId !== activeSessionId) {
864
+ setActiveSessionId(data.sessionId);
865
+ setAppStatus(prev => ({ ...prev, sender: 'ready' }));
866
+ // 点击会话时,使用其最后一条AI消息的推荐问题
867
+ const conv = chatData.find(c => c.id === data.sessionId);
868
+ if (conv && conv.messages && conv.messages.length > 0) {
869
+ const lastAiMsg = [...conv.messages].reverse().find((m: any) => m.istype === 'ai');
870
+ if (lastAiMsg && lastAiMsg.recommendQuestion) {
871
+ setRecommandQuestions(lastAiMsg.recommendQuestion);
872
+ } else {
873
+ setRecommandQuestions([]);
874
+ }
875
+ } else {
876
+ setRecommandQuestions([]);
877
+ }
878
+ }
879
+ }
880
+
881
+ // =================================================================
882
+ // Local State Updaters - 本地状态更新 (供事件发射器使用)
883
+ // =================================================================
884
+
885
+ const handleFeedDownConfirm = (data: any) => {
886
+ handleFeedBack({ url, token }, { ...data, ...feedParam, restult: 0 }, () => {
887
+ setFeed(feedParam.queryId, 0);
888
+ });
889
+ };
890
+
891
+ // =================================================================
892
+ // Event Emitter - 事件分发器
893
+ // =================================================================
894
+ /**
895
+ * 统一事件分发器,连接业务逻辑与所有子组件的事件
896
+ * @param {string} eventName - 事件名称
897
+ * @param {any} data - 事件数据
898
+ */
899
+ const mergedEventsEmit = (eventName: string, data: any) => {
900
+ console.log(`[Event] ${eventName}`, data);
901
+ switch (eventName) {
902
+ case 'retrive_tag:click':
903
+ if (data?.graph?.id) {
904
+ //图谱溯源
905
+ setDrawerType('graphPreview');
906
+ setCurFileInfo({ ...data.graph, traceNode: data.traceNode });
907
+ setOpen(true);
908
+ return;
909
+ }
910
+ if (!data?.tagInfo && !data?.file && !data?.referenceDoc) return;
911
+ const curFile = data?.referenceDoc || data?.file || data?.tagInfo;
912
+ const { pdfPages, parsedFilePath, order_num, metadata, tags } = curFile;
913
+ if (curFile.type == 'video') {
914
+ setCurFileInfo({
915
+ ...metadata,
916
+ displayType: 'retrive',
917
+ });
918
+ setDrawerType('video');
919
+ setOpen(true);
920
+ return;
921
+ }
922
+
923
+ const id = curFile.id || order_num || 'Unknown ID';
924
+ // 解析 source 字段
925
+ const sourceParts = metadata.source.split('/');
926
+ const fileName = sourceParts[sourceParts.length - 1] || '';
927
+ const fileParts = fileName.split('.');
928
+ const label = fileParts.slice(0, -1).join('.') || 'Unknown Label';
929
+ const file_type = fileParts[fileParts.length - 1] || 'Unknown Type';
930
+
931
+ setContent({
932
+ id,
933
+ title: label,
934
+ file_name: fileName,
935
+ file_type: file_type,
936
+ file_source: getMarkExcludeType(file_type)
937
+ ? `${TempBaseUrl}${metadata.source}`
938
+ : parsedFilePath,
939
+ metadata: metadata,
940
+ pdfPages: pdfPages,
941
+ });
942
+ setDrawerType('mark');
943
+ setOpen(true);
944
+ break;
945
+ // --- 对话列表事件 ---
946
+ case 'conversation:item_click':
947
+ handleItemClick(data);
948
+ break;
949
+
950
+ case 'files:finished_animation_complete':
951
+ setFileStatuses([]);
952
+ break;
953
+
954
+ case 'conversation:create':
955
+ handleConversationCreate(data);
956
+ break;
957
+ case 'conversation:new_assistant_change':
958
+ // headlessChat 不需要处理助手切换
959
+ break;
960
+
961
+ // --- 发送器事件 ---
962
+ case 'sender:send':
963
+ handleSenderSend(data, data.clearFn);
964
+ break;
965
+ case 'sender:send_recommandQuestion':
966
+ // 点击推荐问题,视作一次普通发送
967
+ handleSenderSend(data, data.clearFn);
968
+ break;
969
+ case 'sender:action_history':
970
+ setFileManagerOpen(true);
971
+ break;
972
+ case 'sender:stop':
973
+ stoppedRef.current = true;
974
+ if (uploadController) {
975
+ uploadController.abort();
976
+ uploadController = null;
977
+ }
978
+ if (stopPoll) {
979
+ stopPoll();
980
+ stopPoll = null;
981
+ }
982
+ setAppStatus(pre => ({ ...pre, display: 'ready', sender: 'ready' }));
983
+ setFileStatuses([]);
984
+ stopStream?.();
985
+ break;
986
+ case 'sender:clear':
987
+ data.clearFn?.();
988
+ break;
989
+ case 'sender:configChange':
990
+ // 配置项变化,记录最新 switch 状态
991
+ if (data && data.all) {
992
+ setSenderSwitchValues(data.all);
993
+ }
994
+ break;
995
+ case 'chatbox:follow_up_question_click': {
996
+ // 新链路:来自 ChatMessageAdapter 的追问点击
997
+ const content = (data?.question ?? data?.content ?? '').toString();
998
+ if (!content) break;
999
+ handleSenderSend({ content }, () => {});
1000
+ break;
1001
+ }
1002
+ case 'chatbox:copy': {
1003
+ const text = data?.content || '';
1004
+ if (!text) break;
1005
+ // 直接使用 Clipboard API,避免依赖 event.currentTarget
1006
+ const copyByClipboardApi = async (t: string) => {
1007
+ try {
1008
+ await navigator.clipboard.writeText(t);
1009
+ message.success('已复制到剪贴板');
1010
+ return true;
1011
+ } catch (_) {
1012
+ return false;
1013
+ }
1014
+ };
1015
+ const fallbackCopy = (t: string) => {
1016
+ const textarea = document.createElement('textarea');
1017
+ textarea.value = t;
1018
+ textarea.style.position = 'fixed';
1019
+ textarea.style.opacity = '0';
1020
+ document.body.appendChild(textarea);
1021
+ textarea.focus();
1022
+ textarea.select();
1023
+ try {
1024
+ document.execCommand('copy');
1025
+ message.success('已复制到剪贴板');
1026
+ } catch (_) {
1027
+ message.error('复制失败');
1028
+ }
1029
+ document.body.removeChild(textarea);
1030
+ };
1031
+ copyByClipboardApi(text).then(ok => {
1032
+ if (!ok) fallbackCopy(text);
1033
+ });
1034
+ break;
1035
+ }
1036
+ case 'chatbox:repeat':
1037
+ handleReSenderSend(data);
1038
+ break;
1039
+ case 'chatbox:like':
1040
+ handleThumbsup({ queryId: data?.queryId, restult: data?.result });
1041
+ break;
1042
+ case 'chatbox:dislike':
1043
+ if (data?.result === 0) {
1044
+ handleCancelFeedBack({ url, token }, { queryId: data.queryId }, () => {
1045
+ setFeed(data.queryId, null);
1046
+ });
1047
+ } else {
1048
+ setFeedParam({ queryId: data?.queryId });
1049
+ setOpenFeed(true);
1050
+ }
1051
+ break;
1052
+
1053
+ // --- 消息卡片事件 ---
1054
+ case 'action_copy:click':
1055
+ if (data) {
1056
+ toCopy(data.content, data.event);
1057
+ }
1058
+ break;
1059
+ case 'action_retry':
1060
+ handleReSenderSend(data);
1061
+ break;
1062
+ case 'action_thumbsup':
1063
+ handleThumbsup(data);
1064
+ break;
1065
+ case 'references:click': {
1066
+ // 使用 AiChat 内置的右侧栏事件
1067
+ const Content = () => {
1068
+ // const safe = (() => {
1069
+ // try {
1070
+ // return typeof data === 'string' ? data : JSON.stringify(data, null, 2);
1071
+ // } catch (e) {
1072
+ // return String(data);
1073
+ // }
1074
+ // })();
1075
+ return (
1076
+ <ReferenceBar
1077
+ type={DrawerType.REFERENCELIST}
1078
+ data={data}
1079
+ token={token}
1080
+ is_download={is_download}
1081
+ />
1082
+ );
1083
+ };
1084
+ const setContentEvent = new CustomEvent('aichat:right_set_content', {
1085
+ detail: { content: <Content /> },
1086
+ });
1087
+ window.dispatchEvent(setContentEvent);
1088
+ const openEvent = new CustomEvent('aichat:right_set', {
1089
+ detail: { collapsed: false },
1090
+ });
1091
+ window.dispatchEvent(openEvent);
1092
+ break;
1093
+ }
1094
+ case 'action_thumbsdown':
1095
+ if (data.restult === 0) {
1096
+ handleCancelFeedBack({ url, token }, { queryId: data.queryId }, () => {
1097
+ setFeed(data.queryId, null);
1098
+ });
1099
+ } else {
1100
+ setFeedParam(data);
1101
+ setOpenFeed(true);
1102
+ }
1103
+ break;
1104
+ // --- 文件管理器上传文件删除事件,透传到业务层 ---
1105
+ case 'uploaded_file:removeFromTemp': {
1106
+ console.log('[DEBUG] mergedEventsEmit uploaded_file:removeFromTemp 事件', data);
1107
+
1108
+ const uid = data?.file?.uid;
1109
+ if (!uid) {
1110
+ console.warn('[DEBUG] 缺少uid,无法删除临时文件', data);
1111
+ break;
1112
+ }
1113
+ // 获取当前对话最后一条 AI 消息的 queryId
1114
+ const lastAiMsg = [...(currentChatData.messages || [])]
1115
+ .reverse()
1116
+ .find((msg: any) => msg.istype === 'user');
1117
+ const queryId = lastAiMsg?.queryId;
1118
+ console.log('[DEBUG] mergedEventsEmit 获取到 queryId', queryId, lastAiMsg);
1119
+
1120
+ removeFilefromTempUpload({ url, token }, { uid, queryId }, (success, res) => {
1121
+ console.log('[DEBUG] removeFilefromTempUpload 回调触发', { success, res });
1122
+ if (success) {
1123
+ message.success('文件已从临时知识库移除');
1124
+ // 用后端返回的新data数组(新文件列表)更新本地uploadedFiles
1125
+ //console.log('[DEBUG] removeFilefromTempUpload 回调 true,res:', res, Array.isArray(res.data && res.data.data));
1126
+ if (res && Array.isArray(res.data && res.data.data)) {
1127
+ const uploaded = res.data.data.map((f: any) => {
1128
+ const fileName = f.name || f.fileName || '';
1129
+ return {
1130
+ file: {
1131
+ name: fileName,
1132
+ size: Number(f.size?.replace('MB', '')) * 1024 * 1024 || 0,
1133
+ type: f.type,
1134
+ } as File,
1135
+ type: getFileTypeByName(fileName),
1136
+ status: 'uploaded' as const,
1137
+ url: f.filePath,
1138
+ convertedFilePath: f.convertedFilePath,
1139
+ uid: f.uid,
1140
+ preview: f.type === 'image' ? f.filePath : undefined,
1141
+ };
1142
+ });
1143
+ // console.log('[DEBUG] uploaded 构造完成:', uploaded, '当前 fileManagerData:', fileManagerData);
1144
+ setFileManagerData({ uploadedFiles: uploaded });
1145
+ } else {
1146
+ //console.log('[DEBUG] res.data.data 不是数组', res && res.data && res.data.data);
1147
+ }
1148
+ } else {
1149
+ console.log('[DEBUG] removeFilefromTempUpload 回调 false,res:', res);
1150
+ message.error('文件移除失败');
1151
+ }
1152
+ });
1153
+ break;
1154
+ }
1155
+ // --- 文件管理器事件 ---
1156
+ case 'fileManager:change': {
1157
+ const files = Array.isArray(data?.uploadedFiles) ? data.uploadedFiles : [];
1158
+ setPendingFiles(files);
1159
+ // 保存核心组件传递的文件处理函数引用
1160
+ if (typeof data?.setUploadedFiles === 'function') {
1161
+ setUploadedFilesRef.current = data.setUploadedFiles;
1162
+ removeFileRef.current = data.removeFile;
1163
+ }
1164
+ break;
1165
+ }
1166
+
1167
+ default:
1168
+ // 其他未处理事件可继续向上层抛出
1169
+ eventsEmit?.(eventName, data);
1170
+ }
1171
+ };
1172
+
1173
+ // =================================================================
1174
+ // Component & UI Configuration - 组件及UI配置
1175
+ // =================================================================
1176
+
1177
+ /**
1178
+ * Sidebar 配置 - headlessChat 不需要左侧历史对话栏
1179
+ */
1180
+ const sidebar = undefined;
1181
+
1182
+ /**
1183
+ * 业务层自定义组件
1184
+ */
1185
+ const businessCustomComponents: { [key: string]: any } = {
1186
+ AiChatBox: (msg: any, idx: number) => {
1187
+ const isLastMessage = idx === (currentChatData?.messages?.length || 0) - 1;
1188
+
1189
+ // 根据消息的 status 和 appStatus 来确定 displayStatus
1190
+ let displayStatus = 'ready';
1191
+ if (isLastMessage) {
1192
+ // 优先使用消息的 status 字段
1193
+ if (msg.status !== undefined) {
1194
+ switch (msg.status) {
1195
+ case 0: // StatusType.Pending
1196
+ displayStatus = 'thinking';
1197
+ break;
1198
+ case 1: // StatusType.Process
1199
+ displayStatus = 'processing';
1200
+ break;
1201
+ case 2: // StatusType.Done
1202
+ displayStatus = 'ready';
1203
+ break;
1204
+ case 3: // StatusType.Error
1205
+ displayStatus = 'error';
1206
+ break;
1207
+ default:
1208
+ displayStatus = appStatus.display;
1209
+ }
1210
+ } else {
1211
+ // 如果没有 status 字段,使用 appStatus.display
1212
+ displayStatus = appStatus.display;
1213
+ }
1214
+ }
1215
+ // 将推荐问题强制转换为数组,避免切换会话时报 .map 错误
1216
+ let safeFollowUps: string[] = [];
1217
+ if (Array.isArray(recommandQuestions)) {
1218
+ safeFollowUps = recommandQuestions as string[];
1219
+ } else if (typeof recommandQuestions === 'string') {
1220
+ try {
1221
+ safeFollowUps = JSON.parse(recommandQuestions) || [];
1222
+ } catch {
1223
+ safeFollowUps = [];
1224
+ }
1225
+ }
1226
+ // 保证传入 ChatMessageAdapter 的 reference/webReference/graphReference 始终是有效的 JSON 字符串
1227
+ const safeReference = (() => {
1228
+ const r = (msg as any)?.reference;
1229
+ if (!r) return '[]';
1230
+ if (typeof r === 'string') {
1231
+ try {
1232
+ JSON.parse(r);
1233
+ return r;
1234
+ } catch {
1235
+ return '[]';
1236
+ }
1237
+ }
1238
+ try {
1239
+ return JSON.stringify(r);
1240
+ } catch {
1241
+ return '[]';
1242
+ }
1243
+ })();
1244
+ const safeWebReference = (() => {
1245
+ const r = (msg as any)?.webReference;
1246
+ if (!r) return '[]';
1247
+ if (typeof r === 'string') {
1248
+ try {
1249
+ JSON.parse(r);
1250
+ return r;
1251
+ } catch {
1252
+ return '[]';
1253
+ }
1254
+ }
1255
+ try {
1256
+ return JSON.stringify(r);
1257
+ } catch {
1258
+ return '[]';
1259
+ }
1260
+ })();
1261
+ const safeGraphReference = (() => {
1262
+ const r = (msg as any)?.graphReference;
1263
+ if (!r) return '[]';
1264
+ if (typeof r === 'string') {
1265
+ try {
1266
+ JSON.parse(r);
1267
+ return r;
1268
+ } catch {
1269
+ return '[]';
1270
+ }
1271
+ }
1272
+ try {
1273
+ return JSON.stringify(r);
1274
+ } catch {
1275
+ return '[]';
1276
+ }
1277
+ })();
1278
+ return (
1279
+ <ChatMessageAdapter
1280
+ key={`${msg?.queryId || msg?.id || idx}-${msg?.istype || 'unknown'}`}
1281
+ {...msg}
1282
+ referenceMode="button"
1283
+ reference={safeReference}
1284
+ webReference={safeWebReference}
1285
+ graphReference={safeGraphReference}
1286
+ contentType="stream"
1287
+ displayStatus={displayStatus}
1288
+ eventsEmit={mergedEventsEmit}
1289
+ // 仅最后一条 AI 消息展示追问
1290
+ isLast={isLastMessage && msg?.istype === 'ai'}
1291
+ followUpQuestions={isLastMessage && msg?.istype === 'ai' ? safeFollowUps : []}
1292
+ defaultAnswer={
1293
+ currentChatData?.searchConfigDTO?.defaultAnswer ||
1294
+ '不知道什么原因我们没能查到你要的问题*-*'
1295
+ }
1296
+ styles={styles}
1297
+ />
1298
+ );
1299
+ },
1300
+ LogoBox: () => <div className="text-2xl w-full text-center font-bold">小鲸智能助手</div>,
1301
+ DisplayLoading: () => <DisplayLoading />,
1302
+ DisplayError: () => <DisplayError />,
1303
+ AppError: () => <AppError />,
1304
+ AppLoading: () => <AppLoading />,
1305
+ UserChatBox: (msg: any, idx: number) => {
1306
+ return (
1307
+ <ChatMessageAdapter
1308
+ key={`${msg?.queryId || msg?.id || idx}-user`}
1309
+ {...msg}
1310
+ referenceMode="button"
1311
+ contentType="plainText"
1312
+ isUser={true}
1313
+ displayStatus="ready"
1314
+ eventsEmit={mergedEventsEmit}
1315
+ styles={styles}
1316
+ fileManagerData={fileManagerData}
1317
+ />
1318
+ );
1319
+ },
1320
+ WelcomeComponent: () => (
1321
+ <GientechNewChatWelcome
1322
+ eventsEmit={mergedEventsEmit}
1323
+ assistantList={assistantList}
1324
+ styles={styles}
1325
+ // defaultSelect={newAssistantId || assistantList[0]?.id}
1326
+ />
1327
+ ),
1328
+ };
1329
+
1330
+ /**
1331
+ * 合并外部传入和业务默认的自定义组件,外部优先
1332
+ */
1333
+ const mergedCustomComponents: { [key: string]: any } = { ...businessCustomComponents };
1334
+ if (rest.CustomComponents) {
1335
+ Object.keys(rest.CustomComponents).forEach(key => {
1336
+ const val = rest.CustomComponents?.[key];
1337
+ if (val !== undefined) {
1338
+ mergedCustomComponents[key] = val;
1339
+ }
1340
+ });
1341
+ }
1342
+
1343
+ // =================================================================
1344
+ // Render - 渲染
1345
+ // =================================================================
1346
+ return (
1347
+ <>
1348
+ <FileManager
1349
+ open={fileManagerOpen}
1350
+ onCancel={() => setFileManagerOpen(false)}
1351
+ files={fileManagerData.uploadedFiles}
1352
+ currentFiles={pendingFiles}
1353
+ onUpload={handleFileManagerUpload}
1354
+ onRemoveFile={handleFileManagerRemove}
1355
+ styles={styles}
1356
+ eventsEmit={mergedEventsEmit}
1357
+ />
1358
+
1359
+ <WrappedComponent
1360
+ activeSessionId={activeSessionId}
1361
+ status={appStatus}
1362
+ chatData={currentChatData}
1363
+ sidebar={sidebar}
1364
+ recommandQuestions={[]}
1365
+ eventsEmit={mergedEventsEmit}
1366
+ styles={styles}
1367
+ senderConfig={dynamicSenderConfig}
1368
+ fileUploadStatus={fileStatuses}
1369
+ CustomComponents={mergedCustomComponents}
1370
+ rightbarWidth={'400px'}
1371
+ />
1372
+ <FeedBackModal
1373
+ open={openFeed}
1374
+ feedBackList={feedBackList}
1375
+ setOpen={setOpenFeed}
1376
+ handleConfirm={handleFeedDownConfirm}
1377
+ />
1378
+ <ConfigProvider
1379
+ drawer={{
1380
+ styles: {
1381
+ body: { padding: 0 },
1382
+ header: { display: 'none' },
1383
+ },
1384
+ }}
1385
+ >
1386
+ <Drawer
1387
+ autoFocus={false}
1388
+ onClose={() => setOpen(false)}
1389
+ open={open}
1390
+ width={drawerType === 'graphPreview' ? '100%' : 720}
1391
+ className="overflow-x-hidden"
1392
+ destroyOnClose
1393
+ afterOpenChange={open => {
1394
+ if (!open) {
1395
+ setContent(null);
1396
+ }
1397
+ }}
1398
+ >
1399
+ {drawerType === 'mark' && (
1400
+ <DrawerContent
1401
+ content={content as any}
1402
+ onClose={() => setOpen(false)}
1403
+ token={token}
1404
+ />
1405
+ )}
1406
+ </Drawer>
1407
+ </ConfigProvider>
1408
+ </>
1409
+ );
1410
+ };
1411
+ }