feat:删除多余代码

This commit is contained in:
2026-10-01 07:32:02 -07:00
parent 071228c5f8
commit dd2fd8bcde
14 changed files with 25 additions and 833 deletions
+10 -136
View File
@@ -122,7 +122,9 @@ class ActionNode(BaseNode):
repairing=state.get("repair_plan") is not None,
)
# 需要写组件属性时提供相关组件的字段分组,模型再按需查询字段定义
with_fields = uses_material_fields(state["requirement"], state.get("screen_plan"))
with_fields = uses_material_fields(
state["requirement"], state.get("screen_plan")
)
if with_fields:
payload["field_groups"] = field_group_directory(state)
# 将本次具体资料放入用户消息,保留中文以便阅读和排查
@@ -140,10 +142,15 @@ class ActionNode(BaseNode):
try:
# 异步调用模型,根据需求、规划及是否正在修正选择对应的系统规则
if with_fields:
result = await invoke_with_field_tools(ActionBatch, system_prompt, content)
result = await invoke_with_field_tools(
ActionBatch, system_prompt, content
)
else:
result = await get_llm(ActionBatch).ainvoke(
[SystemMessage(content=system_prompt), HumanMessage(content=content)]
[
SystemMessage(content=system_prompt),
HumanMessage(content=content),
]
)
# 响应中没有工具调用时解析器会返回 None
@@ -190,136 +197,3 @@ class ActionNode(BaseNode):
# 返回待校验状态,此时 validation_passed 仍为 None,不代表动作已执行或通过校验
return updated_state
if __name__ == "__main__":
import asyncio
import sys
from pydantic import BaseModel
from app.processor.nodes.component_resource_node import ComponentResourceNode
from app.processor.nodes.input_node import InputNode
from app.processor.nodes.validator_node import ValidatorNode
from app.schemas.change_scope import ChangeScope
from app.schemas.requirement import Requirement
from app.schemas.screen_plan import ScreenPlan
async def main():
state = InputNode().process(
{
"request": {
"prompt": "将销售额统计向右移动 50px",
"screen": {
"canvas": {"width": 1920, "height": 1080},
"nodes": [
{
"id": "sales-chart",
"type": "chart",
"layout": {
"x": 100,
"y": 200,
"width": 400,
"height": 300,
},
}
],
},
}
}
)
state["requirement"] = Requirement(
intent="modify_screen",
goal="向右移动 50px",
needs_clarification=False,
changes=[
{
"target_scope": "nodes",
"target_ids": ["sales-chart"],
"operation": "move",
"parameters": {"delta_x": 50},
}
],
)
state["change_scope"] = ChangeScope(
scope="local",
target_ids=["sales-chart"],
needs_planning=False,
reason="明确的组件位移",
)
# 加 --add 测试规划到新增动作,默认仍测试简单移动
if "--add" in sys.argv:
state = InputNode().process(
{
"request": {
"prompt": "保留已有组件,在顶部新增销售总览标题",
"screen": state["input_context"].screen.model_dump(mode="json"),
}
}
)
state["requirement"] = Requirement(
intent="modify_screen",
goal="新增标题",
needs_clarification=False,
changes=[{"target_scope": "screen", "operation": "add"}],
)
state["change_scope"] = ChangeScope(
scope="local",
needs_planning=True,
reason="顶部新增标题",
)
state = ComponentResourceNode().process(state)
state["screen_plan"] = ScreenPlan(
goal="新增标题",
design_summary="顶部标题",
layout_description="保留原图表",
components=[
{
"plan_id": "heading",
"disposition": "add",
"component_type": "text",
"purpose": "显示销售总览",
"design": {"text": "销售总览"},
"layout": {"x": 100, "y": 40, "width": 500, "height": 60},
}
],
)
# 加 --modify 测试规划到已有组件调整,无需新增物料
if "--modify" in sys.argv:
state = ComponentResourceNode().process(state)
state["change_scope"].needs_planning = True
state["screen_plan"] = ScreenPlan(
goal="向右移动 50px",
design_summary="调整图表位置",
layout_description="保留尺寸,向右移动",
components=[
{
"plan_id": "sales-position",
"disposition": "modify",
"target_id": "sales-chart",
"purpose": "调整位置",
"layout": {"x": 150, "y": 200, "width": 400, "height": 300},
}
],
)
node = ActionNode()
final_state = await node.process(state)
if (
state.get("screen_plan") is not None
and final_state.get("actions") is not None
):
final_state = ValidatorNode().process(final_state)
print(
json.dumps(
final_state,
ensure_ascii=False,
indent=2,
default=lambda value: (
value.model_dump(mode="json")
if isinstance(value, BaseModel)
else str(value)
),
)
)
asyncio.run(main())