diff --git a/CHANGELOG.md b/CHANGELOG.md index 642d07e52..a2a06c572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ history. ### Added +- DynamicGroup workflow conversion, row editing and validation, including row + templates in node discovery and the widget catalog. Refuse incompatible saved + widget layouts and ambiguous names instead of editing a different widget. + - `comfy deploy cancel [PATH] [--deployment ]` ends the update a deployment waits on and keeps it serving the release it served; `--json` names the update it ended in `cancelledUpdate`, and nothing waiting exits 0 diff --git a/comfy_cli/command/nodes.py b/comfy_cli/command/nodes.py index c59718923..e74b654d5 100644 --- a/comfy_cli/command/nodes.py +++ b/comfy_cli/command/nodes.py @@ -1384,7 +1384,8 @@ def widget_catalog_cmd( { "code": "object_info_stale", "message": f"served from cache ({_stale['source']}): {_stale['reason']}", - } + }, + *payload.get("warnings", []), ] if select is not None: diff --git a/comfy_cli/command/templates.py b/comfy_cli/command/templates.py index cf5a61ebd..6aebdc00d 100644 --- a/comfy_cli/command/templates.py +++ b/comfy_cli/command/templates.py @@ -844,7 +844,7 @@ def _resolve_template_models(wf: Any, input_path: str | None) -> dict[str, Any]: """ if not isinstance(wf, dict) or not (input_path or os.environ.get("COMFY_OBJECT_INFO_FILE")): return {} - from comfy_cli.cql.engine import Graph + from comfy_cli.cql.engine import DynamicGroupBindingError, Graph from comfy_cli.cql.loader import resilient_load_object_info from comfy_cli.model_variants import resolve_workflow_models @@ -852,7 +852,10 @@ def _resolve_template_models(wf: Any, input_path: str | None) -> dict[str, Any]: graph = Graph.from_object_info(resilient_load_object_info(input_path=input_path)) except Exception as e: # noqa: BLE001 — a missing catalog only skips the check return {"model_check_skipped": f"could not load object_info: {e}"} - subs, unavailable = resolve_workflow_models(wf, graph) + try: + subs, unavailable = resolve_workflow_models(wf, graph) + except DynamicGroupBindingError as e: + return {"model_check_skipped": f"could not bind saved widgets: {e}"} notes: dict[str, Any] = {} if subs: notes["model_substitutions"] = subs diff --git a/comfy_cli/cql/engine.py b/comfy_cli/cql/engine.py index c58e4b42b..c51b03bfb 100644 --- a/comfy_cli/cql/engine.py +++ b/comfy_cli/cql/engine.py @@ -276,6 +276,10 @@ def is_autogrow(self) -> bool: ``images.image0``, ``images.image1``, … one per connection.""" return self.type.startswith("COMFY_AUTOGROW") + @property + def is_dynamic_group(self) -> bool: + return self.type == "COMFY_DYNAMICGROUP_V3" + @property def is_dynamic_combo(self) -> bool: """V3 dynamic combo (e.g. ``COMFY_DYNAMICCOMBO_V3``): the schema declares @@ -993,7 +997,7 @@ def _is_link( return False # A dynamic combo is a widget port even when its options block is missing # or malformed — the frontend always renders the selector inline. - if _is_dynamic_combo_type(type_id): + if _is_dynamic_combo_type(type_id) or type_id == "COMFY_DYNAMICGROUP_V3": return False if type_id in _FRONTEND_DOM_WIDGET_TYPES and not force_input: return False @@ -1730,7 +1734,8 @@ def widget_order_for_node(self, class_name: str, widgets_values: list[Any] | Non m = self._nodes.get(class_name) if m is None: return [] - return [e.name for e in _expand_widget_entries(m, widgets_values or [])] + defaults = widgets_values is None and any(p.is_dynamic_group for p in m.inputs) + return [e.name for e in _expand_widget_entries(m, widgets_values or [], first_key=defaults)] def editable_widget_names(self, class_name: str, widgets_values: list[Any] | None = None) -> list[str]: """The subset of :meth:`widget_order_for_node` a write may target — @@ -1738,7 +1743,8 @@ def editable_widget_names(self, class_name: str, widgets_values: list[Any] | Non m = self._nodes.get(class_name) if m is None: return [] - return _editable_widget_names(_expand_widget_entries(m, widgets_values or [])) + defaults = widgets_values is None and any(p.is_dynamic_group for p in m.inputs) + return _editable_widget_names(_expand_widget_entries(m, widgets_values or [], first_key=defaults)) def frontend_injected_widget_names(self, class_name: str) -> list[str]: """Names in the widget order that the frontend injects with no schema @@ -1975,7 +1981,15 @@ def validate_workflow(self, workflow: dict[str, Any]) -> dict[str, Any]: dyn_errors, dyn_warnings, dyn_valid_keys, dyn_unresolved = _check_dynamic_combos( node_id, class_type, m, node_inputs ) + group_errors: list[dict] = [] + group_warnings: list[dict] = [] + for group in (p for p in m.inputs if p.is_dynamic_group): + e, w, _ = _check_dynamic_group(node_id, class_type, group, node_inputs) + group_errors.extend(e) + group_warnings.extend(w) for input_name, value in node_inputs.items(): + if input_name in port_by_name and port_by_name[input_name].is_dynamic_group: + continue if ( "." in input_name and input_name.split(".", 1)[0] in dyn_port_names @@ -2289,6 +2303,7 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar # silently lose its dangling_edge error with nothing standing in # for it. warnings.extend(dyn_warnings) + warnings.extend(group_warnings) # Required-presence checks apply only to output-reachable nodes: the # server prunes unreachable nodes without validating them, so # enforcing required inputs on a disconnected node over-rejects a @@ -2299,6 +2314,7 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar errors.extend(_check_autogrow_required(node_id, autogrow_ports, autogrow_seen, node_data)) errors.extend(_check_required_present(node_id, m, node_data)) errors.extend(dyn_errors) + errors.extend(group_errors) # No-outputs check: the server rejects any prompt with zero output # nodes (execution.py:1155-1162, prompt_no_outputs) — including an @@ -2503,6 +2519,8 @@ def _widget_default(p: Port) -> Any: """The value a fresh node carries for widget port ``p`` — a dynamic combo's first key, else the schema default, else the first choice, else the DOM-widget placeholder, else ``None``.""" + if p.is_dynamic_group: + return p.options.min or 0 if p.dynamic_options: return p.enum_values[0] if p.enum_values else None if p.options.default is not None: @@ -2539,6 +2557,12 @@ def _input_payload(p: Port, depth: int) -> dict[str, Any]: "default": p.options.default, }, } + if p.is_dynamic_group: + entry["dynamic_group"] = { + "template": p.options.template, + "min": p.options.min if p.options.min is not None else 0, + "max": p.options.max if p.options.max is not None else 20, + } if p.is_autogrow: lo, hi = p.autogrow_limits template = p.autogrow_element_template or {} @@ -2756,6 +2780,70 @@ def _validate_catalog_value( return errors, warnings +def _check_dynamic_group( + node_id: str, class_type: str, port: Port, present: dict +) -> tuple[list[dict], list[dict], set[str]]: + errors: list[dict] = [] + warnings: list[dict] = [] + valid_keys: set[str] = set() + try: + if "." in port.name: + raise DynamicGroupBindingError("CLI does not support DynamicGroup inside DynamicCombo") + _validate_dynamic_group_port(port) + fields = _dynamic_group_fields(port) + except DynamicGroupBindingError as error: + errors.append( + {"node_id": node_id, "field": port.name, "code": "invalid_dynamic_group_schema", "message": str(error)} + ) + return errors, warnings, valid_keys + field_names = {field.name for field in fields} + rows: set[int] = set() + maximum = port.options.max if port.options.max is not None else 20 + minimum = port.options.min if port.options.min is not None else 0 + for key in present: + if not key.startswith(f"{port.name}."): + continue + index, separator, field = key[len(port.name) + 1 :].partition(".") + if ( + not separator + or not index.isascii() + or not index.isdecimal() + or (len(index) > 1 and index.startswith("0")) + or field not in field_names + or len(index) > len(str(maximum)) + or int(index) >= maximum + ): + errors.append( + { + "node_id": node_id, + "field": key, + "code": "invalid_dynamic_group_input", + "message": f"expected {port.name}..