index.tsx 23 KB

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