mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 09:35:53 +08:00
fix: filter file and file sub variable
This commit is contained in:
parent
48d8b01d81
commit
08d3cb1912
@ -14,6 +14,7 @@ import type { ToolNodeType } from '../../../tool/types'
|
||||
import type { ParameterExtractorNodeType } from '../../../parameter-extractor/types'
|
||||
import type { IterationNodeType } from '../../../iteration/types'
|
||||
import type { ListFilterNodeType } from '../../../list-filter/types'
|
||||
import { OUTPUT_FILE_SUB_VARIABLES } from '../../../if-else/default'
|
||||
import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types'
|
||||
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
|
||||
import type { ConversationVariable, EnvironmentVariable, Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||
@ -76,8 +77,6 @@ const formatItem = (
|
||||
): NodeOutPutVar => {
|
||||
const { id, data } = item
|
||||
|
||||
console.log(data.type)
|
||||
|
||||
const res: NodeOutPutVar = {
|
||||
nodeId: id,
|
||||
title: data.title,
|
||||
@ -303,27 +302,57 @@ const formatItem = (
|
||||
}
|
||||
|
||||
const selector = [id]
|
||||
|
||||
res.vars = res.vars.filter((v) => {
|
||||
const { children } = v
|
||||
if (!children) {
|
||||
return filterVar(v, (() => {
|
||||
const variableArr = v.variable.split('.')
|
||||
const [first, ..._other] = variableArr
|
||||
if (first === 'sys' || first === 'env' || first === 'conversation')
|
||||
return variableArr
|
||||
const isCurrentMatched = filterVar(v, (() => {
|
||||
const variableArr = v.variable.split('.')
|
||||
const [first, ..._other] = variableArr
|
||||
if (first === 'sys' || first === 'env' || first === 'conversation')
|
||||
return variableArr
|
||||
|
||||
return [...selector, ...variableArr]
|
||||
})())
|
||||
}
|
||||
return [...selector, ...variableArr]
|
||||
})())
|
||||
if (isCurrentMatched)
|
||||
return true
|
||||
|
||||
const obj = findExceptVarInObject(v, filterVar, selector)
|
||||
const isFile = v.type === VarType.file
|
||||
const children = (() => {
|
||||
if (isFile) {
|
||||
return OUTPUT_FILE_SUB_VARIABLES.map((key) => {
|
||||
return {
|
||||
variable: key,
|
||||
type: key === 'size' ? VarType.number : VarType.string,
|
||||
}
|
||||
})
|
||||
}
|
||||
return v.children
|
||||
})()
|
||||
if (!children)
|
||||
return false
|
||||
|
||||
const obj = findExceptVarInObject(isFile ? { ...v, children } : v, filterVar, selector)
|
||||
return obj?.children && obj?.children.length > 0
|
||||
}).map((v) => {
|
||||
const { children } = v
|
||||
const isFile = v.type === VarType.file
|
||||
|
||||
const { children } = (() => {
|
||||
if (isFile) {
|
||||
return {
|
||||
children: OUTPUT_FILE_SUB_VARIABLES.map((key) => {
|
||||
return {
|
||||
variable: key,
|
||||
type: key === 'size' ? VarType.number : VarType.string,
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
return v
|
||||
})()
|
||||
|
||||
if (!children)
|
||||
return v
|
||||
|
||||
return findExceptVarInObject(v, filterVar, selector)
|
||||
return findExceptVarInObject(isFile ? { ...v, children } : v, filterVar, selector)
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -46,8 +46,8 @@ const Item: FC<ItemProps> = ({
|
||||
onHovering,
|
||||
itemWidth,
|
||||
}) => {
|
||||
const isObj = (itemData.type === VarType.object && itemData.children && itemData.children.length > 0) || itemData.type === VarType.file
|
||||
const isFile = itemData.type === VarType.file
|
||||
const isObj = ([VarType.object, VarType.file].includes(itemData.type) && itemData.children && itemData.children.length > 0)
|
||||
const isSys = itemData.variable.startsWith('sys.')
|
||||
const isEnv = itemData.variable.startsWith('env.')
|
||||
const isChatVar = itemData.variable.startsWith('conversation.')
|
||||
|
@ -76,3 +76,4 @@ export const TRANSFER_METHOD = [
|
||||
]
|
||||
|
||||
export const SUB_VARIABLES = ['type', 'size', 'name', 'url', 'extension', 'mime_type', 'transfer_method', 'url']
|
||||
export const OUTPUT_FILE_SUB_VARIABLES = SUB_VARIABLES.filter(key => key !== 'transfer_method')
|
||||
|
Loading…
x
Reference in New Issue
Block a user