HEL-892: add pinned frontend 1.41.20 grid reference conversion

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-30 06:15:35 +08:00
co-authored by multica-agent
parent 0609341afa
commit 638c59035f
49 changed files with 21095 additions and 9 deletions
@@ -13,6 +13,8 @@ from dataclasses import dataclass, field
from typing import Any
from uuid import UUID
GRID_PROFILE = "comfy-frontend-1.41.20-core-0.17.0-grid-reference"
SETGET_COMMIT = "ab72eda7ffad6280422d71ab7d54d3fb87c0ba18"
SETGET_PROFILES = {
f"comfy-frontend-{v}-kj-setget-ab72eda7-vhs-reference": v for v in ("1.37.11", "1.48.6")
@@ -802,3 +804,94 @@ def _expand(source, profile, widgets=False, case04=False):
"extra": deepcopy(source.get("extra", {})),
}
return Structure(graph, issues, unresolved, resolved)
def validate_grid_structure(source):
"""Only direct root links under the pinned 1.41.20 reference premise.
IMAGE -> IMAGE,MASK is the single supported MatchType specialization.
No UE implementation identity is inferred from an empty saved mapping.
"""
if (source.get("extra") or {}).get("frontendVersion") != "1.41.20":
raise ValueError("四宫格参考需要显式前端1.41.20")
if (source.get("definitions") or {}).get("subgraphs"):
raise ValueError("四宫格参考不覆盖子图")
extra = source.get("extra") or {}
if extra.get("workflowRendererVersion", "LG") != "LG":
raise ValueError("四宫格只覆盖LG保存态")
for key in ("ue_links", "links_added_by_ue"):
if key in extra and extra[key] != []:
raise ValueError("四宫格参考只覆盖空UE连线数组")
nodes = {}
for node in source["nodes"]:
nid = _id(node["id"])
if nid in nodes:
raise ValueError("重复节点ID")
nodes[nid] = node
if type(node.get("mode", 0)) is not int or node.get("mode", 0) != 0:
raise ValueError("四宫格仅正常mode=0")
if node.get("type") in ("Note", "MarkdownNote") and (
node.get("inputs") or node.get("outputs")
):
raise ValueError("虚拟说明节点不得带执行连线")
links = {}
for edge in source.get("links", []):
if not isinstance(edge, list) or len(edge) != 6:
raise ValueError("四宫格只接受六字段连线")
lid, a, oslot, b, islot, typ = edge
if type(lid) is not int or lid < 0 or lid in links:
raise ValueError("重复或非法连线ID")
a, b = _id(a), _id(b)
for nid, slot, direction in ((a, oslot, "outputs"), (b, islot, "inputs")):
if (
nid not in nodes
or type(slot) is not int
or not (0 <= slot < len(nodes[nid].get(direction, [])))
):
raise ValueError("连线原槽缺失或非法")
origin, target = nodes[a]["outputs"][oslot], nodes[b]["inputs"][islot]
accepted = origin.get("type") == target.get("type") == typ
if nodes[b].get("type") == "ResizeImageMaskNode" and target.get("name") == "input":
accepted = typ == origin.get("type") == "IMAGE" and target.get("type") == "IMAGE,MASK"
if not accepted:
raise ValueError("连线类型与精确槽不符,未覆盖的MatchType分支")
ids = origin.get("links") or []
if any(type(x) is not int for x in ids) or ids.count(lid) != 1:
raise ValueError("输出与连线不互指")
if type(target.get("link")) is not int or target["link"] != lid:
raise ValueError("输入与连线不互指")
links[lid] = edge
for nid, n in nodes.items():
for direction in ("inputs", "outputs"):
for slot, socket in enumerate(n.get(direction, [])):
ids = (
[socket["link"]]
if direction == "inputs" and socket.get("link") is not None
else (socket.get("links") or [])
if direction == "outputs"
else []
)
for lid in ids:
if type(lid) is not int or lid not in links:
raise ValueError("槽引用未知连线")
edge = links[lid]
offset = 1 if direction == "outputs" else 3
if [str(edge[offset]), edge[offset + 1]] != [nid, slot]:
raise ValueError("槽引用错误端点")
# graphToPrompt's execution ordering requires an acyclic direct graph here.
visiting, visited = set(), set()
def visit(nid):
if nid in visiting:
raise ValueError("四宫格参考不支持环")
if nid in visited:
return
visiting.add(nid)
for e in links.values():
if str(e[3]) == nid:
visit(str(e[1]))
visiting.remove(nid)
visited.add(nid)
for nid in nodes:
visit(nid)