feat:简化部分代码

This commit is contained in:
2026-09-29 07:23:42 -07:00
parent af84485e8d
commit 352d144823
13 changed files with 123 additions and 306 deletions
+6 -12
View File
@@ -22,9 +22,9 @@ from app.schemas.screen_plan import PlanComponent
def plan_block_reason(state: QueryState) -> str | None:
"""检查规划是否在当前支持范围内,不支持时返回原因"""
# 获取当前规划和可选的组件目录,后续分别检查操作范围与新增物料能力
# 获取当前规划和组件目录,后续分别检查操作范围与新增物料能力
plan = state["screen_plan"]
resources = state.get("component_resources")
resources = state["component_resources"]
# 如果需求尚未明确,不能根据规划直接生成动作
if state["requirement"].needs_clarification:
@@ -47,12 +47,8 @@ def plan_block_reason(state: QueryState) -> str | None:
if not additions and not modifications and not removals and not plan.canvas_changes:
return "规划未包含可执行的组件或画布修改"
# 新增组件依赖真实物料目录,仅调整已有组件时不强制要求目录存在
if additions and (resources is None or resources.status != "resolved"):
return "组件目录尚未就绪"
# 收集目录支持的类型,拒绝规划虚构前端未注册的新增组件类型
supported = {item.type for item in resources.components} if resources else set()
supported = {item.type for item in resources.components}
if any(item.component_type not in supported for item in additions):
return "规划中的新增类型未在组件目录中找到"
@@ -179,8 +175,7 @@ def assemble_plan_actions(state: QueryState, batch: ActionBatch) -> ActionBatch:
"""用物料默认配置补全新增节点,模型显式提供的字段优先"""
# 按物料编号建立索引,动作通过 component_key 选择具体预设
resources = state.get("component_resources")
materials = {item.key: item for item in resources.components} if resources else {}
materials = {item.key: item for item in state["component_resources"].components}
# 复制整批动作,补全配置时不改动调用方提供的动作对象
result = batch.model_copy(deep=True)
@@ -328,8 +323,7 @@ def validate_plan_actions(
}
# 物料按 key 索引,用于核对新增组件的类型和示例数据标记
resources = state.get("component_resources")
materials = {item.key: item for item in resources.components} if resources else {}
materials = {item.key: item for item in state["component_resources"].components}
seen: set[str] = set() # 已关联的新增规划编号
modified: set[str] = set() # 已覆盖的修改目标
@@ -439,6 +433,6 @@ def validate_plan_result(
code="scope_error", message=f"执行后的画布属性与规划不一致: {key}"
)
)
# 返回布局及画布结果错误,空列表表示这些最终值符合规划
return errors