feat:优化增量执行、工具调用容错与评测体系
This commit is contained in:
+35
-2
@@ -1,5 +1,6 @@
|
||||
"""在大屏 JSON 副本上按路径更新组件属性,用于后端校验动作能否执行"""
|
||||
|
||||
import json
|
||||
from copy import deepcopy
|
||||
|
||||
from app.actions.base import BaseActionHandler
|
||||
@@ -7,6 +8,30 @@ from app.schemas.actions import UpdateAction
|
||||
from app.schemas.screen import Screen, ScreenNode
|
||||
|
||||
|
||||
def same_value(node: ScreenNode, action: UpdateAction) -> bool:
|
||||
"""字段已经存在、并且值和要写入的完全一样(按 JSON 比较,1 和 1.0、true 和 1 不算一样)"""
|
||||
if action.section == "name":
|
||||
current = node.name
|
||||
else:
|
||||
current = getattr(node, action.section)
|
||||
for segment in action.path:
|
||||
if (
|
||||
isinstance(current, dict)
|
||||
and isinstance(segment, str)
|
||||
and segment in current
|
||||
) or (
|
||||
isinstance(current, list)
|
||||
and type(segment) is int
|
||||
and segment < len(current)
|
||||
):
|
||||
current = current[segment]
|
||||
else:
|
||||
return False
|
||||
return json.dumps(current, sort_keys=True) == json.dumps(
|
||||
action.value, sort_keys=True
|
||||
)
|
||||
|
||||
|
||||
def fit_existing_path(node: ScreenNode, action: UpdateAction) -> UpdateAction:
|
||||
"""字段定义允许的路径在组件中可能还没有中间对象(例如未开启过的数值标签)
|
||||
|
||||
@@ -17,7 +42,11 @@ def fit_existing_path(node: ScreenNode, action: UpdateAction) -> UpdateAction:
|
||||
return action
|
||||
current = getattr(node, action.section) or {}
|
||||
for index, segment in enumerate(action.path[:-1]):
|
||||
if isinstance(current, dict) and isinstance(segment, str) and segment not in current:
|
||||
if (
|
||||
isinstance(current, dict)
|
||||
and isinstance(segment, str)
|
||||
and segment not in current
|
||||
):
|
||||
rest = action.path[index + 1 :]
|
||||
if not all(isinstance(item, str) for item in rest):
|
||||
return action
|
||||
@@ -29,7 +58,11 @@ def fit_existing_path(node: ScreenNode, action: UpdateAction) -> UpdateAction:
|
||||
)
|
||||
if isinstance(current, dict) and isinstance(segment, str):
|
||||
current = current[segment]
|
||||
elif isinstance(current, list) and type(segment) is int and segment < len(current):
|
||||
elif (
|
||||
isinstance(current, list)
|
||||
and type(segment) is int
|
||||
and segment < len(current)
|
||||
):
|
||||
current = current[segment]
|
||||
else:
|
||||
return action
|
||||
|
||||
Reference in New Issue
Block a user