mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 01:25:53 +08:00
fix: chatflow check start node form
This commit is contained in:
parent
5f76e665a1
commit
9fe2f321ae
@ -34,6 +34,7 @@ type ChatInputAreaProps = {
|
|||||||
visionConfig?: FileUpload
|
visionConfig?: FileUpload
|
||||||
speechToTextConfig?: EnableType
|
speechToTextConfig?: EnableType
|
||||||
onSend?: OnSend
|
onSend?: OnSend
|
||||||
|
onSendCheck?: () => boolean
|
||||||
theme?: Theme | null
|
theme?: Theme | null
|
||||||
}
|
}
|
||||||
const ChatInputArea = ({
|
const ChatInputArea = ({
|
||||||
@ -44,6 +45,7 @@ const ChatInputArea = ({
|
|||||||
visionConfig,
|
visionConfig,
|
||||||
speechToTextConfig = { enabled: true },
|
speechToTextConfig = { enabled: true },
|
||||||
onSend,
|
onSend,
|
||||||
|
onSendCheck = () => true,
|
||||||
// theme,
|
// theme,
|
||||||
}: ChatInputAreaProps) => {
|
}: ChatInputAreaProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -80,9 +82,11 @@ const ChatInputArea = ({
|
|||||||
notify({ type: 'info', message: t('appAnnotation.errorMessage.queryRequired') })
|
notify({ type: 'info', message: t('appAnnotation.errorMessage.queryRequired') })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSend(query, files)
|
if (onSendCheck()) {
|
||||||
setQuery('')
|
onSend(query, files)
|
||||||
setFiles([])
|
setQuery('')
|
||||||
|
setFiles([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ export type ChatProps = {
|
|||||||
onStopResponding?: () => void
|
onStopResponding?: () => void
|
||||||
noChatInput?: boolean
|
noChatInput?: boolean
|
||||||
onSend?: OnSend
|
onSend?: OnSend
|
||||||
|
onSendCheck?: () => boolean
|
||||||
onRegenerate?: OnRegenerate
|
onRegenerate?: OnRegenerate
|
||||||
chatContainerClassName?: string
|
chatContainerClassName?: string
|
||||||
chatContainerInnerClassName?: string
|
chatContainerInnerClassName?: string
|
||||||
@ -72,6 +73,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
appData,
|
appData,
|
||||||
config,
|
config,
|
||||||
onSend,
|
onSend,
|
||||||
|
onSendCheck,
|
||||||
onRegenerate,
|
onRegenerate,
|
||||||
chatList,
|
chatList,
|
||||||
isResponding,
|
isResponding,
|
||||||
@ -281,6 +283,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
visionConfig={config?.file_upload}
|
visionConfig={config?.file_upload}
|
||||||
speechToTextConfig={config?.speech_to_text}
|
speechToTextConfig={config?.speech_to_text}
|
||||||
onSend={onSend}
|
onSend={onSend}
|
||||||
|
onSendCheck={onSendCheck}
|
||||||
theme={themeBuilder?.theme}
|
theme={themeBuilder?.theme}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
@ -16,3 +16,4 @@ export * from './use-workflow-variables'
|
|||||||
export * from './use-shortcuts'
|
export * from './use-shortcuts'
|
||||||
export * from './use-workflow-interactions'
|
export * from './use-workflow-interactions'
|
||||||
export * from './use-workflow-mode'
|
export * from './use-workflow-mode'
|
||||||
|
export * from './use-check-start-node-form'
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
import { useCallback } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useStoreApi } from 'reactflow'
|
||||||
|
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||||
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
|
import { useToastContext } from '@/app/components/base/toast'
|
||||||
|
import type { InputVar } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
|
export const useCheckStartNodeForm = () => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const storeApi = useStoreApi()
|
||||||
|
const workflowStore = useWorkflowStore()
|
||||||
|
const { notify } = useToastContext()
|
||||||
|
|
||||||
|
const checkStartNodeForm = useCallback(() => {
|
||||||
|
const { getNodes } = storeApi.getState()
|
||||||
|
const nodes = getNodes()
|
||||||
|
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
|
||||||
|
const variables: InputVar[] = startNode?.data.variables || []
|
||||||
|
const inputs = workflowStore.getState().inputs
|
||||||
|
|
||||||
|
let hasEmptyInput = ''
|
||||||
|
const requiredVars = variables.filter(({ required }) => required)
|
||||||
|
|
||||||
|
if (requiredVars?.length) {
|
||||||
|
requiredVars.forEach(({ variable, label }) => {
|
||||||
|
if (hasEmptyInput)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (!inputs[variable])
|
||||||
|
hasEmptyInput = label as string
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasEmptyInput) {
|
||||||
|
notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput }) })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}, [storeApi, workflowStore, notify, t])
|
||||||
|
|
||||||
|
return {
|
||||||
|
checkStartNodeForm,
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import {
|
|||||||
useStore,
|
useStore,
|
||||||
useWorkflowStore,
|
useWorkflowStore,
|
||||||
} from '../../store'
|
} from '../../store'
|
||||||
|
import { useCheckStartNodeForm } from '../../hooks'
|
||||||
import type { StartNodeType } from '../../nodes/start/types'
|
import type { StartNodeType } from '../../nodes/start/types'
|
||||||
import Empty from './empty'
|
import Empty from './empty'
|
||||||
import UserInput from './user-input'
|
import UserInput from './user-input'
|
||||||
@ -61,6 +62,7 @@ const ChatWrapper = forwardRef<ChatWrapperRefType, ChatWrapperProps>(({
|
|||||||
}
|
}
|
||||||
}, [features.opening, features.suggested, features.text2speech, features.speech2text, features.citation, features.moderation, features.file])
|
}, [features.opening, features.suggested, features.text2speech, features.speech2text, features.citation, features.moderation, features.file])
|
||||||
const setShowFeaturesPanel = useStore(s => s.setShowFeaturesPanel)
|
const setShowFeaturesPanel = useStore(s => s.setShowFeaturesPanel)
|
||||||
|
const { checkStartNodeForm } = useCheckStartNodeForm()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
conversationId,
|
conversationId,
|
||||||
@ -141,6 +143,7 @@ const ChatWrapper = forwardRef<ChatWrapperRefType, ChatWrapperProps>(({
|
|||||||
showFeatureBar
|
showFeatureBar
|
||||||
onFeatureBarClick={setShowFeaturesPanel}
|
onFeatureBarClick={setShowFeaturesPanel}
|
||||||
onSend={doSend}
|
onSend={doSend}
|
||||||
|
onSendCheck={checkStartNodeForm}
|
||||||
onRegenerate={doRegenerate}
|
onRegenerate={doRegenerate}
|
||||||
onStopResponding={handleStop}
|
onStopResponding={handleStop}
|
||||||
chatNode={(
|
chatNode={(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user