HEL-892: add pinned controlnet aux reference widget conversion
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""Small, explicit public-reference contract, never a target object_info snapshot.
|
||||
|
||||
Sources and limits: docs/hel-892/serialization-evidence/sources.json.
|
||||
Only unmodified scalar core widgets are covered. No plugin, dynamic prompt,
|
||||
seed controller, subgraph, bypass or custom serializeValue is inferred.
|
||||
Sources and limits: docs/hel-892/{serialization-evidence,controlnet-reference}/sources.json.
|
||||
Only explicitly pinned scalar layouts are covered. No dynamic prompt, seed
|
||||
controller, subgraph, bypass or custom serializeValue is inferred.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -10,6 +10,20 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
PROFILE = "comfy-frontend-1.37.11-core-reference"
|
||||
AUX_PROFILE = "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference"
|
||||
AUX_COMMIT = "e8b689a513c3e6b63edc44066560ca5919c0576e"
|
||||
# pyproject declares 1.1.5 at AUX_COMMIT; registry artifact mapping and target
|
||||
# installation remain unknown. This opt-in profile assumes unmodified widgets,
|
||||
# including no UE serializer changes. It never verifies dynamic combo membership.
|
||||
_AUX_LAYOUTS = {
|
||||
"AIO_Preprocessor": (("preprocessor", str), ("resolution", int)),
|
||||
"DepthAnythingPreprocessor": (("ckpt_name", str), ("resolution", int)),
|
||||
}
|
||||
_DEPTH_CHECKPOINTS = (
|
||||
"depth_anything_vitl14.pth",
|
||||
"depth_anything_vitb14.pth",
|
||||
"depth_anything_vits14.pth",
|
||||
)
|
||||
|
||||
# Widget construction order, including workflow-only upload button. A None type
|
||||
# is a workflow-persisted widget with options.serialize=false in graphToPrompt.
|
||||
@@ -26,8 +40,8 @@ _LAYOUTS = {
|
||||
}
|
||||
|
||||
|
||||
def reference_definitions() -> dict[str, Any]:
|
||||
"""Only public core reference schemas; no model/file availability assertion."""
|
||||
def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
|
||||
"""Only opt-in public reference schemas; no model/file availability assertion."""
|
||||
|
||||
def spec(required, outputs, optional=None):
|
||||
return {
|
||||
@@ -38,7 +52,9 @@ def reference_definitions() -> dict[str, Any]:
|
||||
"output": outputs,
|
||||
}
|
||||
|
||||
return {
|
||||
if profile not in (PROFILE, AUX_PROFILE):
|
||||
raise ValueError("未知参考版本")
|
||||
definitions = {
|
||||
"Canny": spec(
|
||||
{"image": "IMAGE", "low_threshold": "FLOAT", "high_threshold": "FLOAT"}, ["IMAGE"]
|
||||
),
|
||||
@@ -57,9 +73,22 @@ def reference_definitions() -> dict[str, Any]:
|
||||
"PreviewImage": spec({"images": "IMAGE"}, []),
|
||||
}
|
||||
|
||||
if profile == AUX_PROFILE:
|
||||
for ct, layout in _AUX_LAYOUTS.items():
|
||||
definitions[ct] = spec(
|
||||
{"image": "IMAGE"},
|
||||
["IMAGE"],
|
||||
{name: "INT" if kind is int else "COMBO" for name, kind in layout},
|
||||
)
|
||||
return definitions
|
||||
|
||||
def serialize_reference_widgets(node: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
def serialize_reference_widgets(node: dict[str, Any], profile: str = PROFILE) -> dict[str, Any]:
|
||||
"""Apply only the pinned identity serializers; reject any extra/missing value."""
|
||||
if profile not in (PROFILE, AUX_PROFILE):
|
||||
raise ValueError("未知参考版本")
|
||||
if profile == AUX_PROFILE and node.get("type") in _AUX_LAYOUTS:
|
||||
return _serialize_aux(node)
|
||||
if node.get("mode", 0) != 0:
|
||||
raise ValueError("静音/旁路不在序列化参考契约内")
|
||||
properties = node.get("properties") or {}
|
||||
@@ -87,6 +116,48 @@ def serialize_reference_widgets(node: dict[str, Any]) -> dict[str, Any]:
|
||||
return result
|
||||
|
||||
|
||||
def _serialize_aux(node: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Pinned optional widget order; no defaults or guessed dynamic options.
|
||||
|
||||
AIO strings are serialized verbatim, with membership explicitly unverified.
|
||||
DepthAnything's static enum proves a declared name, never file availability.
|
||||
Resolution bounds are schema metadata, not a clamp/rounding serializer.
|
||||
"""
|
||||
properties = node.get("properties") or {}
|
||||
if (
|
||||
node.get("mode", 0) != 0
|
||||
or properties.get("cnr_id") != "comfyui_controlnet_aux"
|
||||
or properties.get("ver") != "1.1.5"
|
||||
):
|
||||
raise ValueError("节点提供方/声明版本/模式不符合固定 aux 参考")
|
||||
layout = _AUX_LAYOUTS[node["type"]]
|
||||
values = node.get("widgets_values")
|
||||
if not isinstance(values, list) or len(values) != len(layout):
|
||||
raise ValueError("aux 控件必须为固定的两个标量;不补默认值")
|
||||
result = {}
|
||||
for (name, kind), value in zip(layout, values):
|
||||
if type(value) is not kind:
|
||||
raise ValueError(f"{name} 的类型不符合 aux 标量契约")
|
||||
result[name] = value
|
||||
if (
|
||||
node["type"] == "DepthAnythingPreprocessor"
|
||||
and result["ckpt_name"] not in _DEPTH_CHECKPOINTS
|
||||
):
|
||||
raise ValueError("ckpt_name 不在固定源码静态枚举内")
|
||||
socket_types = {"image": "IMAGE", layout[0][0]: "COMBO", "resolution": "INT"}
|
||||
sockets = node.get("inputs", [])
|
||||
names = [s.get("name") for s in sockets]
|
||||
if len(names) != len(set(names)) or "image" not in names:
|
||||
raise ValueError("aux 输入槽重复或缺少 image")
|
||||
for socket in sockets:
|
||||
if socket.get("type") != socket_types.get(socket.get("name")):
|
||||
raise ValueError("aux 输入槽名称/类型不符合固定参考")
|
||||
widget = socket.get("widget")
|
||||
if widget is not None and widget != {"name": socket["name"]}:
|
||||
raise ValueError("aux 输入控件绑定不符合固定参考")
|
||||
return result
|
||||
|
||||
|
||||
def validate_reroute(node: dict[str, Any]) -> None:
|
||||
if (
|
||||
node.get("mode", 0) != 0
|
||||
|
||||
@@ -13,6 +13,7 @@ from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from .serialization_reference import (
|
||||
AUX_PROFILE,
|
||||
PROFILE,
|
||||
reference_definitions,
|
||||
resolve_reference_link,
|
||||
@@ -38,21 +39,27 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
|
||||
An unknown profile is rejected, not interpreted as a widget-order contract.
|
||||
Public reference definitions cannot establish target execution eligibility.
|
||||
"""
|
||||
if profile != PROFILE or not isinstance(source, dict) or "nodes" not in source:
|
||||
if (
|
||||
profile not in (PROFILE, AUX_PROFILE)
|
||||
or not isinstance(source, dict)
|
||||
or "nodes" not in source
|
||||
):
|
||||
return Conversion(
|
||||
None,
|
||||
[{"code": "invalid_reference_contract", "message": "未知参考版本或不是 UI 图"}],
|
||||
True,
|
||||
)
|
||||
try:
|
||||
result = _convert(source, reference_definitions(), reference=True)
|
||||
result = _convert(
|
||||
source, reference_definitions(profile), reference=True, reference_profile=profile
|
||||
)
|
||||
except (ValueError, TypeError, KeyError, AttributeError, IndexError) as exc:
|
||||
return Conversion(None, [{"code": "invalid_reference_contract", "message": str(exc)}], True)
|
||||
result.reference_only = True
|
||||
return result
|
||||
|
||||
|
||||
def _convert(source, object_info=None, *, reference=False) -> Conversion:
|
||||
def _convert(source, object_info=None, *, reference=False, reference_profile=PROFILE) -> Conversion:
|
||||
issues: list[dict[str, Any]] = []
|
||||
|
||||
def fail(code: str, message: str, node_id: Any = "") -> None:
|
||||
@@ -154,7 +161,7 @@ def _convert(source, object_info=None, *, reference=False) -> Conversion:
|
||||
inputs = {}
|
||||
if reference:
|
||||
try:
|
||||
inputs.update(serialize_reference_widgets(node))
|
||||
inputs.update(serialize_reference_widgets(node, reference_profile))
|
||||
if [s.get("type") for s in node.get("outputs", [])] != spec["output"]:
|
||||
raise ValueError("源输出槽不符合固定参考契约")
|
||||
names = [s.get("name") for s in node.get("inputs", [])]
|
||||
|
||||
Reference in New Issue
Block a user