mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 22:55:58 +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 { ParameterExtractorNodeType } from '../../../parameter-extractor/types'
|
||||||
import type { IterationNodeType } from '../../../iteration/types'
|
import type { IterationNodeType } from '../../../iteration/types'
|
||||||
import type { ListFilterNodeType } from '../../../list-filter/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 { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types'
|
||||||
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
|
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
|
||||||
import type { ConversationVariable, EnvironmentVariable, Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
import type { ConversationVariable, EnvironmentVariable, Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
@ -76,8 +77,6 @@ const formatItem = (
|
|||||||
): NodeOutPutVar => {
|
): NodeOutPutVar => {
|
||||||
const { id, data } = item
|
const { id, data } = item
|
||||||
|
|
||||||
console.log(data.type)
|
|
||||||
|
|
||||||
const res: NodeOutPutVar = {
|
const res: NodeOutPutVar = {
|
||||||
nodeId: id,
|
nodeId: id,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
@ -303,10 +302,9 @@ const formatItem = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selector = [id]
|
const selector = [id]
|
||||||
|
|
||||||
res.vars = res.vars.filter((v) => {
|
res.vars = res.vars.filter((v) => {
|
||||||
const { children } = v
|
const isCurrentMatched = filterVar(v, (() => {
|
||||||
if (!children) {
|
|
||||||
return filterVar(v, (() => {
|
|
||||||
const variableArr = v.variable.split('.')
|
const variableArr = v.variable.split('.')
|
||||||
const [first, ..._other] = variableArr
|
const [first, ..._other] = variableArr
|
||||||
if (first === 'sys' || first === 'env' || first === 'conversation')
|
if (first === 'sys' || first === 'env' || first === 'conversation')
|
||||||
@ -314,16 +312,47 @@ const formatItem = (
|
|||||||
|
|
||||||
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
|
return obj?.children && obj?.children.length > 0
|
||||||
}).map((v) => {
|
}).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)
|
if (!children)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
return findExceptVarInObject(v, filterVar, selector)
|
return findExceptVarInObject(isFile ? { ...v, children } : v, filterVar, selector)
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
@ -46,8 +46,8 @@ const Item: FC<ItemProps> = ({
|
|||||||
onHovering,
|
onHovering,
|
||||||
itemWidth,
|
itemWidth,
|
||||||
}) => {
|
}) => {
|
||||||
const isObj = (itemData.type === VarType.object && itemData.children && itemData.children.length > 0) || itemData.type === VarType.file
|
|
||||||
const isFile = 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 isSys = itemData.variable.startsWith('sys.')
|
||||||
const isEnv = itemData.variable.startsWith('env.')
|
const isEnv = itemData.variable.startsWith('env.')
|
||||||
const isChatVar = itemData.variable.startsWith('conversation.')
|
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 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