mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
chore: chat input and feature readonly
This commit is contained in:
parent
df4e32aaa0
commit
738d3001be
@ -39,6 +39,7 @@ const DebugWithSingleModel = (
|
|||||||
) => {
|
) => {
|
||||||
const { userProfile } = useAppContext()
|
const { userProfile } = useAppContext()
|
||||||
const {
|
const {
|
||||||
|
readonly,
|
||||||
modelConfig,
|
modelConfig,
|
||||||
appId,
|
appId,
|
||||||
inputs,
|
inputs,
|
||||||
@ -154,6 +155,7 @@ const DebugWithSingleModel = (
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Chat
|
<Chat
|
||||||
|
readonly={readonly}
|
||||||
config={config}
|
config={config}
|
||||||
chatList={chatList}
|
chatList={chatList}
|
||||||
isResponding={isResponding}
|
isResponding={isResponding}
|
||||||
|
|||||||
@ -50,13 +50,14 @@ function getActionButtonState(state: ActionButtonState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ActionButton = ({ className, size, state = ActionButtonState.Default, styleCss, children, ref, ...props }: ActionButtonProps) => {
|
const ActionButton = ({ className, size, state = ActionButtonState.Default, styleCss, children, ref, disabled, ...props }: ActionButtonProps) => {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
className={classNames(
|
className={classNames(
|
||||||
actionButtonVariants({ className, size }),
|
actionButtonVariants({ className, size }),
|
||||||
getActionButtonState(state),
|
getActionButtonState(state),
|
||||||
|
disabled && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled',
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
style={styleCss}
|
style={styleCss}
|
||||||
|
|||||||
@ -27,8 +27,10 @@ import { useToastContext } from '@/app/components/base/toast'
|
|||||||
import FeatureBar from '@/app/components/base/features/new-feature-panel/feature-bar'
|
import FeatureBar from '@/app/components/base/features/new-feature-panel/feature-bar'
|
||||||
import type { FileUpload } from '@/app/components/base/features/types'
|
import type { FileUpload } from '@/app/components/base/features/types'
|
||||||
import { TransferMethod } from '@/types/app'
|
import { TransferMethod } from '@/types/app'
|
||||||
|
import { noop } from 'lodash-es'
|
||||||
|
|
||||||
type ChatInputAreaProps = {
|
type ChatInputAreaProps = {
|
||||||
|
readonly?: boolean
|
||||||
botName?: string
|
botName?: string
|
||||||
showFeatureBar?: boolean
|
showFeatureBar?: boolean
|
||||||
showFileUpload?: boolean
|
showFileUpload?: boolean
|
||||||
@ -44,6 +46,7 @@ type ChatInputAreaProps = {
|
|||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
const ChatInputArea = ({
|
const ChatInputArea = ({
|
||||||
|
readonly,
|
||||||
botName,
|
botName,
|
||||||
showFeatureBar,
|
showFeatureBar,
|
||||||
showFileUpload,
|
showFileUpload,
|
||||||
@ -159,6 +162,7 @@ const ChatInputArea = ({
|
|||||||
const operation = (
|
const operation = (
|
||||||
<Operation
|
<Operation
|
||||||
ref={holdSpaceRef}
|
ref={holdSpaceRef}
|
||||||
|
readonly={readonly}
|
||||||
fileConfig={visionConfig}
|
fileConfig={visionConfig}
|
||||||
speechToTextConfig={speechToTextConfig}
|
speechToTextConfig={speechToTextConfig}
|
||||||
onShowVoiceInput={handleShowVoiceInput}
|
onShowVoiceInput={handleShowVoiceInput}
|
||||||
@ -194,7 +198,7 @@ const ChatInputArea = ({
|
|||||||
className={cn(
|
className={cn(
|
||||||
'body-lg-regular w-full resize-none bg-transparent p-1 leading-6 text-text-primary outline-none',
|
'body-lg-regular w-full resize-none bg-transparent p-1 leading-6 text-text-primary outline-none',
|
||||||
)}
|
)}
|
||||||
placeholder={t('common.chat.inputPlaceholder', { botName }) || ''}
|
placeholder={readonly ? t('common.chat.inputDisabledPlaceholder') : t('common.chat.inputPlaceholder', { botName }) || ''}
|
||||||
autoFocus
|
autoFocus
|
||||||
minRows={1}
|
minRows={1}
|
||||||
onResize={handleTextareaResize}
|
onResize={handleTextareaResize}
|
||||||
@ -211,6 +215,7 @@ const ChatInputArea = ({
|
|||||||
onDragLeave={handleDragFileLeave}
|
onDragLeave={handleDragFileLeave}
|
||||||
onDragOver={handleDragFileOver}
|
onDragOver={handleDragFileOver}
|
||||||
onDrop={handleDropFile}
|
onDrop={handleDropFile}
|
||||||
|
readOnly={readonly}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
@ -232,7 +237,12 @@ const ChatInputArea = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{showFeatureBar && <FeatureBar showFileUpload={showFileUpload} disabled={featureBarDisabled} onFeatureBarClick={onFeatureBarClick} />}
|
{showFeatureBar && <FeatureBar
|
||||||
|
showFileUpload={showFileUpload}
|
||||||
|
disabled={featureBarDisabled}
|
||||||
|
onFeatureBarClick={readonly ? noop : onFeatureBarClick}
|
||||||
|
hideEditEntrance={readonly}
|
||||||
|
/>}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,10 @@ import ActionButton from '@/app/components/base/action-button'
|
|||||||
import { FileUploaderInChatInput } from '@/app/components/base/file-uploader'
|
import { FileUploaderInChatInput } from '@/app/components/base/file-uploader'
|
||||||
import type { FileUpload } from '@/app/components/base/features/types'
|
import type { FileUpload } from '@/app/components/base/features/types'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
import { noop } from 'lodash'
|
||||||
|
|
||||||
type OperationProps = {
|
type OperationProps = {
|
||||||
|
readonly?: boolean
|
||||||
fileConfig?: FileUpload
|
fileConfig?: FileUpload
|
||||||
speechToTextConfig?: EnableType
|
speechToTextConfig?: EnableType
|
||||||
onShowVoiceInput?: () => void
|
onShowVoiceInput?: () => void
|
||||||
@ -22,6 +24,7 @@ type OperationProps = {
|
|||||||
}
|
}
|
||||||
const Operation = (
|
const Operation = (
|
||||||
{
|
{
|
||||||
|
readonly,
|
||||||
ref,
|
ref,
|
||||||
fileConfig,
|
fileConfig,
|
||||||
speechToTextConfig,
|
speechToTextConfig,
|
||||||
@ -43,12 +46,13 @@ const Operation = (
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
>
|
>
|
||||||
<div className='flex items-center space-x-1'>
|
<div className='flex items-center space-x-1'>
|
||||||
{fileConfig?.enabled && <FileUploaderInChatInput fileConfig={fileConfig} />}
|
{fileConfig?.enabled && <FileUploaderInChatInput readonly={readonly} fileConfig={fileConfig} />}
|
||||||
{
|
{
|
||||||
speechToTextConfig?.enabled && (
|
speechToTextConfig?.enabled && (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
size='l'
|
size='l'
|
||||||
onClick={onShowVoiceInput}
|
disabled={readonly}
|
||||||
|
onClick={readonly ? noop : onShowVoiceInput}
|
||||||
>
|
>
|
||||||
<RiMicLine className='h-5 w-5' />
|
<RiMicLine className='h-5 w-5' />
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
@ -58,7 +62,8 @@ const Operation = (
|
|||||||
<Button
|
<Button
|
||||||
className='ml-3 w-8 px-0'
|
className='ml-3 w-8 px-0'
|
||||||
variant='primary'
|
variant='primary'
|
||||||
onClick={onSend}
|
onClick={readonly ? noop : onSend}
|
||||||
|
disabled={readonly}
|
||||||
style={
|
style={
|
||||||
theme
|
theme
|
||||||
? {
|
? {
|
||||||
|
|||||||
@ -17,10 +17,13 @@ export type ChatContextValue = Pick<ChatProps, 'config'
|
|||||||
| 'onAnnotationRemoved'
|
| 'onAnnotationRemoved'
|
||||||
| 'disableFeedback'
|
| 'disableFeedback'
|
||||||
| 'onFeedback'
|
| 'onFeedback'
|
||||||
>
|
> & {
|
||||||
|
readonly?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
const ChatContext = createContext<ChatContextValue>({
|
const ChatContext = createContext<ChatContextValue>({
|
||||||
chatList: [],
|
chatList: [],
|
||||||
|
readonly: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
type ChatContextProviderProps = {
|
type ChatContextProviderProps = {
|
||||||
@ -29,6 +32,7 @@ type ChatContextProviderProps = {
|
|||||||
|
|
||||||
export const ChatContextProvider = ({
|
export const ChatContextProvider = ({
|
||||||
children,
|
children,
|
||||||
|
readonly = false,
|
||||||
config,
|
config,
|
||||||
isResponding,
|
isResponding,
|
||||||
chatList,
|
chatList,
|
||||||
@ -46,6 +50,7 @@ export const ChatContextProvider = ({
|
|||||||
return (
|
return (
|
||||||
<ChatContext.Provider value={{
|
<ChatContext.Provider value={{
|
||||||
config,
|
config,
|
||||||
|
readonly,
|
||||||
isResponding,
|
isResponding,
|
||||||
chatList: chatList || [],
|
chatList: chatList || [],
|
||||||
showPromptLog,
|
showPromptLog,
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import { useStore as useAppStore } from '@/app/components/app/store'
|
|||||||
import type { AppData } from '@/models/share'
|
import type { AppData } from '@/models/share'
|
||||||
|
|
||||||
export type ChatProps = {
|
export type ChatProps = {
|
||||||
|
readonly?: boolean
|
||||||
appData?: AppData
|
appData?: AppData
|
||||||
chatList: ChatItem[]
|
chatList: ChatItem[]
|
||||||
config?: ChatConfig
|
config?: ChatConfig
|
||||||
@ -77,6 +78,7 @@ export type ChatProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Chat: FC<ChatProps> = ({
|
const Chat: FC<ChatProps> = ({
|
||||||
|
readonly = false,
|
||||||
appData,
|
appData,
|
||||||
config,
|
config,
|
||||||
onSend,
|
onSend,
|
||||||
@ -221,6 +223,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ChatContextProvider
|
<ChatContextProvider
|
||||||
|
readonly={readonly}
|
||||||
config={config}
|
config={config}
|
||||||
chatList={chatList}
|
chatList={chatList}
|
||||||
isResponding={isResponding}
|
isResponding={isResponding}
|
||||||
@ -324,6 +327,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
inputsForm={inputsForm}
|
inputsForm={inputsForm}
|
||||||
theme={themeBuilder?.theme}
|
theme={themeBuilder?.theme}
|
||||||
isResponding={isResponding}
|
isResponding={isResponding}
|
||||||
|
readonly={readonly}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ type Props = {
|
|||||||
showFileUpload?: boolean
|
showFileUpload?: boolean
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
onFeatureBarClick?: (state: boolean) => void
|
onFeatureBarClick?: (state: boolean) => void
|
||||||
|
hideEditEntrance?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const FeatureBar = ({
|
const FeatureBar = ({
|
||||||
@ -20,6 +21,7 @@ const FeatureBar = ({
|
|||||||
showFileUpload = true,
|
showFileUpload = true,
|
||||||
disabled,
|
disabled,
|
||||||
onFeatureBarClick,
|
onFeatureBarClick,
|
||||||
|
hideEditEntrance = false,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const features = useFeatures(s => s.features)
|
const features = useFeatures(s => s.features)
|
||||||
@ -132,10 +134,14 @@ const FeatureBar = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='body-xs-regular grow text-text-tertiary'>{t('appDebug.feature.bar.enableText')}</div>
|
<div className='body-xs-regular grow text-text-tertiary'>{t('appDebug.feature.bar.enableText')}</div>
|
||||||
<Button className='shrink-0' variant='ghost-accent' size='small' onClick={() => onFeatureBarClick?.(true)}>
|
{
|
||||||
<div className='mx-1'>{t('appDebug.feature.bar.manage')}</div>
|
!hideEditEntrance && (
|
||||||
<RiArrowRightLine className='h-3.5 w-3.5 text-text-accent' />
|
<Button className='shrink-0' variant='ghost-accent' size='small' onClick={() => onFeatureBarClick?.(true)}>
|
||||||
</Button>
|
<div className='mx-1'>{t('appDebug.feature.bar.manage')}</div>
|
||||||
|
<RiArrowRightLine className='h-3.5 w-3.5 text-text-accent' />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -13,21 +13,27 @@ import { TransferMethod } from '@/types/app'
|
|||||||
|
|
||||||
type FileUploaderInChatInputProps = {
|
type FileUploaderInChatInputProps = {
|
||||||
fileConfig: FileUpload
|
fileConfig: FileUpload
|
||||||
|
readonly?: boolean
|
||||||
}
|
}
|
||||||
const FileUploaderInChatInput = ({
|
const FileUploaderInChatInput = ({
|
||||||
fileConfig,
|
fileConfig,
|
||||||
|
readonly,
|
||||||
}: FileUploaderInChatInputProps) => {
|
}: FileUploaderInChatInputProps) => {
|
||||||
const renderTrigger = useCallback((open: boolean) => {
|
const renderTrigger = useCallback((open: boolean) => {
|
||||||
return (
|
return (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
size='l'
|
size='l'
|
||||||
className={cn(open && 'bg-state-base-hover')}
|
className={cn(open && 'bg-state-base-hover')}
|
||||||
|
disabled={readonly}
|
||||||
>
|
>
|
||||||
<RiAttachmentLine className='h-5 w-5' />
|
<RiAttachmentLine className='h-5 w-5' />
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
)
|
)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
if(readonly)
|
||||||
|
return renderTrigger(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FileFromLinkOrLocal
|
<FileFromLinkOrLocal
|
||||||
trigger={renderTrigger}
|
trigger={renderTrigger}
|
||||||
|
|||||||
@ -663,6 +663,7 @@ const translation = {
|
|||||||
hitScore: 'Retrieval Score:',
|
hitScore: 'Retrieval Score:',
|
||||||
},
|
},
|
||||||
inputPlaceholder: 'Talk to {{botName}}',
|
inputPlaceholder: 'Talk to {{botName}}',
|
||||||
|
inputDisabledPlaceholder: 'Preview Only',
|
||||||
thinking: 'Thinking...',
|
thinking: 'Thinking...',
|
||||||
thought: 'Thought',
|
thought: 'Thought',
|
||||||
resend: 'Resend',
|
resend: 'Resend',
|
||||||
|
|||||||
@ -657,6 +657,7 @@ const translation = {
|
|||||||
hitScore: '召回得分:',
|
hitScore: '召回得分:',
|
||||||
},
|
},
|
||||||
inputPlaceholder: '和 {{botName}} 聊天',
|
inputPlaceholder: '和 {{botName}} 聊天',
|
||||||
|
inputDisabledPlaceholder: '仅供试用',
|
||||||
thinking: '深度思考中...',
|
thinking: '深度思考中...',
|
||||||
thought: '已深度思考',
|
thought: '已深度思考',
|
||||||
resend: '重新发送',
|
resend: '重新发送',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user