datasource variables

This commit is contained in:
zxhlyh 2025-05-27 18:44:04 +08:00
parent 377093b776
commit b320ebe2ba
3 changed files with 29 additions and 2 deletions

View File

@ -34,6 +34,7 @@ import {
TOOL_OUTPUT_STRUCT,
} from '@/app/components/workflow/constants'
import DataSourceNodeDefault from '@/app/components/workflow/nodes/data-source/default'
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import type { PromptItem } from '@/models/debug'
import { VAR_REGEX } from '@/config'
import type { AgentNodeType } from '../../../agent/types'
@ -459,7 +460,7 @@ const formatItem = (
}
case BlockEnum.DataSource: {
res.vars = DataSourceNodeDefault.getOutputVars?.(data as any) || []
res.vars = DataSourceNodeDefault.getOutputVars?.(data as DataSourceNodeType) || []
break
}

View File

@ -3,6 +3,7 @@ import type { DataSourceNodeType } from './types'
import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types'
import { OUTPUT_VARIABLES_MAP } from './constants'
import { inputVarTypeToVarType } from './utils'
const metaData = genNodeMetaData({
sort: -1,
@ -22,8 +23,12 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
}
},
getOutputVars(payload) {
const { provider_type } = payload
const {
provider_type,
variables,
} = payload
const isLocalFile = provider_type === 'local_file'
const hasUserInputFields = !!variables?.length
return [
{
variable: OUTPUT_VARIABLES_MAP.datasource_type.name,
@ -39,6 +44,17 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
]
: []
),
...(
hasUserInputFields
? variables.map((field) => {
return {
variable: field.variable,
type: inputVarTypeToVarType(field.type),
isUserInputField: true,
}
})
: []
),
]
},
}

View File

@ -0,0 +1,10 @@
import { PipelineInputVarType } from '@/models/pipeline'
import { VarType } from '@/app/components/workflow/types'
export const inputVarTypeToVarType = (type: PipelineInputVarType): VarType => {
return ({
[PipelineInputVarType.number]: VarType.number,
[PipelineInputVarType.singleFile]: VarType.file,
[PipelineInputVarType.multiFiles]: VarType.arrayFile,
} as any)[type] || VarType.string
}