mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 10:28:10 +08:00
step run of human input
This commit is contained in:
@ -32,10 +32,12 @@ export type BeforeRunFormProps = {
|
||||
showSpecialResultPanel?: boolean
|
||||
existVarValuesInForms: Record<string, any>[]
|
||||
filteredExistVarForms: FormProps[]
|
||||
generatedFormContentData?: Record<string, any>
|
||||
showGeneratedForm?: boolean
|
||||
handleShowGeneratedForm?: (data: Record<string, any>) => void
|
||||
handleHideGeneratedForm?: () => void
|
||||
formData?: any
|
||||
handleSubmitHumanInputForm?: (data: any) => Promise<void>
|
||||
handleAfterHumanInputStepRun?: () => void
|
||||
} & Partial<SpecialResultPanelProps>
|
||||
|
||||
function formatValue(value: string | any, type: InputVarType) {
|
||||
@ -73,14 +75,17 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
|
||||
forms,
|
||||
filteredExistVarForms,
|
||||
existVarValuesInForms,
|
||||
generatedFormContentData,
|
||||
showGeneratedForm = false,
|
||||
handleShowGeneratedForm,
|
||||
handleHideGeneratedForm,
|
||||
formData,
|
||||
handleSubmitHumanInputForm,
|
||||
handleAfterHumanInputStepRun,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const isHumanInput = nodeType === BlockEnum.HumanInput
|
||||
const showBackButton = filteredExistVarForms.length > 0
|
||||
|
||||
const isFileLoaded = (() => {
|
||||
if (!forms || forms.length === 0)
|
||||
@ -154,6 +159,11 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
|
||||
onRun(submitData)
|
||||
}
|
||||
|
||||
const handleHumanInputFormSubmit = async (data: any) => {
|
||||
await handleSubmitHumanInputForm?.(data)
|
||||
handleAfterHumanInputStepRun?.()
|
||||
}
|
||||
|
||||
const hasRun = useRef(false)
|
||||
useEffect(() => {
|
||||
// React 18 run twice in dev mode
|
||||
@ -162,7 +172,9 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
|
||||
hasRun.current = true
|
||||
if (filteredExistVarForms.length === 0 && !isHumanInput)
|
||||
onRun({})
|
||||
}, [filteredExistVarForms, onRun])
|
||||
if (filteredExistVarForms.length === 0 && isHumanInput)
|
||||
handleShowGeneratedForm?.({})
|
||||
}, [filteredExistVarForms, handleShowGeneratedForm, isHumanInput, onRun])
|
||||
|
||||
if (filteredExistVarForms.length === 0 && !isHumanInput)
|
||||
return null
|
||||
@ -187,14 +199,13 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{showGeneratedForm && generatedFormContentData && (
|
||||
{showGeneratedForm && formData && (
|
||||
<SingleRunForm
|
||||
nodeName={nodeName}
|
||||
showBackButton={showBackButton}
|
||||
handleBack={handleHideGeneratedForm}
|
||||
showBackButton={generatedFormContentData.showBackButton}
|
||||
formContent={generatedFormContentData.formContent}
|
||||
inputFields={generatedFormContentData.inputFields}
|
||||
userActions={generatedFormContentData.userActions}
|
||||
data={formData}
|
||||
onSubmit={handleHumanInputFormSubmit}
|
||||
/>
|
||||
)}
|
||||
{!showGeneratedForm && (
|
||||
|
||||
@ -445,6 +445,7 @@ const BasePanel: FC<BasePanelProps> = ({
|
||||
{...passedLogParams}
|
||||
existVarValuesInForms={getExistVarValuesInForms(singleRunParams?.forms as any)}
|
||||
filteredExistVarForms={getFilteredExistVarForms(singleRunParams?.forms as any)}
|
||||
handleAfterHumanInputStepRun={handleAfterCustomSingleRun}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@ -133,6 +133,7 @@ const useLastRun = <T>({
|
||||
const isLoopNode = blockType === BlockEnum.Loop
|
||||
const isAggregatorNode = blockType === BlockEnum.VariableAggregator
|
||||
const isCustomRunNode = isSupportCustomRunForm(blockType)
|
||||
const isHumanInputNode = blockType === BlockEnum.HumanInput
|
||||
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
||||
const {
|
||||
getData: getDataForCheckMore,
|
||||
@ -342,17 +343,11 @@ const useLastRun = <T>({
|
||||
return
|
||||
if (blockType === BlockEnum.TriggerWebhook || blockType === BlockEnum.TriggerPlugin || blockType === BlockEnum.TriggerSchedule)
|
||||
setShowVariableInspectPanel(true)
|
||||
if (isCustomRunNode) {
|
||||
if (isCustomRunNode || isHumanInputNode) {
|
||||
showSingleRun()
|
||||
return
|
||||
}
|
||||
const vars = singleRunParams?.getDependentVars?.()
|
||||
// TODO human input
|
||||
if (singleRunParams?.generatedFormContentData) {
|
||||
singleRunParams?.handleShowGeneratedForm()
|
||||
showSingleRun()
|
||||
return
|
||||
}
|
||||
// no need to input params
|
||||
if (isAggregatorNode ? checkAggregatorVarsSet(vars) : isAllVarsHasValue(vars)) {
|
||||
callRunApi({}, async () => {
|
||||
|
||||
Reference in New Issue
Block a user