feat:图表交互
This commit is contained in:
+25
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from app.actions.interaction import interaction_problems
|
||||
from app.actions.layout import EXPANDERS
|
||||
from app.actions.registry import apply_action
|
||||
from app.actions.update import fit_existing_path, same_value
|
||||
@@ -21,11 +22,17 @@ from app.schemas.screen import Screen, ScreenNode
|
||||
|
||||
|
||||
class BatchError(ValueError):
|
||||
"""整批中第 index 个动作(从 0 开始)失败,消息里带上序号和目标,模型据此修正"""
|
||||
"""整批中第 index 个动作(从 0 开始)失败,消息里带上序号和目标,模型据此修正
|
||||
|
||||
def __init__(self, index: int, action: AgentAction, reason: str):
|
||||
index 和 action 为 None 时是整批执行完后的检查失败(变量与交互的引用),不对应某一个动作
|
||||
"""
|
||||
|
||||
def __init__(self, index: int | None, action: AgentAction | None, reason: str):
|
||||
self.index = index
|
||||
self.reason = reason
|
||||
if action is None:
|
||||
super().__init__(f"整批执行后检查:{reason}")
|
||||
return
|
||||
if isinstance(action, AddAction):
|
||||
target = action.node.id
|
||||
elif ids := getattr(action, "target_ids", None):
|
||||
@@ -125,6 +132,8 @@ def run_batch(
|
||||
布局意图(arrange、align、distribute、set_layout)在这里按当时的大屏展开成 move 和 resize
|
||||
update 写入的值和字段现在的值完全一样时没有变化,跳过:不经过字段契约、也不交付;
|
||||
模型常把已经正确的值再写一遍(例如已经是 category 的轴类型),字段不在契约里时整批都会失败
|
||||
全部执行完再检查一次变量与交互的引用(interaction_problems):一批里常常先加组件后声明变量;
|
||||
只拦这一批新出现的问题,大屏原有的问题(用户在编辑器里保存的)不挡住无关的修改
|
||||
"""
|
||||
current = screen.model_copy(deep=True)
|
||||
completed: list[Action] = []
|
||||
@@ -154,4 +163,18 @@ def run_batch(
|
||||
except ValueError as error: # 含 pydantic ValidationError
|
||||
raise BatchError(index, action, str(error)) from error
|
||||
completed.append(action)
|
||||
# 按问题的 key 比较:措辞里的列清单这类上下文变了,原有的问题仍是原有的
|
||||
existing = {item.key for item in interaction_problems(screen, catalog)}
|
||||
if problems := [
|
||||
item.message
|
||||
for item in interaction_problems(current, catalog)
|
||||
if item.key not in existing
|
||||
]:
|
||||
# 这一批整个没写入:缺的部分要和原来的动作一起重新提交,分到下一批时这一批永远通不过
|
||||
raise BatchError(
|
||||
None,
|
||||
None,
|
||||
";".join(problems)
|
||||
+ "。这一批没有写入:把补上的部分和原来的动作放在同一批里重新提交",
|
||||
)
|
||||
return completed, current
|
||||
|
||||
Reference in New Issue
Block a user