index.tsx 23 KB

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