mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
feat: add File Upload node functionality and related components
- Implemented File Upload node with support for uploading files to the sandbox. - Added necessary UI components including node panel and default configurations. - Enhanced workflow constants and enums to include File Upload. - Updated error handling for file upload operations. - Integrated File Upload into existing workflow structure, ensuring compatibility with variable handling and output management. - Added translations for new File Upload features in workflow.json.
This commit is contained in:
@ -4,6 +4,7 @@ import type { CodeNodeType } from '../../../code/types'
|
||||
import type { CommandNodeType } from '../../../command/types'
|
||||
import type { DocExtractorNodeType } from '../../../document-extractor/types'
|
||||
import type { EndNodeType } from '../../../end/types'
|
||||
import type { FileUploadNodeType } from '../../../file-upload/types'
|
||||
import type { HttpNodeType } from '../../../http/types'
|
||||
import type { IfElseNodeType } from '../../../if-else/types'
|
||||
import type { IterationNodeType } from '../../../iteration/types'
|
||||
@ -42,6 +43,7 @@ import {
|
||||
AGENT_OUTPUT_STRUCT,
|
||||
COMMAND_OUTPUT_STRUCT,
|
||||
FILE_STRUCT,
|
||||
FILE_UPLOAD_OUTPUT_STRUCT,
|
||||
getGlobalVars,
|
||||
HTTP_REQUEST_OUTPUT_STRUCT,
|
||||
HUMAN_INPUT_OUTPUT_STRUCT,
|
||||
@ -471,6 +473,22 @@ const formatItem = (
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.FileUpload: {
|
||||
res.vars = (data as FileUploadNodeType).is_array_file
|
||||
? [
|
||||
{
|
||||
variable: 'sandbox_path',
|
||||
type: VarType.arrayString,
|
||||
},
|
||||
{
|
||||
variable: 'file_name',
|
||||
type: VarType.arrayString,
|
||||
},
|
||||
]
|
||||
: FILE_UPLOAD_OUTPUT_STRUCT
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
res.vars = QUESTION_CLASSIFIER_OUTPUT_STRUCT
|
||||
break
|
||||
@ -1538,6 +1556,11 @@ export const getNodeUsedVars = (node: Node): ValueSelector[] => {
|
||||
])
|
||||
break
|
||||
}
|
||||
case BlockEnum.FileUpload: {
|
||||
const payload = data as FileUploadNodeType
|
||||
res = [payload.variable_selector]
|
||||
break
|
||||
}
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
const payload = data as QuestionClassifierNodeType
|
||||
res = [payload.query_variable_selector]
|
||||
@ -1933,6 +1956,12 @@ export const updateNodeVars = (
|
||||
)
|
||||
break
|
||||
}
|
||||
case BlockEnum.FileUpload: {
|
||||
const payload = data as FileUploadNodeType
|
||||
if (payload.variable_selector.join('.') === oldVarSelector.join('.'))
|
||||
payload.variable_selector = newVarSelector
|
||||
break
|
||||
}
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
const payload = data as QuestionClassifierNodeType
|
||||
if (
|
||||
@ -2232,6 +2261,17 @@ export const getNodeOutputVars = (
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.FileUpload: {
|
||||
if ((data as FileUploadNodeType).is_array_file) {
|
||||
res.push([id, 'sandbox_path'])
|
||||
res.push([id, 'file_name'])
|
||||
}
|
||||
else {
|
||||
varsToValueSelectorList(FILE_UPLOAD_OUTPUT_STRUCT, [id], res)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
varsToValueSelectorList(QUESTION_CLASSIFIER_OUTPUT_STRUCT, [id], res)
|
||||
break
|
||||
|
||||
@ -20,6 +20,7 @@ import useAgentSingleRunFormParams from '@/app/components/workflow/nodes/agent/u
|
||||
import useVariableAssignerSingleRunFormParams from '@/app/components/workflow/nodes/assigner/use-single-run-form-params'
|
||||
import useCodeSingleRunFormParams from '@/app/components/workflow/nodes/code/use-single-run-form-params'
|
||||
import useDocExtractorSingleRunFormParams from '@/app/components/workflow/nodes/document-extractor/use-single-run-form-params'
|
||||
import useFileUploadSingleRunFormParams from '@/app/components/workflow/nodes/file-upload/use-single-run-form-params'
|
||||
import useHttpRequestSingleRunFormParams from '@/app/components/workflow/nodes/http/use-single-run-form-params'
|
||||
import useHumanInputSingleRunFormParams from '@/app/components/workflow/nodes/human-input/hooks/use-single-run-form-params'
|
||||
import useIfElseSingleRunFormParams from '@/app/components/workflow/nodes/if-else/use-single-run-form-params'
|
||||
@ -51,6 +52,7 @@ const singleRunFormParamsHooks: Record<BlockEnum, any> = {
|
||||
[BlockEnum.KnowledgeRetrieval]: useKnowledgeRetrievalSingleRunFormParams,
|
||||
[BlockEnum.Code]: useCodeSingleRunFormParams,
|
||||
[BlockEnum.Command]: undefined,
|
||||
[BlockEnum.FileUpload]: useFileUploadSingleRunFormParams,
|
||||
[BlockEnum.TemplateTransform]: useTemplateTransformSingleRunFormParams,
|
||||
[BlockEnum.QuestionClassifier]: useQuestionClassifierSingleRunFormParams,
|
||||
[BlockEnum.HttpRequest]: useHttpRequestSingleRunFormParams,
|
||||
@ -93,6 +95,7 @@ const getDataForCheckMoreHooks: Record<BlockEnum, any> = {
|
||||
[BlockEnum.KnowledgeRetrieval]: undefined,
|
||||
[BlockEnum.Code]: undefined,
|
||||
[BlockEnum.Command]: undefined,
|
||||
[BlockEnum.FileUpload]: undefined,
|
||||
[BlockEnum.TemplateTransform]: undefined,
|
||||
[BlockEnum.QuestionClassifier]: undefined,
|
||||
[BlockEnum.HttpRequest]: undefined,
|
||||
|
||||
@ -24,6 +24,7 @@ import { getNodeInfoById, isConversationVar, isENV, isSystemVar, toNodeOutputVar
|
||||
import Assigner from '@/app/components/workflow/nodes/assigner/default'
|
||||
import CodeDefault from '@/app/components/workflow/nodes/code/default'
|
||||
import DocumentExtractorDefault from '@/app/components/workflow/nodes/document-extractor/default'
|
||||
import FileUploadDefault from '@/app/components/workflow/nodes/file-upload/default'
|
||||
import HTTPDefault from '@/app/components/workflow/nodes/http/default'
|
||||
import HumanInputDefault from '@/app/components/workflow/nodes/human-input/default'
|
||||
import IfElseDefault from '@/app/components/workflow/nodes/if-else/default'
|
||||
@ -70,6 +71,7 @@ const { checkValid: checkAssignerValid } = Assigner
|
||||
const { checkValid: checkParameterExtractorValid } = ParameterExtractorDefault
|
||||
const { checkValid: checkIterationValid } = IterationDefault
|
||||
const { checkValid: checkDocumentExtractorValid } = DocumentExtractorDefault
|
||||
const { checkValid: checkFileUploadValid } = FileUploadDefault
|
||||
const { checkValid: checkLoopValid } = LoopDefault
|
||||
const { checkValid: checkHumanInputValid } = HumanInputDefault
|
||||
|
||||
@ -88,6 +90,7 @@ const checkValidFns: Partial<Record<BlockEnum, Function>> = {
|
||||
[BlockEnum.ParameterExtractor]: checkParameterExtractorValid,
|
||||
[BlockEnum.Iteration]: checkIterationValid,
|
||||
[BlockEnum.DocExtractor]: checkDocumentExtractorValid,
|
||||
[BlockEnum.FileUpload]: checkFileUploadValid,
|
||||
[BlockEnum.Loop]: checkLoopValid,
|
||||
[BlockEnum.HumanInput]: checkHumanInputValid,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user