embedding in websites setting conversation_id requires hiding reset conversation button (#18623)

This commit is contained in:
Junjie.M 2025-04-23 22:57:42 +08:00 committed by GitHub
parent c479fcf251
commit b203139356
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 2 deletions

View File

@ -39,6 +39,7 @@ export type EmbeddedChatbotContextValue = {
chatShouldReloadKey: string chatShouldReloadKey: string
isMobile: boolean isMobile: boolean
isInstalledApp: boolean isInstalledApp: boolean
allowResetChat: boolean
appId?: string appId?: string
handleFeedback: (messageId: string, feedback: Feedback) => void handleFeedback: (messageId: string, feedback: Feedback) => void
currentChatInstanceRef: RefObject<{ handleStop: () => void }> currentChatInstanceRef: RefObject<{ handleStop: () => void }>
@ -67,6 +68,7 @@ export const EmbeddedChatbotContext = createContext<EmbeddedChatbotContextValue>
chatShouldReloadKey: '', chatShouldReloadKey: '',
isMobile: false, isMobile: false,
isInstalledApp: false, isInstalledApp: false,
allowResetChat: true,
handleFeedback: noop, handleFeedback: noop,
currentChatInstanceRef: { current: { handleStop: noop } }, currentChatInstanceRef: { current: { handleStop: noop } },
clearChatList: false, clearChatList: false,

View File

@ -16,6 +16,7 @@ import cn from '@/utils/classnames'
export type IHeaderProps = { export type IHeaderProps = {
isMobile?: boolean isMobile?: boolean
allowResetChat?: boolean
customerIcon?: React.ReactNode customerIcon?: React.ReactNode
title: string title: string
theme?: Theme theme?: Theme
@ -23,6 +24,7 @@ export type IHeaderProps = {
} }
const Header: FC<IHeaderProps> = ({ const Header: FC<IHeaderProps> = ({
isMobile, isMobile,
allowResetChat,
customerIcon, customerIcon,
title, title,
theme, theme,
@ -57,7 +59,7 @@ const Header: FC<IHeaderProps> = ({
{currentConversationId && ( {currentConversationId && (
<Divider type='vertical' className='h-3.5' /> <Divider type='vertical' className='h-3.5' />
)} )}
{currentConversationId && ( {currentConversationId && allowResetChat && (
<Tooltip <Tooltip
popupContent={t('share.chat.resetChat')} popupContent={t('share.chat.resetChat')}
> >
@ -89,7 +91,7 @@ const Header: FC<IHeaderProps> = ({
</div> </div>
</div> </div>
<div className='flex items-center gap-1'> <div className='flex items-center gap-1'>
{currentConversationId && ( {currentConversationId && allowResetChat && (
<Tooltip <Tooltip
popupContent={t('share.chat.resetChat')} popupContent={t('share.chat.resetChat')}
> >

View File

@ -111,6 +111,7 @@ export const useEmbeddedChatbot = () => {
const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState<Record<string, Record<string, string>>>(CONVERSATION_ID_INFO, { const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState<Record<string, Record<string, string>>>(CONVERSATION_ID_INFO, {
defaultValue: {}, defaultValue: {},
}) })
const allowResetChat = !conversationId
const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '', const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '',
[appId, conversationIdInfo, userId, conversationId]) [appId, conversationIdInfo, userId, conversationId])
const handleConversationIdInfoChange = useCallback((changeConversationId: string) => { const handleConversationIdInfoChange = useCallback((changeConversationId: string) => {
@ -365,6 +366,7 @@ export const useEmbeddedChatbot = () => {
appInfoError, appInfoError,
appInfoLoading, appInfoLoading,
isInstalledApp, isInstalledApp,
allowResetChat,
appId, appId,
currentConversationId, currentConversationId,
currentConversationItem, currentConversationItem,

View File

@ -25,6 +25,7 @@ import cn from '@/utils/classnames'
const Chatbot = () => { const Chatbot = () => {
const { const {
isMobile, isMobile,
allowResetChat,
appInfoError, appInfoError,
appInfoLoading, appInfoLoading,
appData, appData,
@ -90,6 +91,7 @@ const Chatbot = () => {
> >
<Header <Header
isMobile={isMobile} isMobile={isMobile}
allowResetChat={allowResetChat}
title={site?.title || ''} title={site?.title || ''}
customerIcon={isDify() ? difyIcon : ''} customerIcon={isDify() ? difyIcon : ''}
theme={themeBuilder?.theme} theme={themeBuilder?.theme}
@ -153,6 +155,7 @@ const EmbeddedChatbotWrapper = () => {
handleNewConversationCompleted, handleNewConversationCompleted,
chatShouldReloadKey, chatShouldReloadKey,
isInstalledApp, isInstalledApp,
allowResetChat,
appId, appId,
handleFeedback, handleFeedback,
currentChatInstanceRef, currentChatInstanceRef,
@ -187,6 +190,7 @@ const EmbeddedChatbotWrapper = () => {
chatShouldReloadKey, chatShouldReloadKey,
isMobile, isMobile,
isInstalledApp, isInstalledApp,
allowResetChat,
appId, appId,
handleFeedback, handleFeedback,
currentChatInstanceRef, currentChatInstanceRef,