diff --git a/web/app/components/share/chatbot/index.tsx b/web/app/components/share/chatbot/index.tsx index 5f72c37593..5602294c42 100644 --- a/web/app/components/share/chatbot/index.tsx +++ b/web/app/components/share/chatbot/index.tsx @@ -12,13 +12,12 @@ import AppUnavailable from '../../base/app-unavailable' import useConversation from './hooks/use-conversation' import s from './style.module.css' import { ToastContext } from '@/app/components/base/toast' -import Sidebar from '@/app/components/share/chatbot/sidebar' import ConfigScene from '@/app/components/share/chatbot/config-scence' import Header from '@/app/components/share/header' -import { /* delConversation, */ fetchAppInfo, fetchAppParams, fetchChatList, fetchConversations, fetchSuggestedQuestions, pinConversation, sendChatMessage, stopChatMessageResponding, unpinConversation, updateFeedback } from '@/service/share' +import { fetchAppInfo, fetchAppParams, fetchChatList, fetchConversations, fetchSuggestedQuestions, sendChatMessage, stopChatMessageResponding, updateFeedback } from '@/service/share' import type { ConversationItem, SiteInfo } from '@/models/share' import type { PromptConfig, SuggestedQuestionsAfterAnswerConfig } from '@/models/debug' -import type { Feedbacktype, IChatItem } from '@/app/components/app/chat' +import type { Feedbacktype, IChatItem } from '@/app/components/app/chat/type' import Chat from '@/app/components/app/chat' import { changeLanguage } from '@/i18n/i18next-config' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' @@ -26,7 +25,7 @@ import Loading from '@/app/components/base/loading' import { replaceStringWithValues } from '@/app/components/app/configuration/prompt-value-panel' import { userInputsFormToPromptVariables } from '@/utils/model-config' import type { InstalledApp } from '@/models/explore' -// import Confirm from '@/app/components/base/confirm' +import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback' export type IMainProps = { isInstalledApp?: boolean @@ -52,8 +51,6 @@ const Main: FC = ({ const [promptConfig, setPromptConfig] = useState(null) const [inited, setInited] = useState(false) const [plan, setPlan] = useState('basic') // basic/plus/pro - // in mobile, show sidebar by click button - const [isShowSidebar, { setTrue: showSidebar, setFalse: hideSidebar }] = useBoolean(false) // Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client. useEffect(() => { if (siteInfo?.title) { @@ -124,37 +121,6 @@ const Main: FC = ({ setControlUpdateConversationList(Date.now()) } - - const handlePin = async (id: string) => { - await pinConversation(isInstalledApp, installedAppInfo?.id, id) - notify({ type: 'success', message: t('common.api.success') }) - noticeUpdateList() - } - - const handleUnpin = async (id: string) => { - await unpinConversation(isInstalledApp, installedAppInfo?.id, id) - notify({ type: 'success', message: t('common.api.success') }) - noticeUpdateList() - } - const [isShowConfirm, { setTrue: showConfirm, setFalse: hideConfirm }] = useBoolean(false) - const [toDeleteConversationId, setToDeleteConversationId] = useState('') - - const handleDelete = (id: string) => { - setToDeleteConversationId(id) - hideSidebar() // mobile - showConfirm() - } - - // const didDelete = async () => { - // await delConversation(isInstalledApp, installedAppInfo?.id, toDeleteConversationId) - // notify({ type: 'success', message: t('common.api.success') }) - // hideConfirm() - // if (currConversationId === toDeleteConversationId) - // handleConversationIdChange('-1') - - // noticeUpdateList() - // } - const [suggestedQuestionsAfterAnswerConfig, setSuggestedQuestionsAfterAnswerConfig] = useState(null) const [speechToTextConfig, setSpeechToTextConfig] = useState(null) @@ -235,20 +201,6 @@ const Main: FC = ({ } useEffect(handleConversationSwitch, [currConversationId, inited]) - const handleConversationIdChange = (id: string) => { - if (id === '-1') { - createNewChat() - setConversationIdChangeBecauseOfNew(true) - } - else { - setConversationIdChangeBecauseOfNew(false) - } - // trigger handleConversationSwitch - setCurrConversationId(id, appId) - setIsShowSuggestion(false) - hideSidebar() - } - /* * chat info. chat is under conversation. */ @@ -416,6 +368,7 @@ const Main: FC = ({ const [suggestQuestions, setSuggestQuestions] = useState([]) const [messageTaskId, setMessageTaskId] = useState('') const [hasStopResponded, setHasStopResponded, getHasStopResponded] = useGetState(false) + const [shouldReload, setShouldReload] = useState(false) const handleSend = async (message: string) => { if (isResponsing) { @@ -500,7 +453,9 @@ const Main: FC = ({ setIsShowSuggestion(true) } }, - onError() { + onError(errorMessage, errorCode) { + if (['provider_not_initialize', 'completion_request_error'].includes(errorCode as string)) + setShouldReload(true) setResponsingFalse() // role back placeholder answer setChatList(produce(getChatList(), (draft) => { @@ -525,31 +480,11 @@ const Main: FC = ({ notify({ type: 'success', message: t('common.api.success') }) } - const renderSidebar = () => { - if (!appId || !siteInfo || !promptConfig) - return null - return ( - - ) + const handleReload = () => { + setCurrConversationId('-1', appId, false) + setChatNotStarted() + setShouldReload(false) + createNewChat() } const difyIcon = ( @@ -571,24 +506,9 @@ const Main: FC = ({ icon_background={siteInfo.icon_background} isEmbedScene={true} isMobile={isMobile} - // onShowSideBar={showSidebar} - // onCreateNewChat={() => handleConversationIdChange('-1')} />
- {/* sidebar */} - {/* {!isMobile && renderSidebar()} */} - {/* {isMobile && isShowSidebar && ( -
-
e.stopPropagation()}> - {renderSidebar()} -
-
- )} */} - {/* main */}
= ({ onInputsChange={setCurrInputs} plan={plan} > - + { + shouldReload && ( +
+
+ + {t('share.chat.temporarySystemIssue')} +
+
+ {t('share.chat.tryToSolve')} +
+
+ ) + } { hasSetInputs && (
diff --git a/web/i18n/lang/share-app.en.ts b/web/i18n/lang/share-app.en.ts index c717865c4d..f621bddfa2 100644 --- a/web/i18n/lang/share-app.en.ts +++ b/web/i18n/lang/share-app.en.ts @@ -27,6 +27,8 @@ const translation = { title: 'Delete conversation', content: 'Are you sure you want to delete this conversation?', }, + tryToSolve: 'Try to solve', + temporarySystemIssue: 'Sorry, temporary system issue.', }, generation: { tabs: { diff --git a/web/i18n/lang/share-app.zh.ts b/web/i18n/lang/share-app.zh.ts index 4f4c1966ff..6ed563b3f7 100644 --- a/web/i18n/lang/share-app.zh.ts +++ b/web/i18n/lang/share-app.zh.ts @@ -23,6 +23,8 @@ const translation = { title: '删除对话', content: '您确定要删除此对话吗?', }, + tryToSolve: '尝试解决', + temporarySystemIssue: '抱歉,临时系统问题。', }, generation: { tabs: { diff --git a/web/service/base.ts b/web/service/base.ts index 74dacb3148..c7cc4c2212 100644 --- a/web/service/base.ts +++ b/web/service/base.ts @@ -28,12 +28,13 @@ export type IOnDataMoreInfo = { taskId?: string messageId: string errorMessage?: string + errorCode?: string } export type IOnData = (message: string, isFirstMessage: boolean, moreInfo: IOnDataMoreInfo) => void export type IOnThought = (though: ThoughtItem) => void export type IOnCompleted = (hasError?: boolean) => void -export type IOnError = (msg: string) => void +export type IOnError = (msg: string, code?: string) => void type IOtherOptions = { isPublicAPI?: boolean @@ -102,6 +103,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted conversationId: undefined, messageId: '', errorMessage: bufferObj.message, + errorCode: bufferObj.code, }) hasError = true onCompleted && onCompleted(true) @@ -345,7 +347,7 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o return handleStream(res, (str: string, isFirstMessage: boolean, moreInfo: IOnDataMoreInfo) => { if (moreInfo.errorMessage) { // debugger - onError?.(moreInfo.errorMessage) + onError?.(moreInfo.errorMessage, moreInfo.errorCode) if (moreInfo.errorMessage !== 'AbortError: The user aborted a request.') Toast.notify({ type: 'error', message: moreInfo.errorMessage }) return