refactor(workflow): simplify edge configuration

This commit is contained in:
Xin Wang
2026-08-03 15:17:01 +08:00
parent dd40bfb90a
commit 8064bb7152
10 changed files with 53 additions and 205 deletions

View File

@@ -138,17 +138,17 @@ def node_types_response() -> dict[str, Any]:
def _edge_data_v3(edge: dict) -> dict:
data = deepcopy(edge.get("data") or {})
data.pop("transitionSpeech", None)
data.pop("transition_speech", None)
if data.get("mode") in EDGE_MODES:
data.setdefault("priority", 10)
return data
condition = str(data.pop("condition", "") or "").strip()
transition = data.pop("transition_speech", data.get("transitionSpeech", ""))
data.update(
{
"mode": "llm" if condition else "always",
"priority": 10,
"condition": condition,
"transitionSpeech": transition,
}
)
return data
@@ -234,6 +234,8 @@ def normalize_graph(graph: dict[str, Any] | None) -> dict[str, Any]:
_normalize_settings(settings)
source.setdefault("nodes", [])
source.setdefault("edges", [])
for edge in source["edges"]:
edge["data"] = _edge_data_v3(edge)
for node in source["nodes"]:
data = node.setdefault("data", {})
if node.get("type") == "start":
@@ -327,7 +329,7 @@ def normalize_graph(graph: dict[str, Any] | None) -> dict[str, Any]:
"id": f"e-{start_id}-{synthetic_id}",
"source": start_id,
"target": synthetic_id,
"data": {"mode": "always", "priority": 0, "transitionSpeech": ""},
"data": {"mode": "always", "priority": 0},
}
)