index.tsx 23 KB

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