index.tsx 23 KB

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