mirror of
https://github.com/langgenius/dify.git
synced 2026-03-22 19:20:31 +08:00
- Extended the getConditionOperators function to include support for the integer variable type, allowing for additional comparison options in agent tool conditions.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { VarType } from '@/app/components/workflow/types'
|
|
|
|
const COMPARISON_OPERATOR_WITHOUT_VALUE = new Set([
|
|
'empty',
|
|
'not empty',
|
|
'null',
|
|
'not null',
|
|
'exists',
|
|
'not exists',
|
|
])
|
|
|
|
export const getConditionOperators = (varType?: VarType): string[] => {
|
|
switch (varType) {
|
|
case VarType.number:
|
|
case VarType.integer:
|
|
return ['=', '≠', '>', '<', '≥', '≤']
|
|
case VarType.boolean:
|
|
return ['is', 'is not']
|
|
case VarType.arrayString:
|
|
case VarType.arrayNumber:
|
|
case VarType.arrayBoolean:
|
|
case VarType.array:
|
|
case VarType.arrayAny:
|
|
return ['contains', 'not contains', 'empty', 'not empty']
|
|
case VarType.arrayFile:
|
|
return ['contains', 'not contains', 'empty', 'not empty']
|
|
case VarType.file:
|
|
return ['exists', 'not exists']
|
|
case VarType.object:
|
|
return ['empty', 'not empty']
|
|
case VarType.any:
|
|
return ['is', 'is not', 'empty', 'not empty']
|
|
default:
|
|
return ['contains', 'not contains', 'start with', 'end with', 'is', 'is not', 'empty', 'not empty']
|
|
}
|
|
}
|
|
|
|
export const operatorNeedsValue = (operator?: string): boolean => {
|
|
if (!operator)
|
|
return false
|
|
|
|
return !COMPARISON_OPERATOR_WITHOUT_VALUE.has(operator)
|
|
}
|
|
|
|
export const getDefaultValueByType = (varType: VarType): string | boolean => {
|
|
if (varType === VarType.boolean)
|
|
return true
|
|
|
|
return ''
|
|
}
|