fix: 流程图连线推导加固——个别节点漏 group 时按发射顺序就近归层(carry-forward)
弱模型可能漏标个别节点的 group,原逻辑一漏标就整体放弃推导导致节点平铺。改为漏 group 的 节点沿用前一节点的层级,只有开头无 group / 全程无 group 才回退模型连边。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cc06d3f4d2
commit
b8b71523b5
1 file changed
+12
-3
@@ -346,18 +346,27 @@ def _derive_layered_edges(nodes: list[dict[str, Any]]) -> list[dict[str, Any]] |
|
||||
返回 None 表示「无法可靠推导」(无 group / 只有一层 / 存在不规则层对),调用方回退模型连边。
|
||||
"""
|
||||
# 按 group 分层,保持每层内节点的原始顺序 + 层的首次出现顺序。
|
||||
# 加固:个别节点漏 group(弱模型可能漏标)→ 按发射顺序**就近归入前一个层级**(carry-forward),
|
||||
# 不再因一个漏标就整体放弃;只有连开头节点都没 group / 全程无任何 group 才放弃。
|
||||
order: list[str] = []
|
||||
layers: dict[str, list[str]] = {}
|
||||
last_group = ""
|
||||
any_group = False
|
||||
for n in nodes:
|
||||
g = _as_str(n.get("group"))
|
||||
if g:
|
||||
any_group = True
|
||||
last_group = g
|
||||
else:
|
||||
g = last_group # 漏 group → 沿用前一节点的层级
|
||||
if not g:
|
||||
return None # 有节点没层级 → 无法分层,回退模型连边
|
||||
return None # 开头节点就没 group,无法锚定层级 → 回退模型连边
|
||||
if g not in layers:
|
||||
layers[g] = []
|
||||
order.append(g)
|
||||
layers[g].append(n["id"])
|
||||
if len(order) < 2:
|
||||
return None # 只有一层,没有层间连线可推
|
||||
if not any_group or len(order) < 2:
|
||||
return None # 全程无 group / 只有一层 → 回退模型连边
|
||||
out: list[dict[str, Any]] = []
|
||||
for k in range(len(order) - 1):
|
||||
a = layers[order[k]]
|
||||
|
||||
Reference in new issue
Block a user