Compare commits

..

No commits in common. "e2cd1cb386671b87c03c90ca6cff7d4a12b95d47" and "3a5daf7dceb333ce47bbecc298a1293949b36142" have entirely different histories.

View File

@ -873,7 +873,7 @@ class DynamicInput(Input, ABC):
def get_dynamic(self) -> list[Input]:
return []
def expand_schema_for_dynamic(self, d: dict[str, Any], live_inputs: dict[str, Any], curr_prefix=''):
def add_to_dict_live_inputs(self, d: dict[str], live_inputs: dict[str], curr_prefix=''):
pass
@ -924,7 +924,7 @@ class Autogrow(ComfyTypeI):
def validate(self):
self.input.validate()
def expand_schema_for_dynamic(self, d: dict[str, Any], live_inputs: dict[str, Any], curr_prefix=''):
def add_to_dict_live_inputs(self, d: dict[str], live_inputs: dict[str], curr_prefix=''):
real_inputs = []
for name, input in self.cached_inputs.items():
if name in live_inputs:
@ -933,11 +933,13 @@ class Autogrow(ComfyTypeI):
add_dynamic_id_mapping(d, real_inputs, curr_prefix)
class TemplatePrefix(_AutogrowTemplate):
def __init__(self, input: Input, prefix: str, min: int=1, max: int=10):
def __init__(self, input: Input, prefix: str, min: int=1, max: int=None):
super().__init__(input)
self.prefix = prefix
assert(min >= 0)
assert(max >= 1)
if not max:
max = 10
assert(max >= 2)
assert(max <= Autogrow._MaxNames)
self.min = min
self.max = max
@ -969,6 +971,7 @@ class Autogrow(ComfyTypeI):
def __init__(self, id: str, template: Autogrow.TemplatePrefix | Autogrow.TemplateNames,
display_name: str=None, optional=False, tooltip: str=None, lazy: bool=None, extra_dict=None):
super().__init__(id, display_name, optional, tooltip, lazy, extra_dict)
# raise Exception("AutogrowDynamic is not implemented yet, and will likely be renamed for actual implementation.")
self.template = template
def as_dict(self):
@ -985,17 +988,17 @@ class Autogrow(ComfyTypeI):
def validate(self):
self.template.validate()
def expand_schema_for_dynamic(self, d: dict[str, Any], live_inputs: dict[str, Any], curr_prefix=''):
def add_to_dict_live_inputs(self, d: dict[str], live_inputs: dict[str], curr_prefix=''):
curr_prefix = f"{curr_prefix}{self.id}."
# need to remove self from expected inputs dictionary; replaced by template inputs in frontend
for inner_dict in d.values():
if self.id in inner_dict:
del inner_dict[self.id]
self.template.expand_schema_for_dynamic(d, live_inputs, curr_prefix)
self.template.add_to_dict_live_inputs(d, live_inputs, curr_prefix)
@comfytype(io_type="COMFY_DYNAMICCOMBO_V3")
class DynamicCombo(ComfyTypeI):
Type = dict[str, Any]
Type = dict[str]
class Option:
def __init__(self, key: str, inputs: list[Input]):
@ -1014,7 +1017,7 @@ class DynamicCombo(ComfyTypeI):
super().__init__(id, display_name, optional, tooltip, lazy, extra_dict)
self.options = options
def expand_schema_for_dynamic(self, d: dict[str, Any], live_inputs: dict[str, Any], curr_prefix=''):
def add_to_dict_live_inputs(self, d: dict[str], live_inputs: dict[str], curr_prefix=''):
# check if dynamic input's id is in live_inputs
if self.id in live_inputs:
curr_prefix = f"{curr_prefix}{self.id}."
@ -1047,7 +1050,7 @@ class DynamicCombo(ComfyTypeI):
@comfytype(io_type="COMFY_DYNAMICSLOT_V3")
class DynamicSlot(ComfyTypeI):
Type = dict[str, Any]
Type = dict[str]
class Input(DynamicInput):
def __init__(self, slot: Input, inputs: list[Input],
@ -1058,7 +1061,7 @@ class DynamicSlot(ComfyTypeI):
optional = True
self.slot.tooltip = slot.tooltip if slot.tooltip is not None else tooltip
self.slot.lazy = slot.lazy if slot.lazy is not None else lazy
self.slot.extra_dict = slot.extra_dict if slot.extra_dict is not None else extra_dict
self.slot.extra_dict = self.extra_dict if extra_dict is not None else extra_dict
super().__init__(slot.id, self.slot.display_name, optional, self.slot.tooltip, self.slot.lazy, self.slot.extra_dict)
self.inputs = inputs
self.force_input = None
@ -1067,7 +1070,7 @@ class DynamicSlot(ComfyTypeI):
self.force_input = True
self.slot.force_input = True
def expand_schema_for_dynamic(self, d: dict[str, Any], live_inputs: dict[str, Any], curr_prefix=''):
def add_to_dict_live_inputs(self, d: dict[str], live_inputs: dict[str], curr_prefix=''):
if self.id in live_inputs:
curr_prefix = f"{curr_prefix}{self.id}."
add_to_input_dict_v1(d, self.inputs, live_inputs, curr_prefix)
@ -1091,7 +1094,7 @@ class DynamicSlot(ComfyTypeI):
for input in self.inputs:
input.validate()
def add_dynamic_id_mapping(d: dict[str, Any], inputs: list[Input], curr_prefix: str, self: DynamicInput=None):
def add_dynamic_id_mapping(d: dict[str], inputs: list[Input], curr_prefix: str, self: DynamicInput=None):
dynamic = d.setdefault("dynamic_paths", {})
if self is not None:
dynamic[self.id] = f"{curr_prefix}{self.id}"
@ -1100,8 +1103,8 @@ def add_dynamic_id_mapping(d: dict[str, Any], inputs: list[Input], curr_prefix:
dynamic[f"{i.id}"] = f"{curr_prefix}{i.id}"
class V3Data(TypedDict):
hidden_inputs: dict[str, Any]
dynamic_paths: dict[str, Any]
hidden_inputs: dict[str]
dynamic_paths: dict[str]
class HiddenHolder:
def __init__(self, unique_id: str, prompt: Any,
@ -1293,8 +1296,7 @@ class Schema:
if output.id is None:
output.id = f"_{i}_{output.io_type}_"
def get_v1_info(self, cls, live_inputs: dict[str, Any]=None) -> NodeInfoV1:
# NOTE: live_inputs will not be used anymore very soon and this will be done another way
def get_v1_info(self, cls, live_inputs: dict[str]=None) -> NodeInfoV1:
# get V1 inputs
input = create_input_dict_v1(self.inputs, live_inputs)
if self.hidden:
@ -1377,19 +1379,19 @@ class Schema:
return info
def create_input_dict_v1(inputs: list[Input], live_inputs: dict[str, Any]=None) -> dict:
def create_input_dict_v1(inputs: list[Input], live_inputs: dict[str]=None) -> dict:
input = {
"required": {}
}
add_to_input_dict_v1(input, inputs, live_inputs)
return input
def add_to_input_dict_v1(d: dict[str, Any], inputs: list[Input], live_inputs: dict[str, Any]=None, curr_prefix=''):
def add_to_input_dict_v1(d: dict[str], inputs: list[Input], live_inputs: dict[str]=None, curr_prefix=''):
for i in inputs:
if isinstance(i, DynamicInput):
add_to_dict_v1(i, d)
if live_inputs is not None:
i.expand_schema_for_dynamic(d, live_inputs, curr_prefix)
i.add_to_dict_live_inputs(d, live_inputs, curr_prefix)
else:
add_to_dict_v1(i, d)
@ -1407,7 +1409,7 @@ def add_to_dict_v1(i: Input, d: dict, dynamic_dict: dict=None):
def add_to_dict_v3(io: Input | Output, d: dict):
d[io.id] = (io.get_io_type(), io.as_dict())
def build_nested_inputs(values: dict[str, Any], v3_data: V3Data):
def build_nested_inputs(values: dict[str], v3_data: V3Data):
paths = v3_data.get("dynamic_paths", None)
if paths is None:
return values