Skip to content

Commit ed6002c

Browse files
add support for kwargs inputs to allow arbitrary inputs from frontend (#12063)
used to output selected combo index Co-authored-by: Jedrzej Kosinski <kosinkadink1@gmail.com>
1 parent bc72d7f commit ed6002c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

comfy_api/latest/_io.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,8 @@ class Schema:
13831383
"""Flags a node as not idempotent; when True, the node will run and not reuse the cached outputs when identical inputs are provided on a different node in the graph."""
13841384
enable_expand: bool=False
13851385
"""Flags a node as expandable, allowing NodeOutput to include 'expand' property."""
1386+
accept_all_inputs: bool=False
1387+
"""When True, all inputs from the prompt will be passed to the node as kwargs, even if not defined in the schema."""
13861388

13871389
def validate(self):
13881390
'''Validate the schema:
@@ -1853,6 +1855,14 @@ def NOT_IDEMPOTENT(cls): # noqa
18531855
cls.GET_SCHEMA()
18541856
return cls._NOT_IDEMPOTENT
18551857

1858+
_ACCEPT_ALL_INPUTS = None
1859+
@final
1860+
@classproperty
1861+
def ACCEPT_ALL_INPUTS(cls): # noqa
1862+
if cls._ACCEPT_ALL_INPUTS is None:
1863+
cls.GET_SCHEMA()
1864+
return cls._ACCEPT_ALL_INPUTS
1865+
18561866
@final
18571867
@classmethod
18581868
def INPUT_TYPES(cls) -> dict[str, dict]:
@@ -1891,6 +1901,8 @@ def GET_SCHEMA(cls) -> Schema:
18911901
cls._INPUT_IS_LIST = schema.is_input_list
18921902
if cls._NOT_IDEMPOTENT is None:
18931903
cls._NOT_IDEMPOTENT = schema.not_idempotent
1904+
if cls._ACCEPT_ALL_INPUTS is None:
1905+
cls._ACCEPT_ALL_INPUTS = schema.accept_all_inputs
18941906

18951907
if cls._RETURN_TYPES is None:
18961908
output = []

comfy_extras/nodes_logic.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,23 @@ def define_schema(cls):
104104
category="utils",
105105
is_experimental=True,
106106
inputs=[io.Combo.Input("choice", options=[])],
107-
outputs=[io.String.Output()]
107+
outputs=[
108+
io.String.Output(display_name="STRING"),
109+
io.Int.Output(display_name="INDEX"),
110+
],
111+
accept_all_inputs=True,
108112
)
109113

110114
@classmethod
111-
def validate_inputs(cls, choice: io.Combo.Type) -> bool:
115+
def validate_inputs(cls, choice: io.Combo.Type, index: int = 0, **kwargs) -> bool:
112116
# NOTE: DO NOT DO THIS unless you want to skip validation entirely on the node's inputs.
113117
# I am doing that here because the widgets (besides the combo dropdown) on this node are fully frontend defined.
114118
# I need to skip checking that the chosen combo option is in the options list, since those are defined by the user.
115119
return True
116120

117121
@classmethod
118-
def execute(cls, choice: io.Combo.Type) -> io.NodeOutput:
119-
return io.NodeOutput(choice)
122+
def execute(cls, choice: io.Combo.Type, index: int = 0, **kwargs) -> io.NodeOutput:
123+
return io.NodeOutput(choice, index)
120124

121125

122126
class DCTestNode(io.ComfyNode):

execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def mark_missing():
175175
continue
176176
obj = cached.outputs[output_index]
177177
input_data_all[x] = obj
178-
elif input_category is not None:
178+
elif input_category is not None or (is_v3 and class_def.ACCEPT_ALL_INPUTS):
179179
input_data_all[x] = [input_data]
180180

181181
if is_v3:

0 commit comments

Comments
 (0)