|
1 | | -# Primitive nodes that are evaluated at backend. |
2 | | -from __future__ import annotations |
3 | | - |
4 | 1 | import sys |
| 2 | +from typing_extensions import override |
5 | 3 |
|
6 | | -from comfy.comfy_types.node_typing import ComfyNodeABC, InputTypeDict, IO |
| 4 | +from comfy_api.latest import ComfyExtension, io |
7 | 5 |
|
8 | 6 |
|
9 | | -class String(ComfyNodeABC): |
| 7 | +class String(io.ComfyNode): |
10 | 8 | @classmethod |
11 | | - def INPUT_TYPES(cls) -> InputTypeDict: |
12 | | - return { |
13 | | - "required": {"value": (IO.STRING, {})}, |
14 | | - } |
15 | | - |
16 | | - RETURN_TYPES = (IO.STRING,) |
17 | | - FUNCTION = "execute" |
18 | | - CATEGORY = "utils/primitive" |
| 9 | + def define_schema(cls): |
| 10 | + return io.Schema( |
| 11 | + node_id="PrimitiveString", |
| 12 | + display_name="String", |
| 13 | + category="utils/primitive", |
| 14 | + inputs=[ |
| 15 | + io.String.Input("value"), |
| 16 | + ], |
| 17 | + outputs=[io.String.Output()], |
| 18 | + ) |
19 | 19 |
|
20 | | - def execute(self, value: str) -> tuple[str]: |
21 | | - return (value,) |
| 20 | + @classmethod |
| 21 | + def execute(cls, value: str) -> io.NodeOutput: |
| 22 | + return io.NodeOutput(value) |
22 | 23 |
|
23 | 24 |
|
24 | | -class StringMultiline(ComfyNodeABC): |
| 25 | +class StringMultiline(io.ComfyNode): |
25 | 26 | @classmethod |
26 | | - def INPUT_TYPES(cls) -> InputTypeDict: |
27 | | - return { |
28 | | - "required": {"value": (IO.STRING, {"multiline": True,},)}, |
29 | | - } |
| 27 | + def define_schema(cls): |
| 28 | + return io.Schema( |
| 29 | + node_id="PrimitiveStringMultiline", |
| 30 | + display_name="String (Multiline)", |
| 31 | + category="utils/primitive", |
| 32 | + inputs=[ |
| 33 | + io.String.Input("value", multiline=True), |
| 34 | + ], |
| 35 | + outputs=[io.String.Output()], |
| 36 | + ) |
30 | 37 |
|
31 | | - RETURN_TYPES = (IO.STRING,) |
32 | | - FUNCTION = "execute" |
33 | | - CATEGORY = "utils/primitive" |
34 | | - |
35 | | - def execute(self, value: str) -> tuple[str]: |
36 | | - return (value,) |
| 38 | + @classmethod |
| 39 | + def execute(cls, value: str) -> io.NodeOutput: |
| 40 | + return io.NodeOutput(value) |
37 | 41 |
|
38 | 42 |
|
39 | | -class Int(ComfyNodeABC): |
| 43 | +class Int(io.ComfyNode): |
40 | 44 | @classmethod |
41 | | - def INPUT_TYPES(cls) -> InputTypeDict: |
42 | | - return { |
43 | | - "required": {"value": (IO.INT, {"min": -sys.maxsize, "max": sys.maxsize, "control_after_generate": True})}, |
44 | | - } |
| 45 | + def define_schema(cls): |
| 46 | + return io.Schema( |
| 47 | + node_id="PrimitiveInt", |
| 48 | + display_name="Int", |
| 49 | + category="utils/primitive", |
| 50 | + inputs=[ |
| 51 | + io.Int.Input("value", min=-sys.maxsize, max=sys.maxsize, control_after_generate=True), |
| 52 | + ], |
| 53 | + outputs=[io.Int.Output()], |
| 54 | + ) |
45 | 55 |
|
46 | | - RETURN_TYPES = (IO.INT,) |
47 | | - FUNCTION = "execute" |
48 | | - CATEGORY = "utils/primitive" |
49 | | - |
50 | | - def execute(self, value: int) -> tuple[int]: |
51 | | - return (value,) |
| 56 | + @classmethod |
| 57 | + def execute(cls, value: int) -> io.NodeOutput: |
| 58 | + return io.NodeOutput(value) |
52 | 59 |
|
53 | 60 |
|
54 | | -class Float(ComfyNodeABC): |
| 61 | +class Float(io.ComfyNode): |
55 | 62 | @classmethod |
56 | | - def INPUT_TYPES(cls) -> InputTypeDict: |
57 | | - return { |
58 | | - "required": {"value": (IO.FLOAT, {"min": -sys.maxsize, "max": sys.maxsize})}, |
59 | | - } |
| 63 | + def define_schema(cls): |
| 64 | + return io.Schema( |
| 65 | + node_id="PrimitiveFloat", |
| 66 | + display_name="Float", |
| 67 | + category="utils/primitive", |
| 68 | + inputs=[ |
| 69 | + io.Float.Input("value", min=-sys.maxsize, max=sys.maxsize), |
| 70 | + ], |
| 71 | + outputs=[io.Float.Output()], |
| 72 | + ) |
60 | 73 |
|
61 | | - RETURN_TYPES = (IO.FLOAT,) |
62 | | - FUNCTION = "execute" |
63 | | - CATEGORY = "utils/primitive" |
| 74 | + @classmethod |
| 75 | + def execute(cls, value: float) -> io.NodeOutput: |
| 76 | + return io.NodeOutput(value) |
64 | 77 |
|
65 | | - def execute(self, value: float) -> tuple[float]: |
66 | | - return (value,) |
67 | 78 |
|
| 79 | +class Boolean(io.ComfyNode): |
| 80 | + @classmethod |
| 81 | + def define_schema(cls): |
| 82 | + return io.Schema( |
| 83 | + node_id="PrimitiveBoolean", |
| 84 | + display_name="Boolean", |
| 85 | + category="utils/primitive", |
| 86 | + inputs=[ |
| 87 | + io.Boolean.Input("value"), |
| 88 | + ], |
| 89 | + outputs=[io.Boolean.Output()], |
| 90 | + ) |
68 | 91 |
|
69 | | -class Boolean(ComfyNodeABC): |
70 | 92 | @classmethod |
71 | | - def INPUT_TYPES(cls) -> InputTypeDict: |
72 | | - return { |
73 | | - "required": {"value": (IO.BOOLEAN, {})}, |
74 | | - } |
75 | | - |
76 | | - RETURN_TYPES = (IO.BOOLEAN,) |
77 | | - FUNCTION = "execute" |
78 | | - CATEGORY = "utils/primitive" |
79 | | - |
80 | | - def execute(self, value: bool) -> tuple[bool]: |
81 | | - return (value,) |
82 | | - |
83 | | - |
84 | | -NODE_CLASS_MAPPINGS = { |
85 | | - "PrimitiveString": String, |
86 | | - "PrimitiveStringMultiline": StringMultiline, |
87 | | - "PrimitiveInt": Int, |
88 | | - "PrimitiveFloat": Float, |
89 | | - "PrimitiveBoolean": Boolean, |
90 | | -} |
91 | | - |
92 | | -NODE_DISPLAY_NAME_MAPPINGS = { |
93 | | - "PrimitiveString": "String", |
94 | | - "PrimitiveStringMultiline": "String (Multiline)", |
95 | | - "PrimitiveInt": "Int", |
96 | | - "PrimitiveFloat": "Float", |
97 | | - "PrimitiveBoolean": "Boolean", |
98 | | -} |
| 93 | + def execute(cls, value: bool) -> io.NodeOutput: |
| 94 | + return io.NodeOutput(value) |
| 95 | + |
| 96 | + |
| 97 | +class PrimitivesExtension(ComfyExtension): |
| 98 | + @override |
| 99 | + async def get_node_list(self) -> list[type[io.ComfyNode]]: |
| 100 | + return [ |
| 101 | + String, |
| 102 | + StringMultiline, |
| 103 | + Int, |
| 104 | + Float, |
| 105 | + Boolean, |
| 106 | + ] |
| 107 | + |
| 108 | +async def comfy_entrypoint() -> PrimitivesExtension: |
| 109 | + return PrimitivesExtension() |
0 commit comments