HEL-892: add explicit PreviewAny and promoted scalar reference conversion

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-30 00:54:36 +08:00
co-authored by multica-agent
parent 5e5cc03395
commit 7d4e3941ed
5 changed files with 848 additions and 34 deletions
@@ -1,6 +1,7 @@
"""Small, explicit public-reference contract, never a target object_info snapshot.
Sources and limits: docs/hel-892/{serialization-evidence,controlnet-reference}/sources.json.
Sources: docs/hel-892/{serialization-evidence,controlnet-reference,
promoted-reference,structure-reference}/sources.json.
Only explicitly pinned scalar layouts are covered. The subtitle opt-in also
folds direct Primitive STRING bindings. No seed controller, bypass, dynamic
extension or target installation is inferred.
@@ -13,6 +14,7 @@ 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"
PREVIEW_PROFILE = "comfy-frontend-1.37.11-preview-reference"
PRIMITIVE_PROFILE = "comfy-frontend-1.37.11-qwen-b037d7be-reference"
# Explicit earlier Qwen schema, not a claim about the installed plugin. Its
# 14 widgets differ from the newer reference's added normalize_text field.
@@ -77,7 +79,7 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
"output": outputs,
}
if profile not in (PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE):
if profile not in (PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE, PREVIEW_PROFILE):
raise ValueError("未知参考版本")
definitions = {
"Canny": spec(
@@ -105,7 +107,7 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
["IMAGE"],
{name: "INT" if kind is int else "COMBO" for name, kind in layout},
)
if profile == PRIMITIVE_PROFILE:
if profile in (PRIMITIVE_PROFILE, PREVIEW_PROFILE):
definitions["LoadAudio"] = spec({"audio": "COMBO"}, ["AUDIO"], {"audioUI": "AUDIO_UI"})
definitions["AILab_Qwen3ASRSubtitle"] = spec(
{"audio": "AUDIO"},
@@ -125,15 +127,22 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
for name, kind in _SUBTITLE_LAYOUT
},
)
if profile == PREVIEW_PROFILE:
definitions["PreviewAny"] = spec({"source": "*"}, [])
return definitions
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, PRIMITIVE_PROFILE):
if profile not in (PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE, PREVIEW_PROFILE):
raise ValueError("未知参考版本")
if profile == PRIMITIVE_PROFILE and node.get("type") in ("LoadAudio", "AILab_Qwen3ASRSubtitle"):
if profile in (PRIMITIVE_PROFILE, PREVIEW_PROFILE) and node.get("type") in (
"LoadAudio",
"AILab_Qwen3ASRSubtitle",
):
return _serialize_subtitle(node)
if profile == PREVIEW_PROFILE and node.get("type") == "PreviewAny":
return _serialize_preview(node)
if profile == AUX_PROFILE and node.get("type") in _AUX_LAYOUTS:
return _serialize_aux(node)
if node.get("mode", 0) != 0:
@@ -239,7 +248,7 @@ def fold_reference_primitives(source, profile):
primitives = [n for n in nodes.values() if n.get("type") == "PrimitiveNode"]
if not primitives:
return graph
if profile != PRIMITIVE_PROFILE:
if profile not in (PRIMITIVE_PROFILE, PREVIEW_PROFILE):
raise ValueError("Primitive 需要显式字幕/具名字符串参考契约")
# Validate all links before removing a virtual node or consuming a value.
for lid in links:
@@ -387,3 +396,154 @@ def resolve_reference_link(nodes, links, link_id) -> list[Any]:
link_id = upstream["inputs"][0].get("link")
if link_id is None:
raise ValueError("Reroute 无上游连线")
def _serialize_preview(node):
"""v1.37.11 configure skips the two serialize=false DOM widgets.
graphToPrompt instead checks options.serialize, so both named preview DOM
widgets participate (the second overwrites the first) and previewMode is
retained. The first persisted element restores previewMode; the two trailing
nulls are legacy workflow placeholders, NOT three fields to omit from API.
No DOM interaction or extension override is modelled by this profile.
"""
properties = node.get("properties") or {}
if (
node.get("mode", 0) != 0
or properties.get("cnr_id") != "comfy-core"
or properties.get("ver") != "0.11.0"
):
raise ValueError("PreviewAny 提供方/版本/模式不符合固定参考")
if any(k in node for k in ("widgets", "widgets_values_named", "serializeValue")):
raise ValueError("PreviewAny 自定义控件/具名恢复未证明")
values = node.get("widgets_values")
if (
not isinstance(values, list)
or len(values) != 3
or values[1:] != [None, None]
or (values[0] is not None and type(values[0]) is not bool)
):
raise ValueError("PreviewAny 仅覆盖布尔/null模式和两个null旧式占位")
sockets = node.get("inputs", [])
if (
len(sockets) != 1
or sockets[0].get("name") != "source"
or sockets[0].get("type") != "*"
or sockets[0].get("widget") is not None
):
raise ValueError("PreviewAny source 绑定不符")
return {"preview": "", "previewMode": values[0]}
# Direct scalar contracts proved by fixed core 0.31.0/0.38.0 schemas and
# corresponding frontend constructors. Binding a field is deliberately weaker
# than proving the whole node's serializer (e.g. TextGenerate dynamic combo).
_DIRECT = {
"UNETLoader": {"unet_name": "COMBO", "weight_dtype": "COMBO"},
"CLIPLoader": {"clip_name": "COMBO", "type": "COMBO", "device": "COMBO"},
"VAELoader": {"vae_name": "COMBO"},
"EmptyLatentImage": {"width": "INT", "height": "INT", "batch_size": "INT"},
"KSampler": {
"seed": "INT",
"steps": "INT",
"cfg": "FLOAT",
"sampler_name": "COMBO",
"scheduler": "COMBO",
"denoise": "FLOAT",
},
"ComfySwitchNode": {"switch": "BOOLEAN"},
"PrimitiveStringMultiline": {"value": "STRING"},
"PrimitiveBoolean": {"value": "BOOLEAN"},
"TextGenerate": {"prompt": "STRING", "thinking": "BOOLEAN"},
"TextEncodeQwenImage21": {"prompt": "STRING", "negative_prompt": "STRING", "resolution": "INT"},
"QwenImage21Cache": {"device": "COMBO", "dtype": "COMBO"},
}
_SIMPLE_LAYOUTS = {
"UNETLoader": ("unet_name", "weight_dtype"),
"CLIPLoader": ("clip_name", "type", "device"),
"VAELoader": ("vae_name",),
"EmptyLatentImage": ("width", "height", "batch_size"),
"PrimitiveStringMultiline": ("value",),
"PrimitiveBoolean": ("value",),
"QwenImage21Cache": ("device", "dtype"),
}
_SIMPLE_OUTPUTS = {
"UNETLoader": ["MODEL"],
"CLIPLoader": ["CLIP"],
"VAELoader": ["VAE"],
"EmptyLatentImage": ["LATENT"],
"PrimitiveStringMultiline": ["STRING"],
"QwenImage21Cache": ["MODEL"],
"PrimitiveBoolean": ["BOOLEAN"],
}
def direct_widget_type(node, socket, version):
"""Prove a named scalar binding, never infer one from source array order."""
props = node.get("properties") or {}
expected = "0.31.0" if version == "1.48.7" else "0.38.0"
ct, name = node.get("type"), socket.get("name")
if (
props.get("cnr_id") != "comfy-core"
or props.get("ver") != expected
or node.get("mode", 0) != 0
):
raise ValueError("内部节点提供方/版本/模式不符合固定参考")
if ct in ("TextGenerate", "TextEncodeQwenImage21", "QwenImage21Cache") and expected != "0.38.0":
raise ValueError("此节点未在固定0.31.0来源中证明")
kind = _DIRECT.get(ct, {}).get(name)
if kind is None or socket.get("type") != kind or socket.get("widget") != {"name": name}:
raise ValueError(f"未证明内部字段绑定:{ct}.{name}")
if any(k in node for k in ("widgets", "serializeValue")):
raise ValueError("自定义控件或具名恢复不在参考契约内")
return kind
def validate_direct_value(value, kind):
expected = {"COMBO": str, "STRING": str, "BOOLEAN": bool, "INT": int, "FLOAT": float}[kind]
if (expected is float and type(value) not in (float, int)) or (
expected is not float and type(value) is not expected
):
raise ValueError(f"边界值类型不符:{kind};null不等于缺项/false/0")
def promoted_definitions():
return {
ct: {
"input": {"required": {n: [t] for n, t in _DIRECT[ct].items()}, "optional": {}},
"output": _SIMPLE_OUTPUTS[ct],
}
for ct in _SIMPLE_LAYOUTS
} | {
"QwenImage21Cache": {
"input": {"required": {"model": ["MODEL"], "device": ["COMBO"], "dtype": ["COMBO"]}},
"output": ["MODEL"],
}
}
def serialize_promoted_node(node, version):
"""Only complete simple scalar layouts; no seed/dynamic/autogrow serializer."""
ct = node.get("type")
layout = _SIMPLE_LAYOUTS.get(ct)
values = node.get("widgets_values", [])
if layout is None or not isinstance(values, list) or len(values) != len(layout):
raise ValueError("未证明完整内部控件构造/序列化布局")
named = node.get("widgets_values_named")
if version == "1.53.6" and named is not None:
if (
not isinstance(named, dict)
or set(named) != set(layout)
or any(type(named[n]) is not type(v) or named[n] != v for n, v in zip(layout, values))
):
raise ValueError("具名/位置控件不一致;namedValuesRestore开关未知")
result = {}
for name, value in zip(layout, values):
# A widget can exist without an exposed input socket; its definition is
# pinned independently of the stored sockets.
kind = direct_widget_type(
node, {"name": name, "type": _DIRECT[ct][name], "widget": {"name": name}}, version
)
validate_direct_value(value, kind)
result[name] = value
return result
@@ -1,7 +1,8 @@
"""Pinned frontend structural projection, for diagnostics only.
"""Pinned frontend structure and opt-in direct promoted scalar projection.
Sources: docs/hel-892/structure-reference/sources.json. Does not serialize
promoted widgets, interpret third-party nodes, or establish execution eligibility.
Sources: docs/hel-892/{structure-reference,promoted-reference}/sources.json.
Structure profiles remain diagnostic. Direct values never prove complete ordinary
node serializers, third-party behavior, target versions or execution eligibility.
"""
from __future__ import annotations
@@ -17,12 +18,16 @@ STRUCTURE_PROFILES = {
}
PROMOTED_PROFILES = {f"comfy-frontend-{v}-promoted-reference": v for v in ("1.48.7", "1.53.6")}
@dataclass
class Structure:
graph: dict[str, Any] | None
issues: list[dict[str, Any]] = field(default_factory=list)
# These are boundary inputs whose frontend widget store cannot be reconstructed.
unresolved: list[dict[str, Any]] = field(default_factory=list)
resolved: list[dict[str, Any]] = field(default_factory=list)
def _id(value):
@@ -39,7 +44,7 @@ def _uuid(value):
return False
def expand_reference_subgraphs(source: dict, profile: str) -> Structure:
def expand_reference_subgraphs(source: dict, profile: str, *, widgets: bool = False) -> Structure:
"""Expand scoped nodes/links without consuming positional boundary widgets.
A returned graph is diagnostic data, never an executable prompt. Unbound
@@ -47,12 +52,12 @@ def expand_reference_subgraphs(source: dict, profile: str) -> Structure:
returns no graph, including malformed unused branches/definitions.
"""
try:
return _expand(source, profile)
return _expand(source, profile, widgets)
except (ValueError, TypeError, KeyError, AttributeError, IndexError, RecursionError) as exc:
return Structure(None, [{"code": "reference_structure_invalid", "message": str(exc)}])
def _expand(source, profile):
def _expand(source, profile, widgets=False):
version = STRUCTURE_PROFILES.get(profile)
if version is None or (source.get("extra") or {}).get("frontendVersion") != version:
raise ValueError("源前端声明与结构参考版本不符")
@@ -237,6 +242,152 @@ def _expand(source, profile):
return resolve(child, link[1], link[2], seen)
return [":".join((*path, str(nid))), slot]
resolved = []
if widgets:
from .serialization_reference import direct_widget_type, validate_direct_value
def targets(key, slot, stack=()):
marker = (key, slot)
if marker in stack:
raise ValueError("递归控件绑定")
definition = definitions[key]
found = []
for lid in definition["inputs"][slot]["linkIds"]:
edge = networks[key][1][str(lid)]
target = networks[key][0][str(edge[3])]
socket = target["inputs"][edge[4]]
if target["type"] in definitions:
found.extend(targets(target["type"], edge[4], stack + (marker,)))
elif socket.get("widget") is not None:
try:
kind = direct_widget_type(target, socket, version)
except ValueError:
kind = None
found.append((target, socket, kind))
return found
host_cache = {}
def host_values(path):
if path in host_cache:
return host_cache[path]
key, _, parent, instance = contexts[path]
definition = definitions[key]
props = instance.get("properties") or {}
if (
props.get("proxyWidgetErrorQuarantine")
or props.get("proxyWidgets")
or any(k in instance for k in ("widgets", "serializeValue"))
):
raise ValueError("隔离/代理/自定义控件覆盖不在promoted参考契约内")
names = [s["name"] for s in definition["inputs"]]
if len(names) != len(set(names)):
raise ValueError("重名稳定输入标识")
bindings = []
for slot, socket in enumerate(instance.get("inputs", [])):
bound = targets(key, slot)
if not bound:
if socket.get("widget") is not None:
raise ValueError("实例控件缺少可证明的内部绑定")
continue
kind = bound[0][2]
if kind is None:
raise ValueError(
f"首个内部绑定 {bound[0][0]['type']}.{bound[0][1]['name']} "
"无固定构造契约;无法重建host控件顺序"
)
compatible = all(
t == kind
and (n["type"], s["name"]) == (bound[0][0]["type"], bound[0][1]["name"])
for n, s, t in bound
)
# Differently constrained fanouts need their own compatibility
# proof; never propagate a value just because types coincide.
if socket.get("widget") != {"name": names[slot]} or socket.get("type") != kind:
raise ValueError("实例稳定widget.name或类型不符")
bindings.append((slot, kind, compatible))
values = instance.get("widgets_values", [])
if not isinstance(values, list) or len(values) != len(bindings):
raise ValueError("promoted控件数量不符;不静默回退内部默认值")
# Array offset is justified only after reconstructing every host
# widget via interior named bindings (SubgraphNode._resolveInputWidget).
result = {}
local_nodes = list(networks[parent[0]][0])
prefix = "/nodes/" + str(local_nodes.index(str(instance["id"])))
if parent[0] is not None:
prefix = (
"/definitions/subgraphs/" + str(list(definitions).index(parent[0])) + prefix
)
for index, (slot, kind, compatible) in enumerate(bindings):
value = values[index]
# Retain the persisted value for provenance. Type validation
# happens on scalar consumption; external links always win.
result[slot] = {
"value": value,
"value_pointer": prefix + "/widgets_values/" + str(index),
"binding_name": names[slot],
"binding_type": kind,
"compatible": compatible,
"boundary_instance": ":".join(path),
}
named = instance.get("widgets_values_named")
if version == "1.53.6" and named is not None:
if (
not isinstance(named, dict)
or set(named) != {v["binding_name"] for v in result.values()}
or any(
type(named[v["binding_name"]]) is not type(v["value"])
or named[v["binding_name"]] != v["value"]
for v in result.values()
)
):
raise ValueError("具名/位置host值不一致;namedValuesRestore开关未知")
for v in result.values():
name = v["binding_name"].replace("~", "~0").replace("/", "~1")
v["named_value_pointer"] = prefix + "/widgets_values_named/" + name
host_cache[path] = result
return result
def scalar(endpoint, node, socket):
path = tuple(endpoint["boundary_instance"].split(":"))
values = host_values(path)
slot = endpoint["slot"]
if slot not in values:
raise ValueError("无稳定promoted控件绑定;不采用内部现值")
value = values[slot]
if not value["compatible"]:
raise ValueError("多目标控件约束未知或不兼容")
kind = direct_widget_type(node, socket, version)
validate_direct_value(value["value"], kind)
if kind != value["binding_type"]:
raise ValueError("边界到内部字段类型不兼容")
return value
store_keys = {}
for path in contexts:
if not path:
continue
try:
values = host_values(path)
for value in values.values():
# Pinned store identity uses local instance ID, not the
# composite execution path. Conflicting nested definitions
# must not be advertised as isolated store values.
key = (path[-1], value["binding_name"])
previous = store_keys.get(key)
identity = (value["binding_type"], type(value["value"]), value["value"])
if previous is not None and previous != identity:
raise ValueError("嵌套host的局部widgetId冲突;存储值优先顺序未证明")
store_keys[key] = identity
except ValueError as exc:
issues.append(
{
"code": "promoted_host_unverified",
"node_id": ":".join(path),
"message": str(exc),
}
)
projected = []
for full, node in flat.items():
path = tuple(full.split(":"))
@@ -249,9 +400,40 @@ def _expand(source, profile):
original = networks[ctx[0]][1][str(lid)]
endpoint = resolve(ctx, original[1], original[2], set())
if isinstance(endpoint, dict):
unresolved.append(
{"node_id": full, "input_slot": slot, "input_name": socket["name"], **endpoint}
)
boundary = {
"node_id": full,
"input_slot": slot,
"input_name": socket["name"],
**endpoint,
}
if widgets:
try:
value = scalar(endpoint, node, socket)
except ValueError as exc:
unresolved.append({**boundary, "reason": str(exc)})
else:
local = list(networks[ctx[0]][0]).index(full.split(":")[-1])
prefix = "/nodes/" + str(local)
if ctx[0] is not None:
prefix = (
"/definitions/subgraphs/"
+ str(list(definitions).index(ctx[0]))
+ prefix
)
resolved.append(
{
**boundary,
**deepcopy(value),
"target_pointer": prefix + "/inputs/" + str(slot),
"precedence": [
"external_link",
"promoted_value",
"internal_serializer",
],
}
)
else:
unresolved.append(boundary)
continue
new_id = len(projected) + 1
projected.append([new_id, *endpoint, full, slot, original[5]])
@@ -285,4 +467,4 @@ def _expand(source, profile):
"links": projected,
"extra": deepcopy(source.get("extra", {})),
}
return Structure(graph, issues, unresolved)
return Structure(graph, issues, unresolved, resolved)
+63 -14
View File
@@ -15,15 +15,18 @@ from typing import Any
from .serialization_reference import (
AUX_PROFILE,
PREVIEW_PROFILE,
PRIMITIVE_PROFILE,
PROFILE,
fold_reference_primitives,
promoted_definitions,
reference_definitions,
resolve_reference_link,
serialize_promoted_node,
serialize_reference_widgets,
validate_reroute,
)
from .structure_reference import STRUCTURE_PROFILES, expand_reference_subgraphs
from .structure_reference import PROMOTED_PROFILES, STRUCTURE_PROFILES, expand_reference_subgraphs
@dataclass
@@ -33,6 +36,7 @@ class Conversion:
reference_only: bool = False
diagnostic_graph: dict[str, Any] | None = None
unresolved_boundaries: list[dict[str, Any]] = field(default_factory=list)
resolved_boundaries: list[dict[str, Any]] = field(default_factory=list)
def convert(source: Any, object_info: dict[str, Any] | None = None) -> Conversion:
@@ -46,7 +50,15 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
Public reference definitions cannot establish target execution eligibility.
"""
if (
profile not in (PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE, *STRUCTURE_PROFILES)
profile
not in (
PROFILE,
AUX_PROFILE,
PRIMITIVE_PROFILE,
PREVIEW_PROFILE,
*STRUCTURE_PROFILES,
*PROMOTED_PROFILES,
)
or not isinstance(source, dict)
or "nodes" not in source
):
@@ -56,34 +68,51 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
True,
)
try:
if profile in STRUCTURE_PROFILES:
structure = expand_reference_subgraphs(source, profile)
if profile in (*STRUCTURE_PROFILES, *PROMOTED_PROFILES):
promoted = profile in PROMOTED_PROFILES
structure_profile = profile.replace("-promoted-reference", "-structure-reference")
structure = expand_reference_subgraphs(source, structure_profile, widgets=promoted)
if structure.graph is None:
return Conversion(None, structure.issues, True)
# Structural scope never supplies widget contracts for newer versions.
# List the concrete remaining node gaps instead of one subgraph error.
result = _convert(structure.graph, {}, reference=True, reference_profile=profile)
result = _convert(
structure.graph,
promoted_definitions() if promoted else {},
reference=True,
reference_profile=profile,
boundary_values=structure.resolved,
)
result.issues = structure.issues + result.issues
for boundary in structure.unresolved:
result.issues.append(
{
"code": "boundary_widget_unverified",
**boundary,
"message": "边界无外部连线;不按位置猜 promoted widget 值",
"message": boundary.get(
"reason", "边界无外部连线;不按位置猜 promoted widget 值"
),
}
)
result.prompt = None
if not promoted or result.issues:
result.prompt = None
result.reference_only = True
result.diagnostic_graph = structure.graph
result.unresolved_boundaries = structure.unresolved
result.resolved_boundaries = structure.resolved
return result
if (
profile == PREVIEW_PROFILE
and (source.get("extra") or {}).get("frontendVersion") != "1.37.11"
):
raise ValueError("PreviewAny 需要显式1.37.11前端声明")
original = source
if profile == PRIMITIVE_PROFILE:
if profile in (PRIMITIVE_PROFILE, PREVIEW_PROFILE):
source = fold_reference_primitives(source, profile)
result = _convert(
source, reference_definitions(profile), reference=True, reference_profile=profile
)
if profile == PRIMITIVE_PROFILE and source != original:
if profile in (PRIMITIVE_PROFILE, PREVIEW_PROFILE) and source != original:
result.diagnostic_graph = source
except (ValueError, TypeError, KeyError, AttributeError, IndexError) as exc:
return Conversion(None, [{"code": "invalid_reference_contract", "message": str(exc)}], True)
@@ -91,7 +120,9 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
return result
def _convert(source, object_info=None, *, reference=False, reference_profile=PROFILE) -> Conversion:
def _convert(
source, object_info=None, *, reference=False, reference_profile=PROFILE, boundary_values=()
) -> Conversion:
issues: list[dict[str, Any]] = []
def fail(code: str, message: str, node_id: Any = "") -> None:
@@ -141,7 +172,9 @@ def _convert(source, object_info=None, *, reference=False, reference_profile=PRO
links[str(link[0])] = link
if reference:
frontend_version = (source.get("extra") or {}).get("frontendVersion")
expected_version = STRUCTURE_PROFILES.get(reference_profile, "1.37.11")
expected_version = {**STRUCTURE_PROFILES, **PROMOTED_PROFILES}.get(
reference_profile, "1.37.11"
)
if frontend_version is not None and frontend_version != expected_version:
fail("reference_frontend_mismatch", "源图声明的前端版本与固定参考不一致")
# Validate every stored link, even unused branches: never silently drop
@@ -194,12 +227,16 @@ def _convert(source, object_info=None, *, reference=False, reference_profile=PRO
inputs = {}
if reference:
try:
inputs.update(serialize_reference_widgets(node, reference_profile))
inputs.update(
serialize_promoted_node(node, PROMOTED_PROFILES[reference_profile])
if reference_profile in PROMOTED_PROFILES
else 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", [])]
allowed = set(declared) | ({"upload"} if ct == "LoadImage" else set())
if reference_profile == PRIMITIVE_PROFILE and ct == "LoadAudio":
if reference_profile in (PRIMITIVE_PROFILE, PREVIEW_PROFILE) and ct == "LoadAudio":
allowed |= {"upload", "audioUI"}
if len(names) != len(set(names)) or set(names) - allowed:
raise ValueError("额外或重复输入槽不在固定参考契约内")
@@ -217,6 +254,12 @@ def _convert(source, object_info=None, *, reference=False, reference_profile=PRO
nid,
)
continue
# graphToPrompt writes resolved promoted widgetInfo after the ordinary
# serializer, before/alongside resolved links. Values bypass the inner
# custom serializeValue; external links still take priority below.
for boundary in boundary_values:
if boundary["node_id"] == nid:
inputs[boundary["input_name"]] = boundary["value"]
for name, socket in sockets.items():
lid = socket.get("link")
if lid is None:
@@ -249,7 +292,13 @@ def _convert(source, object_info=None, *, reference=False, reference_profile=PRO
expected = declared[name][0] if declared[name] else None
actual = outputs[link[2]]
# Custom unions/wildcards need frontend evidence; do not guess coercions.
if expected != actual:
if expected != actual and not (
reference
and reference_profile == PREVIEW_PROFILE
and ct == "PreviewAny"
and name == "source"
and expected == "*"
):
fail(
"link_type_unverified",
f"输入 {name} 的槽类型不一致:{actual} → {expected}",