index.tsx 22 KB

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