index.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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. if (currConversationId !== '-1')
  339. return true
  340. const prompt_variables = promptConfig?.prompt_variables
  341. const inputs = currInputs
  342. if (!inputs || !prompt_variables || prompt_variables?.length === 0)
  343. return true
  344. let hasEmptyInput = false
  345. const requiredVars = prompt_variables?.filter(({ key, name, required }) => {
  346. const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
  347. return res
  348. }) || [] // compatible with old version
  349. requiredVars.forEach(({ key }) => {
  350. if (hasEmptyInput)
  351. return
  352. if (!inputs?.[key])
  353. hasEmptyInput = true
  354. })
  355. if (hasEmptyInput) {
  356. logError(t('appDebug.errorMessage.valueOfVarRequired'))
  357. return false
  358. }
  359. return !hasEmptyInput
  360. }
  361. const [controlFocus, setControlFocus] = useState(0)
  362. const [isShowSuggestion, setIsShowSuggestion] = useState(false)
  363. const doShowSuggestion = isShowSuggestion && !isResponsing
  364. const [suggestQuestions, setSuggestQuestions] = useState<string[]>([])
  365. const [messageTaskId, setMessageTaskId] = useState('')
  366. const [hasStopResponded, setHasStopResponded, getHasStopResponded] = useGetState(false)
  367. const handleSend = async (message: string) => {
  368. if (isResponsing) {
  369. notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
  370. return
  371. }
  372. const data = {
  373. inputs: currInputs,
  374. query: message,
  375. conversation_id: isNewConversation ? null : currConversationId,
  376. }
  377. // qustion
  378. const questionId = `question-${Date.now()}`
  379. const questionItem = {
  380. id: questionId,
  381. content: message,
  382. isAnswer: false,
  383. }
  384. const placeholderAnswerId = `answer-placeholder-${Date.now()}`
  385. const placeholderAnswerItem = {
  386. id: placeholderAnswerId,
  387. content: '',
  388. isAnswer: true,
  389. }
  390. const newList = [...getChatList(), questionItem, placeholderAnswerItem]
  391. setChatList(newList)
  392. // answer
  393. const responseItem = {
  394. id: `${Date.now()}`,
  395. content: '',
  396. isAnswer: true,
  397. }
  398. let tempNewConversationId = ''
  399. setHasStopResponded(false)
  400. setResponsingTrue()
  401. setIsShowSuggestion(false)
  402. sendChatMessage(data, {
  403. getAbortController: (abortController) => {
  404. setAbortController(abortController)
  405. },
  406. onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {
  407. responseItem.content = responseItem.content + message
  408. responseItem.id = messageId
  409. if (isFirstMessage && newConversationId)
  410. tempNewConversationId = newConversationId
  411. setMessageTaskId(taskId)
  412. // closesure new list is outdated.
  413. const newListWithAnswer = produce(
  414. getChatList().filter(item => item.id !== responseItem.id && item.id !== placeholderAnswerId),
  415. (draft) => {
  416. if (!draft.find(item => item.id === questionId))
  417. draft.push({ ...questionItem })
  418. draft.push({ ...responseItem })
  419. })
  420. setChatList(newListWithAnswer)
  421. },
  422. async onCompleted(hasError?: boolean) {
  423. setResponsingFalse()
  424. if (hasError)
  425. return
  426. if (getConversationIdChangeBecauseOfNew()) {
  427. const { data: allConversations }: any = await fetchAllConversations()
  428. setAllConversationList(allConversations)
  429. noticeUpdateList()
  430. }
  431. setConversationIdChangeBecauseOfNew(false)
  432. resetNewConversationInputs()
  433. setChatNotStarted()
  434. setCurrConversationId(tempNewConversationId, appId, true)
  435. if (suggestedQuestionsAfterAnswerConfig?.enabled && !getHasStopResponded()) {
  436. const { data }: any = await fetchSuggestedQuestions(responseItem.id, isInstalledApp, installedAppInfo?.id)
  437. setSuggestQuestions(data)
  438. setIsShowSuggestion(true)
  439. }
  440. },
  441. onError() {
  442. setResponsingFalse()
  443. // role back placeholder answer
  444. setChatList(produce(getChatList(), (draft) => {
  445. draft.splice(draft.findIndex(item => item.id === placeholderAnswerId), 1)
  446. }))
  447. },
  448. }, isInstalledApp, installedAppInfo?.id)
  449. }
  450. const handleFeedback = async (messageId: string, feedback: Feedbacktype) => {
  451. await updateFeedback({ url: `/messages/${messageId}/feedbacks`, body: { rating: feedback.rating } }, isInstalledApp, installedAppInfo?.id)
  452. const newChatList = chatList.map((item) => {
  453. if (item.id === messageId) {
  454. return {
  455. ...item,
  456. feedback,
  457. }
  458. }
  459. return item
  460. })
  461. setChatList(newChatList)
  462. notify({ type: 'success', message: t('common.api.success') })
  463. }
  464. const renderSidebar = () => {
  465. if (!appId || !siteInfo || !promptConfig)
  466. return null
  467. return (
  468. <Sidebar
  469. list={conversationList}
  470. isClearConversationList={isClearConversationList}
  471. pinnedList={pinnedConversationList}
  472. isClearPinnedConversationList={isClearPinnedConversationList}
  473. onMoreLoaded={onMoreLoaded}
  474. onPinnedMoreLoaded={onPinnedMoreLoaded}
  475. isNoMore={!hasMore}
  476. isPinnedNoMore={!hasPinnedMore}
  477. onCurrentIdChange={handleConversationIdChange}
  478. currentId={currConversationId}
  479. copyRight={siteInfo.copyright || siteInfo.title}
  480. isInstalledApp={isInstalledApp}
  481. installedAppId={installedAppInfo?.id}
  482. siteInfo={siteInfo}
  483. onPin={handlePin}
  484. onUnpin={handleUnpin}
  485. controlUpdateList={controlUpdateConversationList}
  486. onDelete={handleDelete}
  487. />
  488. )
  489. }
  490. if (appUnavailable)
  491. return <AppUnavailable isUnknwonReason={isUnknwonReason} />
  492. if (!appId || !siteInfo || !promptConfig)
  493. return <Loading type='app' />
  494. return (
  495. <div className='bg-gray-100'>
  496. {!isInstalledApp && (
  497. <Header
  498. title={siteInfo.title}
  499. icon={siteInfo.icon || ''}
  500. icon_background={siteInfo.icon_background}
  501. isMobile={isMobile}
  502. onShowSideBar={showSidebar}
  503. onCreateNewChat={() => handleConversationIdChange('-1')}
  504. />
  505. )}
  506. <div
  507. className={cn(
  508. 'flex rounded-t-2xl bg-white overflow-hidden',
  509. isInstalledApp && 'rounded-b-2xl',
  510. )}
  511. style={isInstalledApp
  512. ? {
  513. boxShadow: '0px 12px 16px -4px rgba(16, 24, 40, 0.08), 0px 4px 6px -2px rgba(16, 24, 40, 0.03)',
  514. }
  515. : {}}
  516. >
  517. {/* sidebar */}
  518. {!isMobile && renderSidebar()}
  519. {isMobile && isShowSidebar && (
  520. <div className='fixed inset-0 z-50'
  521. style={{ backgroundColor: 'rgba(35, 56, 118, 0.2)' }}
  522. onClick={hideSidebar}
  523. >
  524. <div className='inline-block' onClick={e => e.stopPropagation()}>
  525. {renderSidebar()}
  526. </div>
  527. </div>
  528. )}
  529. {/* main */}
  530. <div className={cn(
  531. isInstalledApp ? s.installedApp : 'h-[calc(100vh_-_3rem)]',
  532. 'flex-grow flex flex-col overflow-y-auto',
  533. )
  534. }>
  535. <ConfigSence
  536. conversationName={conversationName}
  537. hasSetInputs={hasSetInputs}
  538. isPublicVersion={isPublicVersion}
  539. siteInfo={siteInfo}
  540. promptConfig={promptConfig}
  541. onStartChat={handleStartChat}
  542. canEidtInpus={canEditInpus}
  543. savedInputs={currInputs as Record<string, any>}
  544. onInputsChange={setCurrInputs}
  545. plan={plan}
  546. ></ConfigSence>
  547. {
  548. hasSetInputs && (
  549. <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')}>
  550. <div className='h-full overflow-y-auto' ref={chatListDomRef}>
  551. <Chat
  552. chatList={chatList}
  553. onSend={handleSend}
  554. isHideFeedbackEdit
  555. onFeedback={handleFeedback}
  556. isResponsing={isResponsing}
  557. canStopResponsing={!!messageTaskId}
  558. abortResponsing={async () => {
  559. await stopChatMessageResponding(appId, messageTaskId, isInstalledApp, installedAppInfo?.id)
  560. setHasStopResponded(true)
  561. setResponsingFalse()
  562. }}
  563. checkCanSend={checkCanSend}
  564. controlFocus={controlFocus}
  565. isShowSuggestion={doShowSuggestion}
  566. suggestionList={suggestQuestions}
  567. />
  568. </div>
  569. </div>)
  570. }
  571. {isShowConfirm && (
  572. <Confirm
  573. title={t('share.chat.deleteConversation.title')}
  574. content={t('share.chat.deleteConversation.content')}
  575. isShow={isShowConfirm}
  576. onClose={hideConfirm}
  577. onConfirm={didDelete}
  578. onCancel={hideConfirm}
  579. />
  580. )}
  581. </div>
  582. </div>
  583. </div>
  584. )
  585. }
  586. export default React.memo(Main)