Skip to content

Commit 3e458af

Browse files
feat: Supports type_is and type_not comparisons
1 parent 0548e2c commit 3e458af

10 files changed

Lines changed: 116 additions & 3 deletions

File tree

‎apps/application/flow/compare/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from .not_equal_compare import NotEqualCompare
2929
from .regex_compare import RegexCompare
3030
from .start_with import StartWithCompare
31+
from .type_is_compare import TypeIsCompare
32+
from .type_not_compare import TypeNotCompare
3133
from .wildcard_compare import WildcardCompare
3234

3335
_compare_handler_dict = {
@@ -50,6 +52,8 @@
5052
'is_not_true': IsNotTrueCompare(),
5153
'start_with': StartWithCompare(),
5254
'end_with': EndWithCompare(),
55+
'type_is': TypeIsCompare(),
56+
'type_not': TypeNotCompare(),
5357
'regex': RegexCompare(),
5458
'wildcard': WildcardCompare(),
5559
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:wangliang181230
5+
@file:type_is_compare.py
6+
@date:2026/5/25 10:01
7+
@desc: “数据类型是” 比较器
8+
"""
9+
from .compare import Compare
10+
11+
12+
class TypeIsCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
try:
16+
if target_value == "json":
17+
return isinstance(source_value, (list, dict))
18+
elif target_value == "num":
19+
return isinstance(source_value, (int, float))
20+
else:
21+
return type(source_value).__name__ == target_value
22+
except Exception:
23+
return False
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:wangliang181230
5+
@file:type_not_compare.py
6+
@date:2026/5/25 10:01
7+
@desc: “数据类型不是” 比较器
8+
"""
9+
from .compare import Compare
10+
11+
12+
class TypeNotCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
try:
16+
if target_value == "json":
17+
return not isinstance(source_value, (list, dict))
18+
elif target_value == "num":
19+
return not isinstance(source_value, (int, float))
20+
else:
21+
return type(source_value).__name__ != target_value
22+
except Exception:
23+
return False

‎ui/src/locales/lang/en-US/workflow.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ You are a master of problem optimization, adept at accurately inferring user int
235235
requiredMessage: 'Please select conditions',
236236
},
237237
valueMessage: 'Please enter a value',
238+
verify_type_compare: {
239+
requiredMessage: 'Please select a type',
240+
},
238241
addCondition: 'Add Condition',
239242
addBranch: 'Add Branch',
240243
},
@@ -550,6 +553,8 @@ You are a master of problem optimization, adept at accurately inferring user int
550553
len_lt: 'Length less than',
551554
is_true: 'Is true',
552555
is_not_true: 'Is not true',
556+
type_is: 'Type is',
557+
type_not: 'Type not',
553558
regex: 'Regex matching',
554559
wildcard: 'Wildcard matching',
555560
},

‎ui/src/locales/lang/zh-CN/workflow.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ export default {
235235
requiredMessage: '请选择条件',
236236
},
237237
valueMessage: '请输入值',
238+
verify_type_compare: {
239+
requiredMessage: '请选择类型',
240+
},
238241
addCondition: '添加条件',
239242
addBranch: '添加分支',
240243
},
@@ -541,6 +544,8 @@ export default {
541544
len_lt: '长度小于',
542545
is_true: '为真',
543546
is_not_true: '不为真',
547+
type_is: '类型是',
548+
type_not: '类型不是',
544549
regex: '正则匹配',
545550
wildcard: '通配符匹配',
546551
},

‎ui/src/locales/lang/zh-Hant/workflow.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ export default {
235235
requiredMessage: '請選擇條件',
236236
},
237237
valueMessage: '請輸入值',
238+
verify_type_compare: {
239+
requiredMessage: '請選擇類型',
240+
},
238241
addCondition: '添加條件',
239242
addBranch: '添加分支',
240243
},
@@ -535,6 +538,8 @@ export default {
535538
len_lt: '長度小於',
536539
is_true: '為真',
537540
is_not_true: '不為真',
541+
type_is: '類型是',
542+
type_not: '類型不是',
538543
regex: '正則匹配',
539544
wildcard: '通配符匹配',
540545
},

