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

View File

@ -16,6 +16,7 @@ import cn from '@/utils/classnames'
export type IHeaderProps = {
isMobile?: boolean
allowResetChat?: boolean
customerIcon?: React.ReactNode
title: string
theme?: Theme
@ -23,6 +24,7 @@ export type IHeaderProps = {
}
const Header: FC<IHeaderProps> = ({
isMobile,
allowResetChat,
customerIcon,
title,
theme,
@ -57,7 +59,7 @@ const Header: FC<IHeaderProps> = ({
{currentConversationId && (
<Divider type='vertical' className='h-3.5' />
)}
{currentConversationId && (
{currentConversationId && allowResetChat && (
<Tooltip
popupContent={t('share.chat.resetChat')}
>
@ -89,7 +91,7 @@ const Header: FC<IHeaderProps> = ({
</div>
</div>
<div className='flex items-center gap-1'>
{currentConversationId && (
{currentConversationId && allowResetChat && (
<Tooltip
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, {
defaultValue: {},
})
const allowResetChat = !conversationId
const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '',
[appId, conversationIdInfo, userId, conversationId])
const handleConversationIdInfoChange = useCallback((changeConversationId: string) => {
@ -365,6 +366,7 @@ export const useEmbeddedChatbot = () => {
appInfoError,
appInfoLoading,
isInstalledApp,
allowResetChat,
appId,
currentConversationId,
currentConversationItem,

View File

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