index.tsx 23 KB

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