feat:优化处理流程
This commit is contained in:
+25
-17
@@ -1,30 +1,38 @@
|
||||
"""修改范围及后续能力需求"""
|
||||
"""修改范围及后续能力需求,由需求按规则推导,不调用模型"""
|
||||
|
||||
from typing import Literal, Self
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from pydantic import Field
|
||||
|
||||
from app.schemas.base import ExtensibleModel, NonBlankString
|
||||
from app.schemas.operations import is_screen_wide, requires_planning
|
||||
from app.schemas.requirement import Requirement
|
||||
|
||||
|
||||
class ChangeScope(ExtensibleModel):
|
||||
scope: Literal["local", "screen"] = Field(
|
||||
description="local=局部修改或新增;screen=整体设计或修改"
|
||||
description="local=只能改动 target_ids 中的已有组件;screen=整体调整,可涉及任意已有组件"
|
||||
)
|
||||
target_ids: list[NonBlankString] = Field(
|
||||
default_factory=list, description="涉及的已有组件 ID,新增内容和画布属性可为空"
|
||||
default_factory=list, description="需求明确指定的已有组件 ID,新增内容和画布属性可为空"
|
||||
)
|
||||
needs_planning: bool = Field(
|
||||
description="是否需要布局、组件组合或设计规划,与范围大小分别判断"
|
||||
)
|
||||
resource_needs: list[NonBlankString] = Field(
|
||||
default_factory=list,
|
||||
description="需要补充查询的数据、组件、模板或素材及用途,已有信息足够则为空",
|
||||
)
|
||||
reason: NonBlankString = Field(description="简短说明范围、规划和资源判断依据")
|
||||
needs_planning: bool = Field(description="是否需要布局、组件组合或设计规划")
|
||||
|
||||
@model_validator(mode="after")
|
||||
def unique_targets(self) -> Self:
|
||||
if len(self.target_ids) != len(set(self.target_ids)):
|
||||
raise ValueError("target_ids 不能包含重复 ID")
|
||||
return self
|
||||
@classmethod
|
||||
def from_requirement(cls, requirement: Requirement) -> Self:
|
||||
"""范围和是否规划都由需求变更决定,规则集中在 operations"""
|
||||
changes = requirement.changes
|
||||
return cls(
|
||||
scope=(
|
||||
"screen"
|
||||
if any(is_screen_wide(c.target_scope, c.operation) for c in changes)
|
||||
else "local"
|
||||
),
|
||||
# 保持需求中的出现顺序并去重
|
||||
target_ids=list(
|
||||
dict.fromkeys(node_id for c in changes for node_id in c.target_ids)
|
||||
),
|
||||
# 新建大屏总是先规划;修改大屏时按操作能力判断
|
||||
needs_planning=requirement.intent == "create_screen"
|
||||
or any(requires_planning(c.target_scope, c.operation) for c in changes),
|
||||
)
|
||||
|
||||
@@ -50,12 +50,20 @@ def is_direct_operation(target_scope: str, operation: str) -> bool:
|
||||
|
||||
|
||||
def requires_planning(target_scope: str, operation: str) -> bool:
|
||||
"""判断是否必须先规划;未登记的操作不在此列,由能力检查判为不支持"""
|
||||
return not is_direct_operation(target_scope, operation) and (
|
||||
operation in PLAN_ONLY_OPERATIONS
|
||||
"""判断是否必须先规划:新增、重排、更换类型,以及没有指定组件的整体调整
|
||||
未登记的操作不在此列,由能力检查判为不支持"""
|
||||
if is_direct_operation(target_scope, operation):
|
||||
return False
|
||||
return operation in PLAN_ONLY_OPERATIONS or (
|
||||
target_scope == "screen" and operation in PLAN_ADJUST_OPERATIONS
|
||||
)
|
||||
|
||||
|
||||
def is_screen_wide(target_scope: str, operation: str) -> bool:
|
||||
"""没有指定组件的整体调整(如整体重排、统一风格),可以涉及大屏上任意已有组件"""
|
||||
return target_scope == "screen" and operation != "add"
|
||||
|
||||
|
||||
def is_canvas_operation(target_scope: str, operation: str) -> bool:
|
||||
"""判断是否为画布属性修改"""
|
||||
return target_scope == "canvas" and operation in CANVAS_OPERATIONS
|
||||
|
||||
Reference in New Issue
Block a user