feat: 接入新动作 update_canvas

This commit is contained in:
2026-09-27 18:03:48 +08:00
parent 216051cd8d
commit eda1db1f88
12 changed files with 128 additions and 36 deletions
+28 -19
View File
@@ -16,29 +16,38 @@ from app.schemas.actions import ActionBatch, AddAction
def can_generate_actions(state: QueryState) -> bool:
return action_block_reason(state) is None
def action_block_reason(state: QueryState) -> str | None:
# 路由和失败说明共用能力判断,避免支持范围不一致
if state.get("screen_plan") is not None:
return plan_block_reason(state) is None
return plan_block_reason(state)
requirement = state["requirement"]
scope = state["change_scope"]
# 简单操作直接生成动作,复杂变更走规划分支
return (
requirement.intent == "modify_screen"
and not requirement.needs_clarification
and not scope.needs_planning
and not scope.resource_needs
and bool(requirement.changes)
and all(
if requirement.needs_clarification:
return "需求尚未澄清完整,不能生成动作"
if scope.needs_planning or requirement.intent != "modify_screen":
return "当前需求需要先完成规划,不能直接生成动作"
if scope.resource_needs:
return "尚未接入所需资源查询:" + ";".join(scope.resource_needs)
if not requirement.changes:
return "需求中没有可执行的变更"
unsupported = [
f"{change.target_scope}/{change.operation}"
for change in requirement.changes
if not (
change.target_scope == "nodes"
and change.operation
in (
"move",
"resize",
"update",
"delete",
)
for change in requirement.changes
and change.operation in ("move", "resize", "update", "delete")
or change.target_scope == "canvas"
and change.operation in ("update", "resize", "update_canvas")
)
)
]
if unsupported:
return "当前尚未支持的直接操作:" + "、".join(dict.fromkeys(unsupported))
return None
class ActionNode(BaseNode):
@@ -60,7 +69,7 @@ class ActionNode(BaseNode):
return updated_state
if not can_generate_actions(state):
raise ValueError(
"ActionNode 当前只支持无需规划和资源的 move、resize、update、delete 需求"
"ActionNode 当前只支持无需规划和资源的 move、resize、update、delete、update_canvas 需求"
)
payload = {
"input_context": state["input_context"].model_dump(mode="json"),