‎ui/src/workflow/common/data.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,8 @@ export const compareList = [
11401140
{ value: 'is_not_true', label: t('workflow.compare.is_not_true') },
11411141
{ value: 'start_with', label: 'startWith' },
11421142
{ value: 'end_with', label: 'endWith' },
1143+
{ value: 'type_is', label: t('workflow.compare.type_is') },
1144+
{ value: 'type_not', label: t('workflow.compare.type_not') },
11431145
{ value: 'regex', label: t('workflow.compare.regex') },
11441146
{ value: 'wildcard', label: t('workflow.compare.wildcard') },
11451147
]

‎ui/src/workflow/nodes/condition-node/index.vue‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,25 @@
115115
trigger: 'blur',
116116
}"
117117
>
118+
<el-select
119+
v-if="['type_is', 'type_not'].includes(condition.compare)"
120+
v-model="condition.value"
121+
:placeholder="$t('workflow.nodes.conditionNode.verify_type_compare.requiredMessage')"
122+
>
123+
<el-option label="json" value="json" />
124+
<el-option label="dict" value="dict" />
125+
<el-option label="array" value="list" />
126+
<el-option label="string" value="str" />
127+
<el-option label="num" value="num" />
128+
<el-option label="int" value="int" />
129+
<el-option label="float" value="float" />
130+
<el-option label="boolean" value="bool" />
131+
<el-option label="null" value="NoneType" />
132+
</el-select>
118133
<el-input
134+
v-else
119135
v-model="condition.value"
120-
:placeholder="
121-
$t('workflow.nodes.conditionNode.valueMessage')
122-
"
136+
:placeholder="$t('workflow.nodes.conditionNode.valueMessage')"
123137
/>
124138
</el-form-item>
125139
</el-col>

‎ui/src/workflow/nodes/loop-break-node/index.vue‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@
8383
trigger: 'blur',
8484
}"
8585
>
86+
<el-select
87+
v-if="['type_is', 'type_not'].includes(condition.compare)"
88+
v-model="condition.value"
89+
:placeholder="$t('workflow.nodes.conditionNode.verify_type_compare.requiredMessage')"
90+
>
91+
<el-option label="json" value="json" />
92+
<el-option label="dict" value="dict" />
93+
<el-option label="array" value="list" />
94+
<el-option label="string" value="str" />
95+
<el-option label="num" value="num" />
96+
<el-option label="int" value="int" />
97+
<el-option label="float" value="float" />
98+
<el-option label="boolean" value="bool" />
99+
<el-option label="null" value="NoneType" />
100+
</el-select>
86101
<el-input
102+
v-else
87103
v-model="condition.value"
88104
:placeholder="$t('workflow.nodes.conditionNode.valueMessage')"
89105
/>

‎ui/src/workflow/nodes/loop-continue-node/index.vue‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@
8383
trigger: 'blur',
8484
}"
8585
>
86+
<el-select
87+
v-if="['type_is', 'type_not'].includes(condition.compare)"
88+
v-model="condition.value"
89+
:placeholder="$t('workflow.nodes.conditionNode.verify_type_compare.requiredMessage')"
90+
>
91+
<el-option label="json" value="json" />
92+
<el-option label="dict" value="dict" />
93+
<el-option label="array" value="list" />
94+
<el-option label="string" value="str" />
95+
<el-option label="num" value="num" />
96+
<el-option label="int" value="int" />
97+
<el-option label="float" value="float" />
98+
<el-option label="boolean" value="bool" />
99+
<el-option label="null" value="NoneType" />
100+
</el-select>
86101
<el-input
102+
v-else
87103
v-model="condition.value"
88104
:placeholder="$t('workflow.nodes.conditionNode.valueMessage')"
89105
/>

0 commit comments

Comments
 (0)