index.tsx 23 KB

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