index.tsx 23 KB

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