index.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. const [canReplaceLogo, setCanReplaceLogo] = useState<boolean>(false)
  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 (canReplaceLogo)
  59. document.title = `${siteInfo.title}`
  60. else
  61. document.title = `${siteInfo.title} - Powered by Dify`
  62. }
  63. }, [siteInfo?.title, canReplaceLogo])
  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, can_replace_logo }: any = appData
  258. setAppId(appId)
  259. setPlan(plan)
  260. setCanReplaceLogo(can_replace_logo)
  261. const tempIsPublicVersion = siteInfo.prompt_public
  262. setIsPublicVersion(tempIsPublicVersion)
  263. const prompt_template = ''
  264. // handle current conversation id
  265. const { data: allConversations } = conversationData as { data: ConversationItem[]; has_more: boolean }
  266. const _conversationId = getConversationIdFromStorage(appId)
  267. const isNotNewConversation = allConversations.some(item => item.id === _conversationId)
  268. setAllConversationList(allConversations)
  269. // fetch new conversation info
  270. const { user_input_form, opening_statement: introduction, suggested_questions_after_answer, speech_to_text, file_upload, sensitive_word_avoidance }: any = appParams
  271. setVisionConfig({
  272. ...file_upload.image,
  273. image_file_size_limit: appParams?.system_parameters?.image_file_size_limit,
  274. })
  275. const prompt_variables = userInputsFormToPromptVariables(user_input_form)
  276. if (siteInfo.default_language)
  277. changeLanguage(siteInfo.default_language)
  278. setNewConversationInfo({
  279. name: t('share.chat.newChatDefaultName'),
  280. introduction,
  281. })
  282. setSiteInfo(siteInfo as SiteInfo)
  283. setPromptConfig({
  284. prompt_template,
  285. prompt_variables,
  286. } as PromptConfig)
  287. setSuggestedQuestionsAfterAnswerConfig(suggested_questions_after_answer)
  288. setSpeechToTextConfig(speech_to_text)
  289. // setConversationList(conversations as ConversationItem[])
  290. if (isNotNewConversation)
  291. setCurrConversationId(_conversationId, appId, false)
  292. setInited(true)
  293. }
  294. catch (e: any) {
  295. if (e.status === 404) {
  296. setAppUnavailable(true)
  297. }
  298. else {
  299. setIsUnknwonReason(true)
  300. setAppUnavailable(true)
  301. }
  302. }
  303. })()
  304. }, [])
  305. const [isResponsing, { setTrue: setResponsingTrue, setFalse: setResponsingFalse }] = useBoolean(false)
  306. const [abortController, setAbortController] = useState<AbortController | null>(null)
  307. const { notify } = useContext(ToastContext)
  308. const logError = (message: string) => {
  309. notify({ type: 'error', message })
  310. }
  311. const checkCanSend = () => {
  312. if (currConversationId !== '-1')
  313. return true
  314. const prompt_variables = promptConfig?.prompt_variables
  315. const inputs = currInputs
  316. if (!inputs || !prompt_variables || prompt_variables?.length === 0)
  317. return true
  318. let hasEmptyInput = ''
  319. const requiredVars = prompt_variables?.filter(({ key, name, required }) => {
  320. const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
  321. return res
  322. }) || [] // compatible with old version
  323. requiredVars.forEach(({ key, name }) => {
  324. if (hasEmptyInput)
  325. return
  326. if (!inputs?.[key])
  327. hasEmptyInput = name
  328. })
  329. if (hasEmptyInput) {
  330. logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput }))
  331. return false
  332. }
  333. return !hasEmptyInput
  334. }
  335. const [controlFocus, setControlFocus] = useState(0)
  336. const [isShowSuggestion, setIsShowSuggestion] = useState(false)
  337. const doShowSuggestion = isShowSuggestion && !isResponsing
  338. const [suggestQuestions, setSuggestQuestions] = useState<string[]>([])
  339. const [messageTaskId, setMessageTaskId] = useState('')
  340. const [hasStopResponded, setHasStopResponded, getHasStopResponded] = useGetState(false)
  341. const [shouldReload, setShouldReload] = useState(false)
  342. const [visionConfig, setVisionConfig] = useState<VisionSettings>({
  343. enabled: false,
  344. number_limits: 2,
  345. detail: Resolution.low,
  346. transfer_methods: [TransferMethod.local_file],
  347. })
  348. const handleSend = async (message: string, files?: VisionFile[]) => {
  349. if (isResponsing) {
  350. notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
  351. return
  352. }
  353. if (files?.find(item => item.transfer_method === TransferMethod.local_file && !item.upload_file_id)) {
  354. notify({ type: 'info', message: t('appDebug.errorMessage.waitForImgUpload') })
  355. return false
  356. }
  357. const data: Record<string, any> = {
  358. inputs: currInputs,
  359. query: message,
  360. conversation_id: isNewConversation ? null : currConversationId,
  361. }
  362. if (visionConfig.enabled && files && files?.length > 0) {
  363. data.files = files.map((item) => {
  364. if (item.transfer_method === TransferMethod.local_file) {
  365. return {
  366. ...item,
  367. url: '',
  368. }
  369. }
  370. return item
  371. })
  372. }
  373. // qustion
  374. const questionId = `question-${Date.now()}`
  375. const questionItem = {
  376. id: questionId,
  377. content: message,
  378. isAnswer: false,
  379. message_files: files,
  380. }
  381. const placeholderAnswerId = `answer-placeholder-${Date.now()}`
  382. const placeholderAnswerItem = {
  383. id: placeholderAnswerId,
  384. content: '',
  385. isAnswer: true,
  386. }
  387. const newList = [...getChatList(), questionItem, placeholderAnswerItem]
  388. setChatList(newList)
  389. // answer
  390. const responseItem: IChatItem = {
  391. id: `${Date.now()}`,
  392. content: '',
  393. isAnswer: true,
  394. }
  395. let tempNewConversationId = ''
  396. setHasStopResponded(false)
  397. setResponsingTrue()
  398. setIsShowSuggestion(false)
  399. sendChatMessage(data, {
  400. getAbortController: (abortController) => {
  401. setAbortController(abortController)
  402. },
  403. onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {
  404. responseItem.content = responseItem.content + message
  405. responseItem.id = messageId
  406. if (isFirstMessage && newConversationId)
  407. tempNewConversationId = newConversationId
  408. setMessageTaskId(taskId)
  409. // closesure new list is outdated.
  410. const newListWithAnswer = produce(
  411. getChatList().filter(item => item.id !== responseItem.id && item.id !== placeholderAnswerId),
  412. (draft) => {
  413. if (!draft.find(item => item.id === questionId))
  414. draft.push({ ...questionItem })
  415. draft.push({ ...responseItem })
  416. })
  417. setChatList(newListWithAnswer)
  418. },
  419. async onCompleted(hasError?: boolean) {
  420. if (hasError)
  421. return
  422. if (getConversationIdChangeBecauseOfNew()) {
  423. const { data: allConversations }: any = await fetchAllConversations()
  424. const newItem: any = await generationConversationName(isInstalledApp, installedAppInfo?.id, allConversations[0].id)
  425. const newAllConversations = produce(allConversations, (draft: any) => {
  426. draft[0].name = newItem.name
  427. })
  428. setAllConversationList(newAllConversations as any)
  429. noticeUpdateList()
  430. }
  431. setConversationIdChangeBecauseOfNew(false)
  432. resetNewConversationInputs()
  433. setChatNotStarted()
  434. setCurrConversationId(tempNewConversationId, appId, true)
  435. if (suggestedQuestionsAfterAnswerConfig?.enabled && !getHasStopResponded()) {
  436. const { data }: any = await fetchSuggestedQuestions(responseItem.id, isInstalledApp, installedAppInfo?.id)
  437. setSuggestQuestions(data)
  438. setIsShowSuggestion(true)
  439. }
  440. setResponsingFalse()
  441. },
  442. onMessageReplace: (messageReplace) => {
  443. setChatList(produce(
  444. getChatList(),
  445. (draft) => {
  446. const current = draft.find(item => item.id === messageReplace.id)
  447. if (current)
  448. current.content = messageReplace.answer
  449. },
  450. ))
  451. },
  452. onError(errorMessage, errorCode) {
  453. if (['provider_not_initialize', 'completion_request_error'].includes(errorCode as string))
  454. setShouldReload(true)
  455. setResponsingFalse()
  456. // role back placeholder answer
  457. setChatList(produce(getChatList(), (draft) => {
  458. draft.splice(draft.findIndex(item => item.id === placeholderAnswerId), 1)
  459. }))
  460. },
  461. }, isInstalledApp, installedAppInfo?.id)
  462. }
  463. const handleFeedback = async (messageId: string, feedback: Feedbacktype) => {
  464. await updateFeedback({ url: `/messages/${messageId}/feedbacks`, body: { rating: feedback.rating } }, isInstalledApp, installedAppInfo?.id)
  465. const newChatList = chatList.map((item) => {
  466. if (item.id === messageId) {
  467. return {
  468. ...item,
  469. feedback,
  470. }
  471. }
  472. return item
  473. })
  474. setChatList(newChatList)
  475. notify({ type: 'success', message: t('common.api.success') })
  476. }
  477. const handleReload = () => {
  478. setCurrConversationId('-1', appId, false)
  479. setChatNotStarted()
  480. setShouldReload(false)
  481. createNewChat()
  482. }
  483. const handleConversationIdChange = (id: string) => {
  484. if (id === '-1') {
  485. createNewChat()
  486. setConversationIdChangeBecauseOfNew(true)
  487. }
  488. else {
  489. setConversationIdChangeBecauseOfNew(false)
  490. }
  491. // trigger handleConversationSwitch
  492. setCurrConversationId(id, appId)
  493. setIsShowSuggestion(false)
  494. }
  495. const difyIcon = (
  496. <LogoHeader />
  497. )
  498. if (appUnavailable)
  499. return <AppUnavailable isUnknwonReason={isUnknwonReason} />
  500. if (!appId || !siteInfo || !promptConfig) {
  501. return <div className='flex h-screen w-full'>
  502. <Loading type='app' />
  503. </div>
  504. }
  505. return (
  506. <div>
  507. <Header
  508. title={siteInfo.title}
  509. icon=''
  510. customerIcon={difyIcon}
  511. icon_background={siteInfo.icon_background}
  512. isEmbedScene={true}
  513. isMobile={isMobile}
  514. onCreateNewChat={() => handleConversationIdChange('-1')}
  515. />
  516. <div className={'flex bg-white overflow-hidden'}>
  517. <div className={cn(
  518. isInstalledApp ? 'h-full' : 'h-[calc(100vh_-_3rem)]',
  519. 'flex-grow flex flex-col overflow-y-auto',
  520. )
  521. }>
  522. <ConfigScene
  523. // conversationName={conversationName}
  524. hasSetInputs={hasSetInputs}
  525. isPublicVersion={isPublicVersion}
  526. siteInfo={siteInfo}
  527. promptConfig={promptConfig}
  528. onStartChat={handleStartChat}
  529. canEditInputs={canEditInputs}
  530. savedInputs={currInputs as Record<string, any>}
  531. onInputsChange={setCurrInputs}
  532. plan={plan}
  533. canReplaceLogo={canReplaceLogo}
  534. ></ConfigScene>
  535. {
  536. shouldReload && (
  537. <div className='flex items-center justify-between mb-5 px-4 py-2 bg-[#FEF0C7]'>
  538. <div className='flex items-center text-xs font-medium text-[#DC6803]'>
  539. <AlertTriangle className='mr-2 w-4 h-4' />
  540. {t('share.chat.temporarySystemIssue')}
  541. </div>
  542. <div
  543. className='flex items-center px-3 h-7 bg-white shadow-xs rounded-md text-xs font-medium text-gray-700 cursor-pointer'
  544. onClick={handleReload}
  545. >
  546. {t('share.chat.tryToSolve')}
  547. </div>
  548. </div>
  549. )
  550. }
  551. {
  552. hasSetInputs && (
  553. <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')}>
  554. <div className='h-full overflow-y-auto' ref={chatListDomRef}>
  555. <Chat
  556. chatList={chatList}
  557. onSend={handleSend}
  558. isHideFeedbackEdit
  559. onFeedback={handleFeedback}
  560. isResponsing={isResponsing}
  561. canStopResponsing={!!messageTaskId}
  562. abortResponsing={async () => {
  563. await stopChatMessageResponding(appId, messageTaskId, isInstalledApp, installedAppInfo?.id)
  564. setHasStopResponded(true)
  565. setResponsingFalse()
  566. }}
  567. checkCanSend={checkCanSend}
  568. controlFocus={controlFocus}
  569. isShowSuggestion={doShowSuggestion}
  570. suggestionList={suggestQuestions}
  571. displayScene='web'
  572. isShowSpeechToText={speechToTextConfig?.enabled}
  573. answerIcon={<LogoAvatar className='relative shrink-0' />}
  574. visionConfig={visionConfig}
  575. />
  576. </div>
  577. </div>)
  578. }
  579. {/* {isShowConfirm && (
  580. <Confirm
  581. title={t('share.chat.deleteConversation.title')}
  582. content={t('share.chat.deleteConversation.content')}
  583. isShow={isShowConfirm}
  584. onClose={hideConfirm}
  585. onConfirm={didDelete}
  586. onCancel={hideConfirm}
  587. />
  588. )} */}
  589. </div>
  590. </div>
  591. </div>
  592. )
  593. }
  594. export default React.memo(Main)