chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
+392
@@ -0,0 +1,392 @@
|
||||
import type { ReactElement } from 'react'
|
||||
import type { EmbeddedChatbotContextValue } from '../../context'
|
||||
import type { AppData } from '@/models/share'
|
||||
import { act, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { InputVarType } from '@/app/components/workflow/types'
|
||||
import { renderWithConsoleQuery } from '@/test/console/query-data'
|
||||
import { createEmbeddedChatbotContextFixture } from '@/test/fixtures/embedded-chatbot'
|
||||
import { EmbeddedChatbotContext } from '../../context'
|
||||
import Header from '../index'
|
||||
|
||||
let context = createEmbeddedChatbotContextFixture()
|
||||
const setContext = (value: Partial<EmbeddedChatbotContextValue>) => {
|
||||
context = createEmbeddedChatbotContextFixture(value)
|
||||
}
|
||||
let mockBranding = { enabled: true, workspace_logo: '' }
|
||||
const render = (ui: ReactElement) =>
|
||||
renderWithConsoleQuery(
|
||||
<EmbeddedChatbotContext.Provider value={context}>{ui}</EmbeddedChatbotContext.Provider>,
|
||||
{
|
||||
systemFeatures: { branding: { ...mockBranding } },
|
||||
},
|
||||
)
|
||||
|
||||
describe('EmbeddedChatbot Header', () => {
|
||||
const defaultAppData: AppData = {
|
||||
app_id: 'test-app-id',
|
||||
can_replace_logo: true,
|
||||
custom_config: {
|
||||
remove_webapp_brand: false,
|
||||
replace_webapp_logo: '',
|
||||
},
|
||||
enable_site: true,
|
||||
end_user_id: 'test-user-id',
|
||||
site: {
|
||||
title: 'Test Site',
|
||||
},
|
||||
}
|
||||
|
||||
const defaultContext: Partial<EmbeddedChatbotContextValue> = {
|
||||
appData: defaultAppData,
|
||||
currentConversationId: 'test-conv-id',
|
||||
inputsForms: [],
|
||||
allInputsHidden: false,
|
||||
}
|
||||
|
||||
const setupIframe = () => {
|
||||
const mockPostMessage = vi.fn()
|
||||
const mockTop = { postMessage: mockPostMessage }
|
||||
vi.stubGlobal('self', {})
|
||||
vi.stubGlobal('top', mockTop)
|
||||
vi.stubGlobal('parent', mockTop)
|
||||
return mockPostMessage
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockBranding = { enabled: true, workspace_logo: '' }
|
||||
setContext(defaultContext)
|
||||
|
||||
vi.stubGlobal('self', window)
|
||||
vi.stubGlobal('top', window)
|
||||
vi.stubGlobal('parent', window)
|
||||
vi.spyOn(document, 'referrer', 'get').mockReturnValue('')
|
||||
})
|
||||
|
||||
const dispatchChatbotConfigMessage = async (
|
||||
origin: string,
|
||||
payload: { isToggledByButton: boolean; isDraggable: boolean },
|
||||
) => {
|
||||
await act(async () => {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
source: window.parent,
|
||||
origin,
|
||||
data: {
|
||||
type: 'dify-chatbot-config',
|
||||
payload,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
describe('Desktop Rendering', () => {
|
||||
it('should render desktop header with branding by default', async () => {
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
expect(screen.getByText('share.chat.poweredBy')).toBeInTheDocument()
|
||||
expect(screen.getByAltText('Dify')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should render custom logo when provided in appData', () => {
|
||||
setContext({
|
||||
...defaultContext,
|
||||
appData: {
|
||||
...defaultAppData,
|
||||
custom_config: {
|
||||
...defaultAppData.custom_config,
|
||||
replace_webapp_logo: 'https://example.com/logo.png',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
const img = screen.getByAltText('logo')
|
||||
expect(img).toHaveAttribute('src', 'https://example.com/logo.png')
|
||||
})
|
||||
|
||||
it('should render workspace logo when branding is enabled and logo exists', () => {
|
||||
mockBranding = { enabled: true, workspace_logo: 'https://example.com/workspace.png' }
|
||||
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
const img = screen.getByAltText('logo')
|
||||
expect(img).toHaveAttribute('src', 'https://example.com/workspace.png')
|
||||
})
|
||||
|
||||
it('should render Dify logo when branding is disabled', () => {
|
||||
mockBranding = { enabled: false, workspace_logo: '' }
|
||||
render(<Header title="Test Chatbot" />)
|
||||
expect(screen.getByAltText('Dify')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should NOT render branding when remove_webapp_brand is true', () => {
|
||||
setContext({
|
||||
...defaultContext,
|
||||
appData: {
|
||||
...defaultAppData,
|
||||
custom_config: {
|
||||
...defaultAppData.custom_config,
|
||||
remove_webapp_brand: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
expect(screen.queryByText('share.chat.poweredBy')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should call onCreateNewChat when reset button is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onCreateNewChat = vi.fn()
|
||||
render(
|
||||
<Header title="Test Chatbot" allowResetChat={true} onCreateNewChat={onCreateNewChat} />,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'share.chat.resetChat' }))
|
||||
expect(onCreateNewChat).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens settings with actual conversation input values', async () => {
|
||||
const user = userEvent.setup()
|
||||
setContext({
|
||||
...defaultContext,
|
||||
inputsForms: [
|
||||
{ type: InputVarType.textInput, label: 'Topic', variable: 'topic', required: false },
|
||||
],
|
||||
currentConversationInputs: { topic: 'Travel' },
|
||||
allInputsHidden: false,
|
||||
})
|
||||
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'share.chat.viewChatSettings' }),
|
||||
).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'share.chat.viewChatSettings' }))
|
||||
expect(screen.getByRole('textbox', { name: 'Topic' })).toHaveValue('Travel')
|
||||
})
|
||||
|
||||
it('should NOT render ViewFormDropdown when inputs are hidden', () => {
|
||||
setContext({
|
||||
...defaultContext,
|
||||
inputsForms: [
|
||||
{ type: InputVarType.textInput, label: 'Topic', variable: 'topic', required: false },
|
||||
],
|
||||
currentConversationInputs: { topic: 'Travel' },
|
||||
allInputsHidden: true,
|
||||
})
|
||||
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'share.chat.viewChatSettings' }),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should NOT render ViewFormDropdown when currentConversationId is missing', () => {
|
||||
setContext({
|
||||
...defaultContext,
|
||||
currentConversationId: '',
|
||||
inputsForms: [
|
||||
{ type: InputVarType.textInput, label: 'Topic', variable: 'topic', required: false },
|
||||
],
|
||||
currentConversationInputs: { topic: 'Travel' },
|
||||
})
|
||||
|
||||
render(<Header title="Test Chatbot" />)
|
||||
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'share.chat.viewChatSettings' }),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Mobile Rendering', () => {
|
||||
it('should NOT render mobile reset button when currentConversationId is missing', () => {
|
||||
setContext({
|
||||
...defaultContext,
|
||||
currentConversationId: '',
|
||||
})
|
||||
render(<Header title="Mobile Chatbot" isMobile allowResetChat />)
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'share.chat.resetChat' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should handle mobile expand button', async () => {
|
||||
const user = userEvent.setup()
|
||||
const mockPostMessage = setupIframe()
|
||||
render(<Header title="Mobile Chatbot" isMobile />)
|
||||
|
||||
await dispatchChatbotConfigMessage('https://parent.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: false,
|
||||
})
|
||||
|
||||
const expandBtn = await screen.findByRole('button', { name: 'share.chat.expand' })
|
||||
expect(expandBtn).toBeInTheDocument()
|
||||
|
||||
await user.click(expandBtn)
|
||||
expect(mockPostMessage).toHaveBeenCalledWith(
|
||||
{ type: 'dify-chatbot-expand-change' },
|
||||
'https://parent.com',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Iframe Communication', () => {
|
||||
it('should send dify-chatbot-iframe-ready on mount', () => {
|
||||
const mockPostMessage = setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
|
||||
expect(mockPostMessage).toHaveBeenCalledWith({ type: 'dify-chatbot-iframe-ready' }, '*')
|
||||
})
|
||||
|
||||
it('should update expand button visibility and handle click', async () => {
|
||||
const user = userEvent.setup()
|
||||
const mockPostMessage = setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
|
||||
await dispatchChatbotConfigMessage('https://parent.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: false,
|
||||
})
|
||||
|
||||
const expandBtn = await screen.findByRole('button', { name: 'share.chat.expand' })
|
||||
expect(expandBtn).toBeInTheDocument()
|
||||
|
||||
await user.click(expandBtn)
|
||||
|
||||
expect(mockPostMessage).toHaveBeenCalledWith(
|
||||
{ type: 'dify-chatbot-expand-change' },
|
||||
'https://parent.com',
|
||||
)
|
||||
expect(screen.getByRole('button', { name: 'share.chat.collapse' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should NOT show expand button if isDraggable is true', async () => {
|
||||
setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
|
||||
await dispatchChatbotConfigMessage('https://parent.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: true,
|
||||
})
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole('button', { name: 'share.chat.expand' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('should ignore messages from different origins after security lock', async () => {
|
||||
setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
|
||||
await dispatchChatbotConfigMessage('https://secure.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: false,
|
||||
})
|
||||
|
||||
await screen.findByRole('button', { name: 'share.chat.expand' })
|
||||
|
||||
await dispatchChatbotConfigMessage('https://malicious.com', {
|
||||
isToggledByButton: false,
|
||||
isDraggable: false,
|
||||
})
|
||||
|
||||
// Should still be visible (not hidden by the malicious message)
|
||||
expect(screen.getByRole('button', { name: 'share.chat.expand' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should ignore non-config messages for origin locking', async () => {
|
||||
setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
|
||||
await act(async () => {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
origin: 'https://first.com',
|
||||
source: window.parent,
|
||||
data: { type: 'other-type' },
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
await dispatchChatbotConfigMessage('https://second.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: false,
|
||||
})
|
||||
|
||||
// Should lock to second.com
|
||||
const expandBtn = await screen.findByRole('button', { name: 'share.chat.expand' })
|
||||
expect(expandBtn).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Edge Cases', () => {
|
||||
it('should handle document.referrer for targetOrigin', () => {
|
||||
const mockPostMessage = setupIframe()
|
||||
vi.spyOn(document, 'referrer', 'get').mockReturnValue('https://referrer.com')
|
||||
render(<Header title="Referrer" />)
|
||||
|
||||
expect(mockPostMessage).toHaveBeenCalledWith(expect.anything(), 'https://referrer.com')
|
||||
})
|
||||
|
||||
it('should NOT add message listener if not in iframe', () => {
|
||||
const addSpy = vi.spyOn(window, 'addEventListener')
|
||||
render(<Header title="Direct" />)
|
||||
expect(addSpy).not.toHaveBeenCalledWith('message', expect.any(Function))
|
||||
})
|
||||
})
|
||||
it.each([
|
||||
null,
|
||||
{},
|
||||
{ type: 'dify-chatbot-config' },
|
||||
{ type: 'dify-chatbot-config', payload: null },
|
||||
])('ignores malformed messages without locking the parent origin: %j', async (data) => {
|
||||
setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
act(() =>
|
||||
window.dispatchEvent(
|
||||
new MessageEvent('message', { origin: 'https://invalid.com', source: window.parent, data }),
|
||||
),
|
||||
)
|
||||
await dispatchChatbotConfigMessage('https://parent.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: false,
|
||||
})
|
||||
expect(screen.getByRole('button', { name: 'share.chat.expand' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ignores config messages from another frame before accepting the parent', async () => {
|
||||
setupIframe()
|
||||
render(<Header title="Iframe" />)
|
||||
act(() =>
|
||||
window.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
origin: 'https://other.com',
|
||||
source: window,
|
||||
data: {
|
||||
type: 'dify-chatbot-config',
|
||||
payload: { isToggledByButton: true, isDraggable: false },
|
||||
},
|
||||
}),
|
||||
),
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: 'share.chat.expand' })).not.toBeInTheDocument()
|
||||
await dispatchChatbotConfigMessage('https://parent.com', {
|
||||
isToggledByButton: true,
|
||||
isDraggable: false,
|
||||
})
|
||||
expect(screen.getByRole('button', { name: 'share.chat.expand' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,257 @@
|
||||
import type { FC } from 'react'
|
||||
import type { Theme } from '../theme/theme'
|
||||
import { cn } from '@langgenius/dify-ui/cn'
|
||||
import { IconButton } from '@langgenius/dify-ui/icon-button'
|
||||
import { Separator } from '@langgenius/dify-ui/separator'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
|
||||
import { useSuspenseQuery } from '@tanstack/react-query'
|
||||
import * as React from 'react'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import ViewFormDropdown from '@/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown'
|
||||
import { DifyLogo } from '@/app/components/base/logo/dify-logo'
|
||||
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
|
||||
import { isClient } from '@/utils/client'
|
||||
import { useEmbeddedChatbotContext } from '../context'
|
||||
import { CssTransform } from '../theme/utils'
|
||||
|
||||
type IHeaderProps = {
|
||||
isMobile?: boolean
|
||||
allowResetChat?: boolean
|
||||
customerIcon?: React.ReactNode
|
||||
title: string
|
||||
theme?: Theme
|
||||
onCreateNewChat?: () => void
|
||||
}
|
||||
const Header: FC<IHeaderProps> = ({
|
||||
isMobile,
|
||||
allowResetChat,
|
||||
customerIcon,
|
||||
title,
|
||||
theme,
|
||||
onCreateNewChat,
|
||||
}) => {
|
||||
const { t } = useTranslation(['share'])
|
||||
const { appData, currentConversationId, inputsForms, allInputsHidden } =
|
||||
useEmbeddedChatbotContext()
|
||||
|
||||
const isIframe = isClient ? window.self !== window.top : false
|
||||
const [parentOrigin, setParentOrigin] = useState('')
|
||||
const [showToggleExpandButton, setShowToggleExpandButton] = useState(false)
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions())
|
||||
|
||||
const handleMessageReceived = useCallback(
|
||||
(event: MessageEvent) => {
|
||||
if (event.source !== window.parent || event.data?.type !== 'dify-chatbot-config') return
|
||||
const payload = event.data.payload
|
||||
if (
|
||||
typeof payload?.isToggledByButton !== 'boolean' ||
|
||||
typeof payload?.isDraggable !== 'boolean'
|
||||
)
|
||||
return
|
||||
let currentParentOrigin = parentOrigin
|
||||
if (!currentParentOrigin && event.data.type === 'dify-chatbot-config') {
|
||||
currentParentOrigin = event.origin
|
||||
setParentOrigin(event.origin)
|
||||
}
|
||||
if (event.origin !== currentParentOrigin) return
|
||||
if (event.data.type === 'dify-chatbot-config')
|
||||
setShowToggleExpandButton(
|
||||
event.data.payload.isToggledByButton && !event.data.payload.isDraggable,
|
||||
)
|
||||
},
|
||||
[parentOrigin],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isIframe) return
|
||||
|
||||
const listener = (event: MessageEvent) => handleMessageReceived(event)
|
||||
window.addEventListener('message', listener)
|
||||
|
||||
// Security: Use document.referrer to get parent origin
|
||||
const targetOrigin = document.referrer ? new URL(document.referrer).origin : '*'
|
||||
window.parent.postMessage({ type: 'dify-chatbot-iframe-ready' }, targetOrigin)
|
||||
|
||||
return () => window.removeEventListener('message', listener)
|
||||
}, [isIframe, handleMessageReceived])
|
||||
|
||||
const handleToggleExpand = useCallback(() => {
|
||||
if (!isIframe || !showToggleExpandButton) return
|
||||
setExpanded(!expanded)
|
||||
window.parent.postMessage(
|
||||
{
|
||||
type: 'dify-chatbot-expand-change',
|
||||
},
|
||||
parentOrigin,
|
||||
)
|
||||
}, [isIframe, parentOrigin, showToggleExpandButton, expanded])
|
||||
|
||||
if (!isMobile) {
|
||||
return (
|
||||
<div className="flex h-14 shrink-0 items-center justify-end p-3">
|
||||
<div className="flex items-center gap-1">
|
||||
{/* powered by */}
|
||||
<div className="shrink-0">
|
||||
{!appData?.custom_config?.remove_webapp_brand && (
|
||||
<div className={cn('flex shrink-0 items-center gap-1.5 px-2')}>
|
||||
{systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo ? (
|
||||
<img
|
||||
src={systemFeatures.branding.workspace_logo}
|
||||
alt="甘肃省房地产价格评估行业协会"
|
||||
className="block h-5 w-auto"
|
||||
/>
|
||||
) : appData?.custom_config?.replace_webapp_logo ? (
|
||||
<img
|
||||
src={`${appData?.custom_config?.replace_webapp_logo}`}
|
||||
alt="甘肃省房地产价格评估行业协会"
|
||||
className="block h-5 w-auto"
|
||||
/>
|
||||
) : (
|
||||
<DifyLogo alt="甘肃省房地产价格评估行业协会" size="small" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{currentConversationId && (
|
||||
<Separator decorative orientation="vertical" className="mx-2 h-3.5" />
|
||||
)}
|
||||
{showToggleExpandButton && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<IconButton
|
||||
size="lg"
|
||||
aria-label={
|
||||
expanded
|
||||
? t(($) => $['chat.collapse'], { ns: 'share' })
|
||||
: t(($) => $['chat.expand'], { ns: 'share' })
|
||||
}
|
||||
onClick={handleToggleExpand}
|
||||
>
|
||||
{expanded ? (
|
||||
<div
|
||||
className="i-ri-collapse-diagonal-2-line h-4.5 w-4.5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : (
|
||||
<div className="i-ri-expand-diagonal-2-line h-4.5 w-4.5" aria-hidden="true" />
|
||||
)}
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
<TooltipContent>
|
||||
{expanded
|
||||
? t(($) => $['chat.collapse'], { ns: 'share' })
|
||||
: t(($) => $['chat.expand'], { ns: 'share' })}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
{currentConversationId && allowResetChat && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<IconButton
|
||||
size="lg"
|
||||
aria-label={t(($) => $['chat.resetChat'], { ns: 'share' })}
|
||||
onClick={onCreateNewChat}
|
||||
>
|
||||
<div className="i-ri-reset-left-line h-4.5 w-4.5" aria-hidden="true" />
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
<TooltipContent>{t(($) => $['chat.resetChat'], { ns: 'share' })}</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
{currentConversationId && inputsForms.length > 0 && !allInputsHidden && (
|
||||
<ViewFormDropdown />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn('flex h-14 shrink-0 items-center justify-between rounded-t-2xl px-3')}
|
||||
style={CssTransform(theme?.headerBorderBottomStyle ?? '')}
|
||||
>
|
||||
<div className="flex grow items-center space-x-3">
|
||||
{customerIcon}
|
||||
<div
|
||||
className="truncate system-md-semibold"
|
||||
style={CssTransform(theme?.colorFontOnHeaderStyle ?? '')}
|
||||
>
|
||||
{title}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
{showToggleExpandButton && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<IconButton
|
||||
size="lg"
|
||||
aria-label={
|
||||
expanded
|
||||
? t(($) => $['chat.collapse'], { ns: 'share' })
|
||||
: t(($) => $['chat.expand'], { ns: 'share' })
|
||||
}
|
||||
onClick={handleToggleExpand}
|
||||
>
|
||||
{expanded ? (
|
||||
<div
|
||||
className={cn(
|
||||
'i-ri-collapse-diagonal-2-line h-4.5 w-4.5',
|
||||
theme?.colorPathOnHeader,
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className={cn(
|
||||
'i-ri-expand-diagonal-2-line h-4.5 w-4.5',
|
||||
theme?.colorPathOnHeader,
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
<TooltipContent>
|
||||
{expanded
|
||||
? t(($) => $['chat.collapse'], { ns: 'share' })
|
||||
: t(($) => $['chat.expand'], { ns: 'share' })}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
{currentConversationId && allowResetChat && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<IconButton
|
||||
size="lg"
|
||||
aria-label={t(($) => $['chat.resetChat'], { ns: 'share' })}
|
||||
onClick={onCreateNewChat}
|
||||
>
|
||||
<div
|
||||
className={cn('i-ri-reset-left-line h-4.5 w-4.5', theme?.colorPathOnHeader)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
<TooltipContent>{t(($) => $['chat.resetChat'], { ns: 'share' })}</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
{currentConversationId && inputsForms.length > 0 && !allInputsHidden && (
|
||||
<ViewFormDropdown iconColor={theme?.colorPathOnHeader} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default React.memo(Header)
|
||||
Reference in new issue
Block a user