index.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /* eslint-disable @typescript-eslint/no-use-before-define */
  2. 'use client'
  3. import type { FC } from 'react'
  4. import React, { useEffect, useRef, useState } from 'react'
  5. import cn from 'classnames'
  6. import { useTranslation } from 'react-i18next'
  7. import { useContext } from 'use-context-selector'
  8. import produce from 'immer'
  9. import { useBoolean, useGetState } from 'ahooks'
  10. import AppUnavailable from '../../base/app-unavailable'
  11. import useConversation from './hooks/use-conversation'
  12. import s from './style.module.css'
  13. import { ToastContext } from '@/app/components/base/toast'
  14. import Sidebar from '@/app/components/share/chat/sidebar'
  15. import ConfigSence from '@/app/components/share/chat/config-scence'
  16. import Header from '@/app/components/share/header'
  17. import { delConversation, fetchAppInfo, fetchAppParams, fetchChatList, fetchConversations, fetchSuggestedQuestions, pinConversation, sendChatMessage, stopChatMessageResponding, unpinConversation, updateFeedback } from '@/service/share'
  18. import type { ConversationItem, SiteInfo } from '@/models/share'
  19. import type { PromptConfig, SuggestedQuestionsAfterAnswerConfig } from '@/models/debug'
  20. import type { Feedbacktype, IChatItem } from '@/app/components/app/chat'
  21. import Chat from '@/app/components/app/chat'
  22. import { changeLanguage } from '@/i18n/i18next-config'
  23. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  24. import Loading from '@/app/components/base/loading'
  25. import { replaceStringWithValues } from '@/app/components/app/configuration/prompt-value-panel'
  26. import { userInputsFormToPromptVariables } from '@/utils/model-config'
  27. import type { InstalledApp } from '@/models/explore'
  28. import Confirm from '@/app/components/base/confirm'
  29. export type IMainProps = {
  30. isInstalledApp?: boolean
  31. installedAppInfo?: InstalledApp
  32. }
  33. const Main: FC<IMainProps> = ({
  34. isInstalledApp = false,
  35. installedAppInfo,
  36. }) => {
  37. const { t } = useTranslation()
  38. const media = useBreakpoints()
  39. const isMobile = media === MediaType.mobile
  40. /*
  41. * app info
  42. */
  43. const [appUnavailable, setAppUnavailable] = useState<boolean>(false)
  44. const [isUnknwonReason, setIsUnknwonReason] = useState<boolean>(false)
  45. const [appId, setAppId] = useState<string>('')
  46. const [isPublicVersion, setIsPublicVersion] = useState<boolean>(true)
  47. const [siteInfo, setSiteInfo] = useState<SiteInfo | null>()
  48. const [promptConfig, setPromptConfig] = useState<PromptConfig | null>(null)
  49. const [inited, setInited] = useState<boolean>(false)
  50. const [plan, setPlan] = useState<string>('basic') // basic/plus/pro
  51. // in mobile, show sidebar by click button
  52. const [isShowSidebar, { setTrue: showSidebar, setFalse: hideSidebar }] = useBoolean(false)
  53. // Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client.
  54. useEffect(() => {
  55. if (siteInfo?.title) {
  56. if (plan !== 'basic')
  57. document.title = `${siteInfo.title}`
  58. else
  59. document.title = `${siteInfo.title} - Powered by Dify`
  60. }
  61. }, [siteInfo?.title, plan])
  62. /*
  63. * conversation info
  64. */
  65. const [allConversationList, setAllConversationList] = useState<ConversationItem[]>([])
  66. const {
  67. conversationList,
  68. setConversationList,
  69. pinnedConversationList,
  70. setPinnedConversationList,
  71. currConversationId,
  72. setCurrConversationId,
  73. getConversationIdFromStorage,
  74. isNewConversation,
  75. currConversationInfo,
  76. currInputs,
  77. newConversationInputs,
  78. // existConversationInputs,
  79. resetNewConversationInputs,
  80. setCurrInputs,
  81. setNewConversationInfo,
  82. setExistConversationInfo,
  83. } = useConversation()
  84. const [hasMore, setHasMore] = useState<boolean>(true)
  85. const [hasPinnedMore, setHasPinnedMore] = useState<boolean>(true)
  86. const onMoreLoaded = ({ data: conversations, has_more }: any) => {
  87. setHasMore(has_more)
  88. setConversationList([...conversationList, ...conversations])
  89. }
  90. const onPinnedMoreLoaded = ({ data: conversations, has_more }: any) => {
  91. setHasPinnedMore(has_more)
  92. setPinnedConversationList([...pinnedConversationList, ...conversations])
  93. }
  94. const [controlUpdateConversationList, setControlUpdateConversationList] = useState(0)
  95. const noticeUpdateList = () => {
  96. setConversationList([])
  97. setHasMore(true)
  98. setPinnedConversationList([])
  99. setHasPinnedMore(true)
  100. setControlUpdateConversationList(Date.now())
  101. }
  102. const handlePin = async (id: string) => {
  103. await pinConversation(isInstalledApp, installedAppInfo?.id, id)
  104. notify({ type: 'success', message: t('common.api.success') })
  105. noticeUpdateList()
  106. }
  107. const handleUnpin = async (id: string) => {
  108. await unpinConversation(isInstalledApp, installedAppInfo?.id, id)
  109. notify({ type: 'success', message: t('common.api.success') })
  110. noticeUpdateList()
  111. }
  112. const [isShowConfirm, { setTrue: showConfirm, setFalse: hideConfirm }] = useBoolean(false)
  113. const [toDeleteConversationId, setToDeleteConversationId] = useState('')
  114. const handleDelete = (id: string) => {
  115. setToDeleteConversationId(id)
  116. hideSidebar() // mobile
  117. showConfirm()
  118. }
  119. const didDelete = async () => {
  120. await delConversation(isInstalledApp, installedAppInfo?.id, toDeleteConversationId)
  121. notify({ type: 'success', message: t('common.api.success') })
  122. hideConfirm()
  123. noticeUpdateList()
  124. }
  125. const [suggestedQuestionsAfterAnswerConfig, setSuggestedQuestionsAfterAnswerConfig] = useState<SuggestedQuestionsAfterAnswerConfig | null>(null)
  126. const [conversationIdChangeBecauseOfNew, setConversationIdChangeBecauseOfNew, getConversationIdChangeBecauseOfNew] = useGetState(false)
  127. const [isChatStarted, { setTrue: setChatStarted, setFalse: setChatNotStarted }] = useBoolean(false)
  128. const handleStartChat = (inputs: Record<string, any>) => {
  129. createNewChat()
  130. setConversationIdChangeBecauseOfNew(true)
  131. setCurrInputs(inputs)
  132. setChatStarted()
  133. // parse variables in introduction
  134. setChatList(generateNewChatListWithOpenstatement('', inputs))
  135. }
  136. const hasSetInputs = (() => {
  137. if (!isNewConversation)
  138. return true
  139. return isChatStarted
  140. })()
  141. const conversationName = currConversationInfo?.name || t('share.chat.newChatDefaultName') as string
  142. const conversationIntroduction = currConversationInfo?.introduction || ''
  143. const handleConversationSwitch = () => {
  144. if (!inited)
  145. return
  146. if (!appId) {
  147. // wait for appId
  148. setTimeout(handleConversationSwitch, 100)
  149. return
  150. }
  151. // update inputs of current conversation
  152. let notSyncToStateIntroduction = ''
  153. let notSyncToStateInputs: Record<string, any> | undefined | null = {}
  154. if (!isNewConversation) {
  155. const item = allConversationList.find(item => item.id === currConversationId)
  156. notSyncToStateInputs = item?.inputs || {}
  157. setCurrInputs(notSyncToStateInputs)
  158. notSyncToStateIntroduction = item?.introduction || ''
  159. setExistConversationInfo({
  160. name: item?.name || '',
  161. introduction: notSyncToStateIntroduction,
  162. })
  163. }
  164. else {
  165. notSyncToStateInputs = newConversationInputs
  166. setCurrInputs(notSyncToStateInputs)
  167. }
  168. // update chat list of current conversation
  169. if (!isNewConversation && !conversationIdChangeBecauseOfNew && !isResponsing) {
  170. fetchChatList(currConversationId, isInstalledApp, installedAppInfo?.id).then((res: any) => {
  171. const { data } = res
  172. const newChatList: IChatItem[] = generateNewChatListWithOpenstatement(notSyncToStateIntroduction, notSyncToStateInputs)
  173. data.forEach((item: any) => {
  174. newChatList.push({
  175. id: `question-${item.id}`,
  176. content: item.query,
  177. isAnswer: false,
  178. })
  179. newChatList.push({
  180. id: item.id,
  181. content: item.answer,
  182. feedback: item.feedback,
  183. isAnswer: true,
  184. })
  185. })
  186. setChatList(newChatList)
  187. })
  188. }
  189. if (isNewConversation && isChatStarted)
  190. setChatList(generateNewChatListWithOpenstatement())
  191. setControlFocus(Date.now())
  192. }
  193. useEffect(handleConversationSwitch, [currConversationId, inited])
  194. const handleConversationIdChange = (id: string) => {
  195. if (id === '-1') {
  196. createNewChat()
  197. setConversationIdChangeBecauseOfNew(true)
  198. }
  199. else {
  200. setConversationIdChangeBecauseOfNew(false)
  201. }
  202. // trigger handleConversationSwitch
  203. setCurrConversationId(id, appId)
  204. setIsShowSuggestion(false)
  205. hideSidebar()
  206. }
  207. /*
  208. * chat info. chat is under conversation.
  209. */
  210. const [chatList, setChatList, getChatList] = useGetState<IChatItem[]>([])
  211. const chatListDomRef = useRef<HTMLDivElement>(null)
  212. useEffect(() => {
  213. // scroll to bottom
  214. if (chatListDomRef.current)
  215. chatListDomRef.current.scrollTop = chatListDomRef.current.scrollHeight
  216. }, [chatList, currConversationId])
  217. // user can not edit inputs if user had send message
  218. const canEditInpus = !chatList.some(item => item.isAnswer === false) && isNewConversation
  219. const createNewChat = async () => {
  220. // if new chat is already exist, do not create new chat
  221. abortController?.abort()
  222. setResponsingFalse()
  223. if (conversationList.some(item => item.id === '-1'))
  224. return
  225. setConversationList(produce(conversationList, (draft) => {
  226. draft.unshift({
  227. id: '-1',
  228. name: t('share.chat.newChatDefaultName'),
  229. inputs: newConversationInputs,
  230. introduction: conversationIntroduction,
  231. })
  232. }))
  233. }
  234. // sometime introduction is not applied to state
  235. const generateNewChatListWithOpenstatement = (introduction?: string, inputs?: Record<string, any> | null) => {
  236. let caculatedIntroduction = introduction || conversationIntroduction || ''
  237. const caculatedPromptVariables = inputs || currInputs || null
  238. if (caculatedIntroduction && caculatedPromptVariables)
  239. caculatedIntroduction = replaceStringWithValues(caculatedIntroduction, promptConfig?.prompt_variables || [], caculatedPromptVariables)
  240. // console.log(isPublicVersion)
  241. const openstatement = {
  242. id: `${Date.now()}`,
  243. content: caculatedIntroduction,
  244. isAnswer: true,
  245. feedbackDisabled: true,
  246. isOpeningStatement: isPublicVersion,
  247. }
  248. if (caculatedIntroduction)
  249. return [openstatement]
  250. return []
  251. }
  252. const fetchAllConversations = () => {
  253. return fetchConversations(isInstalledApp, installedAppInfo?.id, undefined, undefined, 100)
  254. }
  255. const fetchInitData = () => {
  256. return Promise.all([isInstalledApp
  257. ? {
  258. app_id: installedAppInfo?.id,
  259. site: {
  260. title: installedAppInfo?.app.name,
  261. prompt_public: false,
  262. copyright: '',
  263. },
  264. plan: 'basic',
  265. }
  266. : fetchAppInfo(), fetchAllConversations(), fetchAppParams(isInstalledApp, installedAppInfo?.id)])
  267. }
  268. // init
  269. useEffect(() => {
  270. (async () => {
  271. try {
  272. const [appData, conversationData, appParams]: any = await fetchInitData()
  273. const { app_id: appId, site: siteInfo, plan }: any = appData
  274. setAppId(appId)
  275. setPlan(plan)
  276. const tempIsPublicVersion = siteInfo.prompt_public
  277. setIsPublicVersion(tempIsPublicVersion)
  278. const prompt_template = ''
  279. // handle current conversation id
  280. const { data: allConversations } = conversationData as { data: ConversationItem[]; has_more: boolean }
  281. const _conversationId = getConversationIdFromStorage(appId)
  282. const isNotNewConversation = allConversations.some(item => item.id === _conversationId)
  283. setAllConversationList(allConversations)
  284. // fetch new conversation info
  285. const { user_input_form, opening_statement: introduction, suggested_questions_after_answer }: any = appParams
  286. const prompt_variables = userInputsFormToPromptVariables(user_input_form)
  287. if (siteInfo.default_language)
  288. changeLanguage(siteInfo.default_language)
  289. setNewConversationInfo({
  290. name: t('share.chat.newChatDefaultName'),
  291. introduction,
  292. })
  293. setSiteInfo(siteInfo as SiteInfo)
  294. setPromptConfig({
  295. prompt_template,
  296. prompt_variables,
  297. } as PromptConfig)
  298. setSuggestedQuestionsAfterAnswerConfig(suggested_questions_after_answer)
  299. // setConversationList(conversations as ConversationItem[])
  300. if (isNotNewConversation)
  301. setCurrConversationId(_conversationId, appId, false)
  302. setInited(true)
  303. }
  304. catch (e: any) {
  305. if (e.status === 404) {
  306. setAppUnavailable(true)
  307. }
  308. else {
  309. setIsUnknwonReason(true)
  310. setAppUnavailable(true)
  311. }
  312. }
  313. })()
  314. }, [])
  315. const [isResponsing, { setTrue: setResponsingTrue, setFalse: setResponsingFalse }] = useBoolean(false)
  316. const [abortController, setAbortController] = useState<AbortController | null>(null)
  317. const { notify } = useContext(ToastContext)
  318. const logError = (message: string) => {
  319. notify({ type: 'error', message })
  320. }
  321. const checkCanSend = () => {
  322. const prompt_variables = promptConfig?.prompt_variables
  323. const inputs = currInputs
  324. if (!inputs || !prompt_variables || prompt_variables?.length === 0)
  325. return true
  326. let hasEmptyInput = false
  327. const requiredVars = prompt_variables?.filter(({ key, name, required }) => {
  328. const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
  329. return res
  330. }) || [] // compatible with old version
  331. requiredVars.forEach(({ key }) => {
  332. if (hasEmptyInput)
  333. return
  334. if (!inputs?.[key])
  335. hasEmptyInput = true
  336. })
  337. if (hasEmptyInput) {
  338. logError(t('appDebug.errorMessage.valueOfVarRequired'))
  339. return false
  340. }
  341. return !hasEmptyInput
  342. }
  343. const [controlFocus, setControlFocus] = useState(0)
  344. const [isShowSuggestion, setIsShowSuggestion] = useState(false)
  345. const doShowSuggestion = isShowSuggestion && !isResponsing
  346. const [suggestQuestions, setSuggestQuestions] = useState<string[]>([])
  347. const [messageTaskId, setMessageTaskId] = useState('')
  348. const [hasStopResponded, setHasStopResponded, getHasStopResponded] = useGetState(false)
  349. const handleSend = async (message: string) => {
  350. if (isResponsing) {
  351. notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
  352. return
  353. }
  354. const data = {
  355. inputs: currInputs,
  356. query: message,
  357. conversation_id: isNewConversation ? null : currConversationId,
  358. }
  359. // qustion
  360. const questionId = `question-${Date.now()}`
  361. const questionItem = {
  362. id: questionId,
  363. content: message,
  364. isAnswer: false,
  365. }
  366. const placeholderAnswerId = `answer-placeholder-${Date.now()}`
  367. const placeholderAnswerItem = {
  368. id: placeholderAnswerId,
  369. content: '',
  370. isAnswer: true,
  371. }
  372. const newList = [...getChatList(), questionItem, placeholderAnswerItem]
  373. setChatList(newList)
  374. // answer
  375. const responseItem = {
  376. id: `${Date.now()}`,
  377. content: '',
  378. isAnswer: true,
  379. }
  380. let tempNewConversationId = ''
  381. setHasStopResponded(false)
  382. setResponsingTrue()
  383. setIsShowSuggestion(false)
  384. sendChatMessage(data, {
  385. getAbortController: (abortController) => {
  386. setAbortController(abortController)
  387. },
  388. onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {
  389. responseItem.content = responseItem.content + message
  390. responseItem.id = messageId
  391. if (isFirstMessage && newConversationId)
  392. tempNewConversationId = newConversationId
  393. setMessageTaskId(taskId)
  394. // closesure new list is outdated.
  395. const newListWithAnswer = produce(
  396. getChatList().filter(item => item.id !== responseItem.id && item.id !== placeholderAnswerId),
  397. (draft) => {
  398. if (!draft.find(item => item.id === questionId))
  399. draft.push({ ...questionItem })
  400. draft.push({ ...responseItem })
  401. })
  402. setChatList(newListWithAnswer)
  403. },
  404. async onCompleted(hasError?: boolean) {
  405. setResponsingFalse()
  406. if (hasError)
  407. return
  408. if (getConversationIdChangeBecauseOfNew()) {
  409. const { data: allConversations }: any = await fetchAllConversations()
  410. setAllConversationList(allConversations)
  411. noticeUpdateList()
  412. }
  413. setConversationIdChangeBecauseOfNew(false)
  414. resetNewConversationInputs()
  415. setChatNotStarted()
  416. setCurrConversationId(tempNewConversationId, appId, true)
  417. if (suggestedQuestionsAfterAnswerConfig?.enabled && !getHasStopResponded()) {
  418. const { data }: any = await fetchSuggestedQuestions(responseItem.id, isInstalledApp, installedAppInfo?.id)
  419. setSuggestQuestions(data)
  420. setIsShowSuggestion(true)
  421. }
  422. },
  423. onError() {
  424. setResponsingFalse()
  425. // role back placeholder answer
  426. setChatList(produce(getChatList(), (draft) => {
  427. draft.splice(draft.findIndex(item => item.id === placeholderAnswerId), 1)
  428. }))
  429. },
  430. }, isInstalledApp, installedAppInfo?.id)
  431. }
  432. const handleFeedback = async (messageId: string, feedback: Feedbacktype) => {
  433. await updateFeedback({ url: `/messages/${messageId}/feedbacks`, body: { rating: feedback.rating } }, isInstalledApp, installedAppInfo?.id)
  434. const newChatList = chatList.map((item) => {
  435. if (item.id === messageId) {
  436. return {
  437. ...item,
  438. feedback,
  439. }
  440. }
  441. return item
  442. })
  443. setChatList(newChatList)
  444. notify({ type: 'success', message: t('common.api.success') })
  445. }
  446. const renderSidebar = () => {
  447. if (!appId || !siteInfo || !promptConfig)
  448. return null
  449. return (
  450. <Sidebar
  451. list={conversationList}
  452. pinnedList={pinnedConversationList}
  453. onMoreLoaded={onMoreLoaded}
  454. onPinnedMoreLoaded={onPinnedMoreLoaded}
  455. isNoMore={!hasMore}
  456. isPinnedNoMore={!hasPinnedMore}
  457. onCurrentIdChange={handleConversationIdChange}
  458. currentId={currConversationId}
  459. copyRight={siteInfo.copyright || siteInfo.title}
  460. isInstalledApp={isInstalledApp}
  461. installedAppId={installedAppInfo?.id}
  462. siteInfo={siteInfo}
  463. onPin={handlePin}
  464. onUnpin={handleUnpin}
  465. controlUpdateList={controlUpdateConversationList}
  466. onDelete={handleDelete}
  467. />
  468. )
  469. }
  470. if (appUnavailable)
  471. return <AppUnavailable isUnknwonReason={isUnknwonReason} />
  472. if (!appId || !siteInfo || !promptConfig)
  473. return <Loading type='app' />
  474. return (
  475. <div className='bg-gray-100'>
  476. {!isInstalledApp && (
  477. <Header
  478. title={siteInfo.title}
  479. icon={siteInfo.icon || ''}
  480. icon_background={siteInfo.icon_background}
  481. isMobile={isMobile}
  482. onShowSideBar={showSidebar}
  483. onCreateNewChat={() => handleConversationIdChange('-1')}
  484. />
  485. )}
  486. <div
  487. className={cn(
  488. 'flex rounded-t-2xl bg-white overflow-hidden',
  489. isInstalledApp && 'rounded-b-2xl',
  490. )}
  491. style={isInstalledApp
  492. ? {
  493. boxShadow: '0px 12px 16px -4px rgba(16, 24, 40, 0.08), 0px 4px 6px -2px rgba(16, 24, 40, 0.03)',
  494. }
  495. : {}}
  496. >
  497. {/* sidebar */}
  498. {!isMobile && renderSidebar()}
  499. {isMobile && isShowSidebar && (
  500. <div className='fixed inset-0 z-50'
  501. style={{ backgroundColor: 'rgba(35, 56, 118, 0.2)' }}
  502. onClick={hideSidebar}
  503. >
  504. <div className='inline-block' onClick={e => e.stopPropagation()}>
  505. {renderSidebar()}
  506. </div>
  507. </div>
  508. )}
  509. {/* main */}
  510. <div className={cn(
  511. isInstalledApp ? s.installedApp : 'h-[calc(100vh_-_3rem)]',
  512. 'flex-grow flex flex-col overflow-y-auto',
  513. )
  514. }>
  515. <ConfigSence
  516. conversationName={conversationName}
  517. hasSetInputs={hasSetInputs}
  518. isPublicVersion={isPublicVersion}
  519. siteInfo={siteInfo}
  520. promptConfig={promptConfig}
  521. onStartChat={handleStartChat}
  522. canEidtInpus={canEditInpus}
  523. savedInputs={currInputs as Record<string, any>}
  524. onInputsChange={setCurrInputs}
  525. plan={plan}
  526. ></ConfigSence>
  527. {
  528. hasSetInputs && (
  529. <div className={cn(doShowSuggestion ? 'pb-[140px]' : (isResponsing ? 'pb-[113px]' : 'pb-[66px]'), 'relative grow h-[200px] pc:w-[794px] max-w-full mobile:w-full mx-auto mb-3.5 overflow-hidden')}>
  530. <div className='h-full overflow-y-auto' ref={chatListDomRef}>
  531. <Chat
  532. chatList={chatList}
  533. onSend={handleSend}
  534. isHideFeedbackEdit
  535. onFeedback={handleFeedback}
  536. isResponsing={isResponsing}
  537. canStopResponsing={!!messageTaskId}
  538. abortResponsing={async () => {
  539. await stopChatMessageResponding(appId, messageTaskId, isInstalledApp, installedAppInfo?.id)
  540. setHasStopResponded(true)
  541. setResponsingFalse()
  542. }}
  543. checkCanSend={checkCanSend}
  544. controlFocus={controlFocus}
  545. isShowSuggestion={doShowSuggestion}
  546. suggestionList={suggestQuestions}
  547. />
  548. </div>
  549. </div>)
  550. }
  551. {isShowConfirm && (
  552. <Confirm
  553. title={t('share.chat.deleteConversation.title')}
  554. content={t('share.chat.deleteConversation.content')}
  555. isShow={isShowConfirm}
  556. onClose={hideConfirm}
  557. onConfirm={didDelete}
  558. onCancel={hideConfirm}
  559. />
  560. )}
  561. </div>
  562. </div>
  563. </div>
  564. )
  565. }
  566. export default React.memo(Main)