@hanzo/studio 0.1.8 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app/director.d.ts +134 -0
- package/lib/app/director.js +1196 -0
- package/lib/app/flow-run.d.ts +34 -0
- package/lib/app/flow-run.js +77 -0
- package/lib/app/flow.d.ts +58 -0
- package/lib/app/flow.js +1213 -0
- package/lib/app/sections.d.ts +5 -0
- package/lib/app/sections.js +26 -0
- package/lib/attach.d.ts +2 -0
- package/lib/attach.js +7 -0
- package/lib/chat/turn.js +19 -11
- package/lib/desk.d.ts +1 -1
- package/lib/desk.js +370 -14
- package/lib/download.d.ts +2 -0
- package/lib/download.js +11 -0
- package/lib/gpu.d.ts +13 -1
- package/lib/gpu.js +39 -16
- package/lib/handoff.d.ts +2 -0
- package/lib/handoff.js +2 -0
- package/lib/home.d.ts +3 -1
- package/lib/home.js +98 -9
- package/lib/index.d.ts +7 -0
- package/lib/index.js +6 -0
- package/lib/kinds/app.d.ts +40 -0
- package/lib/kinds/app.js +907 -0
- package/lib/kinds/document.js +256 -19
- package/lib/kinds/image.d.ts +3 -0
- package/lib/kinds/image.js +82 -10
- package/lib/kinds/index.js +2 -1
- package/lib/kinds/sound.js +109 -10
- package/lib/kinds/video.js +146 -17
- package/lib/live.d.ts +11 -0
- package/lib/live.js +10 -0
- package/lib/made.d.ts +2 -1
- package/lib/made.js +1 -0
- package/lib/pdf.js +1 -1
- package/lib/places.d.ts +0 -3
- package/lib/places.js +185 -41
- package/lib/route.d.ts +18 -0
- package/lib/route.js +23 -0
- package/lib/starters.d.ts +21 -0
- package/lib/starters.js +33 -2
- package/lib/studio.js +1 -1
- package/lib/talk.js +149 -46
- package/lib/ui.d.ts +18 -4
- package/lib/ui.js +50 -22
- package/lib/wire.d.ts +19 -6
- package/lib/wire.js +36 -3
- package/package.json +1 -1
package/lib/app/flow.js
ADDED
|
@@ -0,0 +1,1213 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SizableText, styled, XStack, YStack } from '@hanzo/gui';
|
|
3
|
+
import { ArrowLeft, Boxes, Check, ChevronDown, Code, Download, Layers, Maximize2, Minus, Play, Plus, Redo2, Terminal, Undo2, Upload, Wand2, Workflow, } from '@hanzogui/lucide-icons-2';
|
|
4
|
+
import { DropdownMenu } from '@hanzo/ui';
|
|
5
|
+
import { createElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { download } from '../download.js';
|
|
7
|
+
import { reducedMotion, RING } from '../ui.js';
|
|
8
|
+
import { parseFlowSection } from './sections.js';
|
|
9
|
+
import { BRAIN, useWire } from '../live.js';
|
|
10
|
+
import { complete, objectInfo } from '../wire.js';
|
|
11
|
+
import { graphEdit, run, runs } from './flow-run.js';
|
|
12
|
+
const FlowInput = styled(SizableText, {
|
|
13
|
+
name: 'FlowFieldInput',
|
|
14
|
+
render: 'input',
|
|
15
|
+
size: '$2',
|
|
16
|
+
width: '100%',
|
|
17
|
+
minW: 0,
|
|
18
|
+
minH: 44,
|
|
19
|
+
$md: { minH: 34, height: 34 },
|
|
20
|
+
px: '$2.5',
|
|
21
|
+
rounded: '$3',
|
|
22
|
+
borderWidth: 1,
|
|
23
|
+
borderColor: 'var(--border-strong)',
|
|
24
|
+
bg: 'var(--background)',
|
|
25
|
+
color: '$ink',
|
|
26
|
+
focusVisibleStyle: RING,
|
|
27
|
+
});
|
|
28
|
+
const FlowTextarea = styled(SizableText, {
|
|
29
|
+
name: 'FlowFieldTextarea',
|
|
30
|
+
render: 'textarea',
|
|
31
|
+
size: '$2',
|
|
32
|
+
fontFamily: '$mono',
|
|
33
|
+
width: '100%',
|
|
34
|
+
minW: 0,
|
|
35
|
+
p: '$3',
|
|
36
|
+
rounded: '$3',
|
|
37
|
+
borderWidth: 1,
|
|
38
|
+
borderColor: 'var(--border-strong)',
|
|
39
|
+
bg: 'var(--background)',
|
|
40
|
+
color: '$ink',
|
|
41
|
+
focusVisibleStyle: RING,
|
|
42
|
+
});
|
|
43
|
+
const FlowInspectorTextarea = styled(SizableText, {
|
|
44
|
+
name: 'FlowInspectorTextarea',
|
|
45
|
+
render: 'textarea',
|
|
46
|
+
size: '$2',
|
|
47
|
+
width: '100%',
|
|
48
|
+
minW: 0,
|
|
49
|
+
p: '$2.5',
|
|
50
|
+
rounded: '$3',
|
|
51
|
+
borderWidth: 1,
|
|
52
|
+
borderColor: 'var(--border-strong)',
|
|
53
|
+
bg: 'var(--pane-fill, var(--background))',
|
|
54
|
+
color: '$ink',
|
|
55
|
+
focusVisibleStyle: RING,
|
|
56
|
+
});
|
|
57
|
+
const MULTILINE_INPUT_KEYS = new Set(['input_value', 'system_prompt', 'text', 'instruction', 'prompt', 'lyrics', 'template', 'paths']);
|
|
58
|
+
export { parseFlowSection };
|
|
59
|
+
export function flowNav(host, go) {
|
|
60
|
+
const active = parseFlowSection(host.path);
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
id: 'make',
|
|
64
|
+
label: 'Hanzo Flow',
|
|
65
|
+
links: [
|
|
66
|
+
{
|
|
67
|
+
id: 'canvas',
|
|
68
|
+
label: 'Flow canvas & playground',
|
|
69
|
+
active: active === 'canvas',
|
|
70
|
+
icon: createElement(Workflow, { size: 16 }),
|
|
71
|
+
onPress: () => go(''),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'comfy',
|
|
75
|
+
label: 'ComfyUI node extensions',
|
|
76
|
+
active: active === 'comfy',
|
|
77
|
+
icon: createElement(Layers, { size: 16 }),
|
|
78
|
+
onPress: () => go('comfy'),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'agents',
|
|
82
|
+
label: 'Langflow agents, RAG & MCP',
|
|
83
|
+
active: active === 'agents',
|
|
84
|
+
icon: createElement(Boxes, { size: 16 }),
|
|
85
|
+
onPress: () => go('agents'),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'code',
|
|
89
|
+
label: 'Python node code editor',
|
|
90
|
+
active: active === 'code',
|
|
91
|
+
icon: createElement(Code, { size: 16 }),
|
|
92
|
+
onPress: () => go('code'),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'publish',
|
|
96
|
+
label: 'Publish REST / MCP / JSON',
|
|
97
|
+
active: active === 'publish',
|
|
98
|
+
icon: createElement(Terminal, { size: 16 }),
|
|
99
|
+
onPress: () => go('publish'),
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
export const FLOW_MODULE_CATALOG = [
|
|
106
|
+
// ── LANGFLOW AGENT / LLM / RAG / MCP / PYTHON NODES ─────────────────────────
|
|
107
|
+
{
|
|
108
|
+
type: 'ChatInput',
|
|
109
|
+
title: 'Chat / Multimodal Input',
|
|
110
|
+
family: 'langflow',
|
|
111
|
+
pack: 'hanzo-flow (MIT)',
|
|
112
|
+
category: 'agent',
|
|
113
|
+
inputPorts: [],
|
|
114
|
+
outputPorts: ['MESSAGE'],
|
|
115
|
+
defaultInputs: { input_value: 'Create a 24mm anamorphic cyberpunk rooftop trailer shot with synthwave score', files: '' },
|
|
116
|
+
pythonSource: `from flow.custom import Component\nfrom flow.io import MessageTextInput, Output\n\nclass ChatInputComponent(Component):\n display_name = "Chat Input"\n inputs = [MessageTextInput(name="input_value", display_name="Text")]\n outputs = [Output(display_name="Message", name="message", method="message_response")]\n\n def message_response(self) -> str:\n return self.input_value`,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: 'ZenAgentNode',
|
|
120
|
+
title: 'Hanzo Zen Agent (Prompt & Tool Router)',
|
|
121
|
+
family: 'langflow',
|
|
122
|
+
pack: 'hanzo-flow (MIT)',
|
|
123
|
+
category: 'agent',
|
|
124
|
+
inputPorts: ['input_message', 'tools', 'context'],
|
|
125
|
+
outputPorts: ['PROMPT', 'JSON_SPEC'],
|
|
126
|
+
defaultInputs: { model: 'zen5', system_prompt: 'Expand user brief into a precision ComfyUI camera rig + lighting prompt.', temperature: 0.3 },
|
|
127
|
+
pythonSource: `from flow.custom import Component\nfrom flow.io import MessageTextInput, DropdownInput, Output\n\nclass ZenAgentComponent(Component):\n display_name = "Hanzo Zen Agent"\n def run_agent(self) -> str:\n return self.llm.invoke(self.input_message)`,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: 'PromptTemplateNode',
|
|
131
|
+
title: 'Prompt Template ({variables})',
|
|
132
|
+
family: 'langflow',
|
|
133
|
+
pack: 'hanzo-flow (MIT)',
|
|
134
|
+
category: 'agent',
|
|
135
|
+
inputPorts: ['variables'],
|
|
136
|
+
outputPorts: ['PROMPT'],
|
|
137
|
+
defaultInputs: { template: '{subject}, shot on {lens}, {lighting}, {camera_rig}, photorealistic 8k' },
|
|
138
|
+
pythonSource: `from flow.custom import Component\n\nclass PromptTemplateComponent(Component):\n display_name = "Prompt Template"\n def build_prompt(self) -> str:\n return self.template.format(**self.variables)`,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: 'MCPToolNode',
|
|
142
|
+
title: 'MCP Server Tool Connector',
|
|
143
|
+
family: 'langflow',
|
|
144
|
+
pack: 'hanzo-flow (MIT)',
|
|
145
|
+
category: 'agent',
|
|
146
|
+
inputPorts: ['query'],
|
|
147
|
+
outputPorts: ['TOOL', 'CONTEXT'],
|
|
148
|
+
defaultInputs: { server: 'hanzo-mcp', tool_name: 'search_brand_assets', transport: 'sse' },
|
|
149
|
+
pythonSource: `from flow.custom import Component\n\nclass MCPToolComponent(Component):\n display_name = "MCP Tool Client"\n async def call_tool(self):\n return await self.mcp_client.call(self.tool_name, self.query)`,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: 'VectorStoreRAG',
|
|
153
|
+
title: 'Vector Store RAG (Brand & Lore Memory)',
|
|
154
|
+
family: 'langflow',
|
|
155
|
+
pack: 'hanzo-flow (MIT)',
|
|
156
|
+
category: 'agent',
|
|
157
|
+
inputPorts: ['search_query'],
|
|
158
|
+
outputPorts: ['CONTEXT'],
|
|
159
|
+
defaultInputs: { collection: 'brand_lookbook_v3', top_k: 4, embedding_model: 'zen-embed-1' },
|
|
160
|
+
pythonSource: `from flow.custom import Component\n\nclass VectorStoreRAGComponent(Component):\n display_name = "Hanzo Vector RAG"\n def retrieve(self) -> list:\n return self.vector_db.similarity_search(self.search_query, k=self.top_k)`,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: 'PythonSandboxNode',
|
|
164
|
+
title: 'Python Custom Component (exec)',
|
|
165
|
+
family: 'langflow',
|
|
166
|
+
pack: 'hanzo-flow (MIT)',
|
|
167
|
+
category: 'agent',
|
|
168
|
+
inputPorts: ['data'],
|
|
169
|
+
outputPorts: ['DATA', 'IMAGE'],
|
|
170
|
+
defaultInputs: { script_name: 'custom_transform.py', timeout_sec: 30 },
|
|
171
|
+
pythonSource: `from studio_compat import io\nimport torch\n\nclass CustomStudioNode(io.ComfyNode):\n @classmethod\n def INPUT_TYPES(cls):\n return {"required": {"images": ("IMAGE",), "gain": ("FLOAT", {"default": 1.15})}}\n RETURN_TYPES = ("IMAGE",)\n FUNCTION = "execute"\n def execute(self, images, gain):\n return (torch.clamp(images * gain, 0.0, 1.0),)`,
|
|
172
|
+
},
|
|
173
|
+
// ── COMFYUI / STUDIO_COMPAT NATIVE MEDIA EXTENSIONS ─────────────────────────
|
|
174
|
+
{
|
|
175
|
+
type: 'UNETLoader',
|
|
176
|
+
title: 'Load UNet Diffusion Model',
|
|
177
|
+
family: 'comfy',
|
|
178
|
+
pack: 'studio-core (ComfyUI)',
|
|
179
|
+
category: 'loader',
|
|
180
|
+
inputPorts: [],
|
|
181
|
+
outputPorts: ['MODEL'],
|
|
182
|
+
defaultInputs: { unet_name: 'wan2.2_ti2v_5B_fp16.safetensors', weight_dtype: 'fp16' },
|
|
183
|
+
pythonSource: `class UNETLoader:\n @classmethod\n def INPUT_TYPES(s):\n return {"required": {"unet_name": (folder_paths.get_filename_list("diffusion_models"),), "weight_dtype": (["default", "fp16", "bf16", "fp8_e4m3fn"],)}}\n RETURN_TYPES = ("MODEL",)\n FUNCTION = "load_unet"`,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: 'CLIPLoader',
|
|
187
|
+
title: 'Load CLIP / UMT5 Text Encoder',
|
|
188
|
+
family: 'comfy',
|
|
189
|
+
pack: 'studio-core (ComfyUI)',
|
|
190
|
+
category: 'loader',
|
|
191
|
+
inputPorts: [],
|
|
192
|
+
outputPorts: ['CLIP'],
|
|
193
|
+
defaultInputs: { clip_name: 'umt5_xxl_fp8_e4m3fn_scaled.safetensors', type: 'wan' },
|
|
194
|
+
pythonSource: `class CLIPLoader:\n RETURN_TYPES = ("CLIP",)\n FUNCTION = "load_clip"`,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
type: 'CheckpointLoaderSimple',
|
|
198
|
+
title: 'Load Checkpoint (Model+CLIP+VAE)',
|
|
199
|
+
family: 'comfy',
|
|
200
|
+
pack: 'studio-core (ComfyUI)',
|
|
201
|
+
category: 'loader',
|
|
202
|
+
inputPorts: [],
|
|
203
|
+
outputPorts: ['MODEL', 'CLIP', 'VAE'],
|
|
204
|
+
defaultInputs: { ckpt_name: 'z_image_turbo_bf16.safetensors' },
|
|
205
|
+
pythonSource: `class CheckpointLoaderSimple:\n RETURN_TYPES = ("MODEL", "CLIP", "VAE")\n FUNCTION = "load_checkpoint"`,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
type: 'UnetLoaderGGUF',
|
|
209
|
+
title: 'Load GGUF Quantized Model',
|
|
210
|
+
family: 'comfy',
|
|
211
|
+
pack: 'ComfyUI-GGUF (Apache-2.0)',
|
|
212
|
+
category: 'loader',
|
|
213
|
+
inputPorts: [],
|
|
214
|
+
outputPorts: ['MODEL'],
|
|
215
|
+
defaultInputs: { unet_name: 'flux1-dev-Q8_0.gguf' },
|
|
216
|
+
pythonSource: `class UnetLoaderGGUF:\n RETURN_TYPES = ("MODEL",)\n FUNCTION = "load_unet"`,
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
type: 'ImageOnlyCheckpointLoader',
|
|
220
|
+
title: 'Load Hunyuan3D 2.1 Checkpoint',
|
|
221
|
+
family: 'comfy',
|
|
222
|
+
pack: 'studio-core 3D (ComfyUI)',
|
|
223
|
+
category: 'loader',
|
|
224
|
+
inputPorts: [],
|
|
225
|
+
outputPorts: ['MODEL', 'CLIP_VISION', 'VAE'],
|
|
226
|
+
defaultInputs: { ckpt_name: 'hunyuan_3d_v2.1.safetensors' },
|
|
227
|
+
pythonSource: `class ImageOnlyCheckpointLoader:\n RETURN_TYPES = ("MODEL", "CLIP_VISION", "VAE")\n FUNCTION = "load_checkpoint"`,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: 'LoadImageMask',
|
|
231
|
+
title: 'Load Image + Inpaint Mask',
|
|
232
|
+
family: 'comfy',
|
|
233
|
+
pack: 'studio-core (ComfyUI)',
|
|
234
|
+
category: 'loader',
|
|
235
|
+
inputPorts: [],
|
|
236
|
+
outputPorts: ['IMAGE', 'MASK'],
|
|
237
|
+
defaultInputs: { image: 'hero_lookbook.png', channel: 'alpha' },
|
|
238
|
+
pythonSource: `class LoadImageMask:\n RETURN_TYPES = ("IMAGE", "MASK")\n FUNCTION = "load_image"`,
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
type: 'CLIPTextEncode',
|
|
242
|
+
title: 'CLIP Text Prompt Encode',
|
|
243
|
+
family: 'comfy',
|
|
244
|
+
pack: 'studio-core (ComfyUI)',
|
|
245
|
+
category: 'conditioning',
|
|
246
|
+
inputPorts: ['clip', 'text_from_agent'],
|
|
247
|
+
outputPorts: ['CONDITIONING'],
|
|
248
|
+
defaultInputs: { text: 'Anamorphic 24mm crane rise over rain-slicked Neo-Kyoto rooftop, volumetric neon backlight' },
|
|
249
|
+
pythonSource: `class CLIPTextEncode:\n RETURN_TYPES = ("CONDITIONING",)\n FUNCTION = "encode"`,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
type: 'WanImageToVideo',
|
|
253
|
+
title: 'Wan 2.2 TI2V Latent Video Grid',
|
|
254
|
+
family: 'comfy',
|
|
255
|
+
pack: 'ComfyUI-WanVideoWrapper (Apache-2.0)',
|
|
256
|
+
category: 'conditioning',
|
|
257
|
+
inputPorts: ['positive'],
|
|
258
|
+
outputPorts: ['CONDITIONING', 'LATENT'],
|
|
259
|
+
defaultInputs: { width: 1280, height: 544, length: 81, fps: 24 },
|
|
260
|
+
pythonSource: `class WanImageToVideo:\n RETURN_TYPES = ("CONDITIONING", "LATENT")\n FUNCTION = "encode"`,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
type: 'LTXVConditioning',
|
|
264
|
+
title: 'LTX-Video 2.0 Frame Conditioning',
|
|
265
|
+
family: 'comfy',
|
|
266
|
+
pack: 'ComfyUI-LTXVideo (Apache-2.0)',
|
|
267
|
+
category: 'conditioning',
|
|
268
|
+
inputPorts: ['positive'],
|
|
269
|
+
outputPorts: ['CONDITIONING', 'LATENT'],
|
|
270
|
+
defaultInputs: { frame_rate: 25, width: 1280, height: 720, frames: 97 },
|
|
271
|
+
pythonSource: `class LTXVConditioning:\n RETURN_TYPES = ("CONDITIONING", "CONDITIONING")\n FUNCTION = "append"`,
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: 'TextEncodeQwenImageEdit',
|
|
275
|
+
title: 'Qwen-Image-Edit 2511 Instruction',
|
|
276
|
+
family: 'comfy',
|
|
277
|
+
pack: 'studio-core (ComfyUI)',
|
|
278
|
+
category: 'conditioning',
|
|
279
|
+
inputPorts: ['clip', 'image'],
|
|
280
|
+
outputPorts: ['CONDITIONING'],
|
|
281
|
+
defaultInputs: { instruction: 'Swap jacket to brushed obsidian leather, preserve face and rim lighting' },
|
|
282
|
+
pythonSource: `class TextEncodeQwenImageEdit:\n RETURN_TYPES = ("CONDITIONING",)\n FUNCTION = "encode"`,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
type: 'TextEncodeAceStepAudio',
|
|
286
|
+
title: 'ACE-Step 3.5B Tags & Lyrics',
|
|
287
|
+
family: 'comfy',
|
|
288
|
+
pack: 'ComfyUI_ACE-Step (Apache-2.0)',
|
|
289
|
+
category: 'conditioning',
|
|
290
|
+
inputPorts: ['clip'],
|
|
291
|
+
outputPorts: ['CONDITIONING'],
|
|
292
|
+
defaultInputs: { tags: 'analog synthwave, driving bassline, 122 bpm', lyrics: '[Verse] Neon reflections\n[Chorus] Signals rising', lyric_strength: 1.0 },
|
|
293
|
+
pythonSource: `class TextEncodeAceStepAudio:\n RETURN_TYPES = ("CONDITIONING",)\n FUNCTION = "encode"`,
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
type: 'ControlNetApplyAdvanced',
|
|
297
|
+
title: 'Apply ControlNet (Depth/Canny/Pose)',
|
|
298
|
+
family: 'comfy',
|
|
299
|
+
pack: 'comfyui_controlnet_aux (Apache-2.0)',
|
|
300
|
+
category: 'conditioning',
|
|
301
|
+
inputPorts: ['positive', 'image'],
|
|
302
|
+
outputPorts: ['CONDITIONING'],
|
|
303
|
+
defaultInputs: { strength: 0.85, start_percent: 0.0, end_percent: 1.0 },
|
|
304
|
+
pythonSource: `class ControlNetApplyAdvanced:\n RETURN_TYPES = ("CONDITIONING", "CONDITIONING")\n FUNCTION = "apply_controlnet"`,
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
type: 'IPAdapterAdvanced',
|
|
308
|
+
title: 'IPAdapter Character/Style Lock',
|
|
309
|
+
family: 'comfy',
|
|
310
|
+
pack: 'ComfyUI_IPAdapter_plus',
|
|
311
|
+
category: 'conditioning',
|
|
312
|
+
inputPorts: ['model', 'image'],
|
|
313
|
+
outputPorts: ['MODEL'],
|
|
314
|
+
defaultInputs: { weight: 0.8, weight_type: 'linear' },
|
|
315
|
+
pythonSource: `class IPAdapterAdvanced:\n RETURN_TYPES = ("MODEL",)\n FUNCTION = "apply_ipadapter"`,
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
type: 'KSampler',
|
|
319
|
+
title: 'KSampler (Diffusion / Rectified Flow)',
|
|
320
|
+
family: 'comfy',
|
|
321
|
+
pack: 'studio-core (ComfyUI)',
|
|
322
|
+
category: 'sampler',
|
|
323
|
+
inputPorts: ['model', 'positive', 'latent_image'],
|
|
324
|
+
outputPorts: ['LATENT'],
|
|
325
|
+
defaultInputs: { seed: 408921, steps: 28, cfg: 5.0, sampler_name: 'uni_pc', scheduler: 'simple', denoise: 1.0 },
|
|
326
|
+
pythonSource: `class KSampler:\n RETURN_TYPES = ("LATENT",)\n FUNCTION = "sample"`,
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
type: 'ModelSamplingAuraFlow',
|
|
330
|
+
title: 'AuraFlow Shift & Sampler',
|
|
331
|
+
family: 'comfy',
|
|
332
|
+
pack: 'studio-core (ComfyUI)',
|
|
333
|
+
category: 'sampler',
|
|
334
|
+
inputPorts: ['model', 'positive'],
|
|
335
|
+
outputPorts: ['LATENT'],
|
|
336
|
+
defaultInputs: { shift: 3.0, seed: 771204, steps: 8, cfg: 1.0 },
|
|
337
|
+
pythonSource: `class ModelSamplingAuraFlow:\n RETURN_TYPES = ("MODEL",)\n FUNCTION = "patch_aura"`,
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
type: 'DemucsStemSeparation',
|
|
341
|
+
title: 'Demucs 4-Stem Audio Splitter',
|
|
342
|
+
family: 'comfy',
|
|
343
|
+
pack: 'audio-separation-nodes (MIT)',
|
|
344
|
+
category: 'sampler',
|
|
345
|
+
inputPorts: ['audio'],
|
|
346
|
+
outputPorts: ['VOCALS', 'DRUMS', 'BASS', 'OTHER'],
|
|
347
|
+
defaultInputs: { model: 'htdemucs_ft', shifts: 2, overlap: 0.25 },
|
|
348
|
+
pythonSource: `class DemucsStemSeparation:\n RETURN_TYPES = ("AUDIO", "AUDIO", "AUDIO", "AUDIO")\n FUNCTION = "separate"`,
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
type: 'MMAudioVideoToAudio',
|
|
352
|
+
title: 'MMAudio Video-to-Foley SFX',
|
|
353
|
+
family: 'comfy',
|
|
354
|
+
pack: 'ComfyUI-MMAudio (Apache-2.0)',
|
|
355
|
+
category: 'sampler',
|
|
356
|
+
inputPorts: ['images'],
|
|
357
|
+
outputPorts: ['AUDIO'],
|
|
358
|
+
defaultInputs: { prompt: 'Rain hitting wet pavement, distant turbine hum, footsteps', duration: 8.0, cfg: 4.5 },
|
|
359
|
+
pythonSource: `class MMAudioVideoToAudio:\n RETURN_TYPES = ("AUDIO",)\n FUNCTION = "generate_foley"`,
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
type: 'KokoroTTS',
|
|
363
|
+
title: 'Kokoro-82M Fast Neural TTS',
|
|
364
|
+
family: 'comfy',
|
|
365
|
+
pack: 'comfyui-kokoro (MIT)',
|
|
366
|
+
category: 'sampler',
|
|
367
|
+
inputPorts: ['text'],
|
|
368
|
+
outputPorts: ['AUDIO'],
|
|
369
|
+
defaultInputs: { text: 'Every node in the cluster is locked in phase.', voice: 'af_bella', speed: 1.0 },
|
|
370
|
+
pythonSource: `class KokoroTTS:\n RETURN_TYPES = ("AUDIO",)\n FUNCTION = "synthesize"`,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
type: 'VAEDecode',
|
|
374
|
+
title: 'VAE Decode Latent → Image/Frames',
|
|
375
|
+
family: 'comfy',
|
|
376
|
+
pack: 'studio-core (ComfyUI)',
|
|
377
|
+
category: 'decode',
|
|
378
|
+
inputPorts: ['samples', 'vae'],
|
|
379
|
+
outputPorts: ['IMAGE'],
|
|
380
|
+
defaultInputs: {},
|
|
381
|
+
pythonSource: `class VAEDecode:\n RETURN_TYPES = ("IMAGE",)\n FUNCTION = "decode"`,
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
type: 'VoxelToMesh',
|
|
385
|
+
title: 'VAEDecodeHunyuan3D → .GLB Mesh',
|
|
386
|
+
family: 'comfy',
|
|
387
|
+
pack: 'studio-core 3D (ComfyUI)',
|
|
388
|
+
category: 'decode',
|
|
389
|
+
inputPorts: ['samples'],
|
|
390
|
+
outputPorts: ['MESH'],
|
|
391
|
+
defaultInputs: { algorithm: 'surface_net', threshold: 0.0, octree_resolution: 384 },
|
|
392
|
+
pythonSource: `class VoxelToMesh:\n RETURN_TYPES = ("MESH",)\n FUNCTION = "convert"`,
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
type: 'UltimateSDUpscale',
|
|
396
|
+
title: 'Ultimate 4× Tile Upscaler',
|
|
397
|
+
family: 'comfy',
|
|
398
|
+
pack: 'ComfyUI_UltimateSDUpscale',
|
|
399
|
+
category: 'decode',
|
|
400
|
+
inputPorts: ['image', 'model'],
|
|
401
|
+
outputPorts: ['IMAGE'],
|
|
402
|
+
defaultInputs: { upscale_by: 2.0, steps: 16, denoise: 0.25 },
|
|
403
|
+
pythonSource: `class UltimateSDUpscale:\n RETURN_TYPES = ("IMAGE",)\n FUNCTION = "upscale"`,
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
type: 'SaveWEBM',
|
|
407
|
+
title: 'SaveVideo (WEBM / MP4)',
|
|
408
|
+
family: 'comfy',
|
|
409
|
+
pack: 'studio-core (ComfyUI)',
|
|
410
|
+
category: 'output',
|
|
411
|
+
inputPorts: ['images'],
|
|
412
|
+
outputPorts: [],
|
|
413
|
+
defaultInputs: { filename_prefix: 'video/wan22_cinema', codec: 'vp9', fps: 24, crf: 18 },
|
|
414
|
+
pythonSource: `class SaveWEBM:\n RETURN_TYPES = ()\n OUTPUT_NODE = True\n FUNCTION = "save_video"`,
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
type: 'ConcatVideo',
|
|
418
|
+
title: 'ConcatVideo Stream-Copy Stitcher',
|
|
419
|
+
family: 'comfy',
|
|
420
|
+
pack: 'studio_extras (Native)',
|
|
421
|
+
category: 'output',
|
|
422
|
+
inputPorts: ['videos'],
|
|
423
|
+
outputPorts: ['VIDEO'],
|
|
424
|
+
defaultInputs: { paths: 'shot_01.mp4\nshot_02.mp4\nshot_03.mp4', filename_prefix: 'film/master_cut' },
|
|
425
|
+
pythonSource: `class ConcatVideo:\n RETURN_TYPES = ("VIDEO",)\n OUTPUT_NODE = True\n FUNCTION = "concat_videos"`,
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
type: 'SaveImage',
|
|
429
|
+
title: 'Save Image to Studio Library',
|
|
430
|
+
family: 'comfy',
|
|
431
|
+
pack: 'studio-core (ComfyUI)',
|
|
432
|
+
category: 'output',
|
|
433
|
+
inputPorts: ['images'],
|
|
434
|
+
outputPorts: [],
|
|
435
|
+
defaultInputs: { filename_prefix: 'image/studio_render' },
|
|
436
|
+
pythonSource: `class SaveImage:\n RETURN_TYPES = ()\n OUTPUT_NODE = True\n FUNCTION = "save_images"`,
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
type: 'SaveGLB',
|
|
440
|
+
title: 'Export Watertight .GLB 3D Asset',
|
|
441
|
+
family: 'comfy',
|
|
442
|
+
pack: 'studio-core 3D (ComfyUI)',
|
|
443
|
+
category: 'output',
|
|
444
|
+
inputPorts: ['mesh'],
|
|
445
|
+
outputPorts: [],
|
|
446
|
+
defaultInputs: { filename_prefix: 'mesh/hunyuan3d_asset' },
|
|
447
|
+
pythonSource: `class SaveGLB:\n RETURN_TYPES = ()\n OUTPUT_NODE = True\n FUNCTION = "save_glb"`,
|
|
448
|
+
},
|
|
449
|
+
];
|
|
450
|
+
export const FLOW_BLUEPRINTS = [
|
|
451
|
+
{
|
|
452
|
+
id: 'hybrid-agent-wan22',
|
|
453
|
+
name: 'Langflow Director Agent → Wan 2.2 Cinema + MMAudio Foley',
|
|
454
|
+
kind: 'Hybrid Langflow + ComfyUI',
|
|
455
|
+
engine: 'zen5 + wan2.2_ti2v_5B + mmaudio',
|
|
456
|
+
description: 'ChatInput & ZenAgent expand a rough creative brief with Vector RAG lore, then drive ComfyUI Wan 2.2 video + MMAudio Foley.',
|
|
457
|
+
nodes: [
|
|
458
|
+
{ id: '1', type: 'ChatInput', title: 'Creative Brief Input', family: 'langflow', category: 'agent', x: 25, y: 30, inputs: { input_value: '24mm anamorphic crane rise over rain-slicked Neo-Kyoto rooftop at dusk' }, wiresFrom: [] },
|
|
459
|
+
{ id: '2', type: 'VectorStoreRAG', title: 'Brand & Lore RAG Memory', family: 'langflow', category: 'agent', x: 25, y: 185, inputs: { collection: 'cyber_lookbook_v3', top_k: 4 }, wiresFrom: ['1'] },
|
|
460
|
+
{ id: '3', type: 'ZenAgentNode', title: 'Zen5 Director Agent', family: 'langflow', category: 'agent', x: 270, y: 95, inputs: { model: 'zen5', system_prompt: 'Write precision camera rig + volumetric lighting prompt for Wan 2.2', temperature: 0.25 }, wiresFrom: ['1', '2'] },
|
|
461
|
+
{ id: '4', type: 'UNETLoader', title: 'Load Wan 2.2 UNet', family: 'comfy', category: 'loader', x: 520, y: 25, inputs: { unet_name: 'wan2.2_ti2v_5B_fp16.safetensors', weight_dtype: 'fp16' }, wiresFrom: [] },
|
|
462
|
+
{ id: '5', type: 'CLIPTextEncode', title: 'Encode Agent Prompt', family: 'comfy', category: 'conditioning', x: 520, y: 180, inputs: { text: 'Anamorphic 24mm crane rise over rain-slicked Neo-Kyoto rooftop, neon rim light' }, wiresFrom: ['3'] },
|
|
463
|
+
{ id: '6', type: 'KSampler', title: 'Wan 2.2 Flow Sampler', family: 'comfy', category: 'sampler', x: 770, y: 60, inputs: { seed: 408921, steps: 28, cfg: 5.0, sampler_name: 'uni_pc', denoise: 1.0 }, wiresFrom: ['4', '5'] },
|
|
464
|
+
{ id: '7', type: 'MMAudioVideoToAudio', title: 'MMAudio Foley Sync', family: 'comfy', category: 'sampler', x: 770, y: 215, inputs: { prompt: 'Rain hitting wet asphalt, distant neon transformer hum', duration: 5.0, cfg: 4.5 }, wiresFrom: ['6'] },
|
|
465
|
+
{ id: '8', type: 'SaveWEBM', title: 'Save Master Cut (/v1/library)', family: 'comfy', category: 'output', x: 1020, y: 130, inputs: { filename_prefix: 'video/hybrid_agent_wan22', codec: 'vp9', fps: 24 }, wiresFrom: ['6', '7'] },
|
|
466
|
+
],
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
id: 'cad-to-lookbook',
|
|
470
|
+
name: 'CAD Flat Sketch → Ghost Mannequin & Lookbook (Qwen 2511)',
|
|
471
|
+
kind: 'ComfyUI Image & CAD',
|
|
472
|
+
engine: 'qwen-image-edit-2511.safetensors',
|
|
473
|
+
description: 'Antje’s production garment conversion graph: CAD drawing → photoreal ghost mannequin (0.92 denoise) → lifestyle lookbook (0.25 denoise).',
|
|
474
|
+
nodes: [
|
|
475
|
+
{ id: '1', type: 'LoadImageMask', title: 'CAD Line Drawing Upload', family: 'comfy', category: 'loader', x: 30, y: 40, inputs: { image: 'cad_jacket_flat.png', channel: 'alpha' }, wiresFrom: [] },
|
|
476
|
+
{ id: '2', type: 'UNETLoader', title: 'Load Qwen-Image-Edit 2511', family: 'comfy', category: 'loader', x: 30, y: 195, inputs: { unet_name: 'qwen-image-edit-2511.safetensors', clip_name: 'qwen2.5-vl-7b.safetensors' }, wiresFrom: [] },
|
|
477
|
+
{ id: '3', type: 'TextEncodeQwenImageEdit', title: 'CAD → Ghost Mannequin Prompt', family: 'comfy', category: 'conditioning', x: 290, y: 110, inputs: { instruction: 'Convert flat CAD technical sketch into photorealistic 3D studio ghost mannequin garment, preserve seam geometry and fabric drape' }, wiresFrom: ['1', '2'] },
|
|
478
|
+
{ id: '4', type: 'KSampler', title: 'Conversion Sampler (0.92 Denoise)', family: 'comfy', category: 'sampler', x: 560, y: 110, inputs: { seed: 882104, steps: 24, cfg: 4.0, sampler_name: 'euler', denoise: 0.92 }, wiresFrom: ['2', '3'] },
|
|
479
|
+
{ id: '5', type: 'SaveImage', title: 'Save to Stack & QC Gallery', family: 'comfy', category: 'output', x: 830, y: 110, inputs: { filename_prefix: 'cad_ghost/garment_render' }, wiresFrom: ['4'] },
|
|
480
|
+
],
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
id: 'hunyuan3d-mesh',
|
|
484
|
+
name: 'Hunyuan3D-2.1 Image-to-GLB Watertight Mesh',
|
|
485
|
+
kind: 'ComfyUI 3D Mesh',
|
|
486
|
+
engine: 'hunyuan_3d_v2.1.safetensors',
|
|
487
|
+
description: 'Single ghost-mannequin or product reference image → AuraFlow 3D latent → marching cubes .glb asset.',
|
|
488
|
+
nodes: [
|
|
489
|
+
{ id: '1', type: 'ImageOnlyCheckpointLoader', title: 'Load Hunyuan3D 2.1', family: 'comfy', category: 'loader', x: 30, y: 45, inputs: { ckpt_name: 'hunyuan_3d_v2.1.safetensors' }, wiresFrom: [] },
|
|
490
|
+
{ id: '2', type: 'ModelSamplingAuraFlow', title: 'AuraFlow 3D Sampler', family: 'comfy', category: 'sampler', x: 310, y: 45, inputs: { shift: 1.0, seed: 771204, steps: 30, cfg: 5.5 }, wiresFrom: ['1'] },
|
|
491
|
+
{ id: '3', type: 'VoxelToMesh', title: 'VAEDecodeHunyuan3D → Mesh', family: 'comfy', category: 'decode', x: 590, y: 45, inputs: { algorithm: 'surface_net', threshold: 0.0, octree_resolution: 384 }, wiresFrom: ['2'] },
|
|
492
|
+
{ id: '4', type: 'SaveGLB', title: 'Export .GLB 3D Asset', family: 'comfy', category: 'output', x: 860, y: 45, inputs: { filename_prefix: 'mesh/hunyuan3d_asset' }, wiresFrom: ['3'] },
|
|
493
|
+
],
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
id: 'acestep-demucs-music',
|
|
497
|
+
name: 'ACE-Step 3.5B Song Synthesis → Demucs 4-Stem Splitter',
|
|
498
|
+
kind: 'ComfyUI Audio & Music',
|
|
499
|
+
engine: 'ace_step_v1_3.5b + htdemucs_ft',
|
|
500
|
+
description: 'Generate full-length music from lyrics & tags, then automatically split into isolated Vocals, Drums, Bass, and Synth stems.',
|
|
501
|
+
nodes: [
|
|
502
|
+
{ id: '1', type: 'CheckpointLoaderSimple', title: 'Load ACE-Step 3.5B', family: 'comfy', category: 'loader', x: 30, y: 45, inputs: { ckpt_name: 'ace_step_v1_3.5b.safetensors' }, wiresFrom: [] },
|
|
503
|
+
{ id: '2', type: 'TextEncodeAceStepAudio', title: 'Tags, BPM & Lyrics', family: 'comfy', category: 'conditioning', x: 290, y: 45, inputs: { tags: 'analog synthwave, 122 bpm, F minor', lyrics: '[Verse] Signals in the rain\n[Chorus] Hold the phase lock', lyric_strength: 1.0 }, wiresFrom: ['1'] },
|
|
504
|
+
{ id: '3', type: 'KSampler', title: 'Audio Diffusion Sampler', family: 'comfy', category: 'sampler', x: 550, y: 45, inputs: { seed: 910344, steps: 45, cfg: 4.0, sampler_name: 'euler' }, wiresFrom: ['1', '2'] },
|
|
505
|
+
{ id: '4', type: 'DemucsStemSeparation', title: 'Demucs 4-Stem Splitter', family: 'comfy', category: 'sampler', x: 810, y: 45, inputs: { model: 'htdemucs_ft', shifts: 2, overlap: 0.25 }, wiresFrom: ['3'] },
|
|
506
|
+
],
|
|
507
|
+
},
|
|
508
|
+
];
|
|
509
|
+
const MAX_HISTORY = 30;
|
|
510
|
+
const MIN_ZOOM = 0.6;
|
|
511
|
+
const MAX_ZOOM = 1.4;
|
|
512
|
+
const NODE_W = 224;
|
|
513
|
+
const NODE_H = 136;
|
|
514
|
+
function cloneNodes(nodes) {
|
|
515
|
+
return nodes.map((n) => ({ ...n, inputs: { ...n.inputs }, wiresFrom: [...n.wiresFrom] }));
|
|
516
|
+
}
|
|
517
|
+
function formatClock(d = new Date()) {
|
|
518
|
+
const hh = String(d.getHours()).padStart(2, '0');
|
|
519
|
+
const mm = String(d.getMinutes()).padStart(2, '0');
|
|
520
|
+
const ss = String(d.getSeconds()).padStart(2, '0');
|
|
521
|
+
const ms = String(d.getMilliseconds()).padStart(3, '0');
|
|
522
|
+
return `${hh}:${mm}:${ss}.${ms}`;
|
|
523
|
+
}
|
|
524
|
+
export function FlowStudio({ host }) {
|
|
525
|
+
const wire = useWire(host);
|
|
526
|
+
const [section, setSection] = useState(() => parseFlowSection(host.path));
|
|
527
|
+
useEffect(() => {
|
|
528
|
+
setSection(parseFlowSection(host.path));
|
|
529
|
+
}, [host.path]);
|
|
530
|
+
const switchSection = (next) => {
|
|
531
|
+
setSection(next);
|
|
532
|
+
host.go?.(next === 'canvas' ? '' : next);
|
|
533
|
+
};
|
|
534
|
+
const [blueprints, setBlueprints] = useState(() => FLOW_BLUEPRINTS.map((b) => ({
|
|
535
|
+
...b,
|
|
536
|
+
nodes: cloneNodes(b.nodes),
|
|
537
|
+
})));
|
|
538
|
+
const [activeBlueprintId, setActiveBlueprintId] = useState(FLOW_BLUEPRINTS[0].id);
|
|
539
|
+
const activeBlueprint = blueprints.find((b) => b.id === activeBlueprintId) ?? blueprints[0];
|
|
540
|
+
const [selectedNodeId, setSelectedNodeId] = useState(activeBlueprint.nodes[0]?.id ?? '1');
|
|
541
|
+
const selectedNode = activeBlueprint.nodes.find((n) => n.id === selectedNodeId) ?? activeBlueprint.nodes[0];
|
|
542
|
+
// Per-blueprint undo/redo stacks (up to 30 snapshots)
|
|
543
|
+
const [historyByBp, setHistoryByBp] = useState({});
|
|
544
|
+
const lastEditKeyRef = useRef(null);
|
|
545
|
+
const activeHistory = historyByBp[activeBlueprint.id] ?? { past: [], future: [] };
|
|
546
|
+
const canUndo = activeHistory.past.length > 0;
|
|
547
|
+
const canRedo = activeHistory.future.length > 0;
|
|
548
|
+
// Canvas pan & zoom state
|
|
549
|
+
const [zoom, setZoom] = useState(1);
|
|
550
|
+
const [pan, setPan] = useState({ x: 0, y: 0 });
|
|
551
|
+
const [isPanning, setIsPanning] = useState(false);
|
|
552
|
+
const [draggingNodeId, setDraggingNodeId] = useState(null);
|
|
553
|
+
const [catalogExpanded, setCatalogExpanded] = useState(false);
|
|
554
|
+
const canvasViewportRef = useRef(null);
|
|
555
|
+
const panDragRef = useRef(null);
|
|
556
|
+
const nodeDragRef = useRef(null);
|
|
557
|
+
const [moduleCatalog, setModuleCatalog] = useState(() => [...FLOW_MODULE_CATALOG]);
|
|
558
|
+
const [familyFilter, setFamilyFilter] = useState('all');
|
|
559
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
560
|
+
const [connectingFromId, setConnectingFromId] = useState(null);
|
|
561
|
+
const [runningFlow, setRunningFlow] = useState(false);
|
|
562
|
+
const [nodeRunStatus, setNodeRunStatus] = useState({});
|
|
563
|
+
const [copilotInput, setCopilotInput] = useState('');
|
|
564
|
+
const [statusMessage, setStatusMessage] = useState('Hanzo Flow · Langflow agent nodes + ComfyUI native engine (/v1/object_info & /v1/prompt)');
|
|
565
|
+
const [playgroundOutput, setPlaygroundOutput] = useState([
|
|
566
|
+
`[${formatClock()}] Ready · ${FLOW_BLUEPRINTS[0].nodes.length} nodes loaded (${FLOW_BLUEPRINTS[0].engine})`,
|
|
567
|
+
]);
|
|
568
|
+
const pushSnapshot = useCallback((bpId, snapshot) => {
|
|
569
|
+
setHistoryByBp((prev) => {
|
|
570
|
+
const cur = prev[bpId] ?? { past: [], future: [] };
|
|
571
|
+
const nextPast = [...cur.past, cloneNodes(snapshot)].slice(-MAX_HISTORY);
|
|
572
|
+
return { ...prev, [bpId]: { past: nextPast, future: [] } };
|
|
573
|
+
});
|
|
574
|
+
}, []);
|
|
575
|
+
const commitGraph = useCallback((updater, opts) => {
|
|
576
|
+
const bpId = activeBlueprint.id;
|
|
577
|
+
const now = Date.now();
|
|
578
|
+
const shouldCoalesce = Boolean(opts?.coalesceKey) &&
|
|
579
|
+
lastEditKeyRef.current?.key === opts?.coalesceKey &&
|
|
580
|
+
now - (lastEditKeyRef.current?.at ?? 0) < 800;
|
|
581
|
+
setBlueprints((prev) => prev.map((b) => {
|
|
582
|
+
if (b.id !== bpId)
|
|
583
|
+
return b;
|
|
584
|
+
if (!shouldCoalesce) {
|
|
585
|
+
pushSnapshot(bpId, b.nodes);
|
|
586
|
+
}
|
|
587
|
+
lastEditKeyRef.current = opts?.coalesceKey ? { key: opts.coalesceKey, at: now } : null;
|
|
588
|
+
return { ...b, nodes: updater(b.nodes) };
|
|
589
|
+
}));
|
|
590
|
+
}, [activeBlueprint.id, pushSnapshot]);
|
|
591
|
+
const undo = useCallback(() => {
|
|
592
|
+
const bpId = activeBlueprint.id;
|
|
593
|
+
const cur = historyByBp[bpId];
|
|
594
|
+
if (!cur || cur.past.length === 0)
|
|
595
|
+
return;
|
|
596
|
+
const previous = cur.past[cur.past.length - 1];
|
|
597
|
+
const currentSnapshot = cloneNodes(activeBlueprint.nodes);
|
|
598
|
+
setHistoryByBp((prev) => {
|
|
599
|
+
const h = prev[bpId] ?? { past: [], future: [] };
|
|
600
|
+
return {
|
|
601
|
+
...prev,
|
|
602
|
+
[bpId]: {
|
|
603
|
+
past: h.past.slice(0, -1),
|
|
604
|
+
future: [currentSnapshot, ...h.future].slice(0, MAX_HISTORY),
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
});
|
|
608
|
+
setBlueprints((prev) => prev.map((b) => (b.id === bpId ? { ...b, nodes: cloneNodes(previous) } : b)));
|
|
609
|
+
if (!previous.some((n) => n.id === selectedNodeId) && previous[0]) {
|
|
610
|
+
setSelectedNodeId(previous[0].id);
|
|
611
|
+
}
|
|
612
|
+
setStatusMessage('Undid last Flow graph change');
|
|
613
|
+
}, [activeBlueprint.id, activeBlueprint.nodes, historyByBp, selectedNodeId]);
|
|
614
|
+
const redo = useCallback(() => {
|
|
615
|
+
const bpId = activeBlueprint.id;
|
|
616
|
+
const cur = historyByBp[bpId];
|
|
617
|
+
if (!cur || cur.future.length === 0)
|
|
618
|
+
return;
|
|
619
|
+
const nextNodes = cur.future[0];
|
|
620
|
+
const currentSnapshot = cloneNodes(activeBlueprint.nodes);
|
|
621
|
+
setHistoryByBp((prev) => {
|
|
622
|
+
const h = prev[bpId] ?? { past: [], future: [] };
|
|
623
|
+
return {
|
|
624
|
+
...prev,
|
|
625
|
+
[bpId]: {
|
|
626
|
+
past: [...h.past, currentSnapshot].slice(-MAX_HISTORY),
|
|
627
|
+
future: h.future.slice(1),
|
|
628
|
+
},
|
|
629
|
+
};
|
|
630
|
+
});
|
|
631
|
+
setBlueprints((prev) => prev.map((b) => (b.id === bpId ? { ...b, nodes: cloneNodes(nextNodes) } : b)));
|
|
632
|
+
if (!nextNodes.some((n) => n.id === selectedNodeId) && nextNodes[0]) {
|
|
633
|
+
setSelectedNodeId(nextNodes[0].id);
|
|
634
|
+
}
|
|
635
|
+
setStatusMessage('Redid Flow graph change');
|
|
636
|
+
}, [activeBlueprint.id, activeBlueprint.nodes, historyByBp, selectedNodeId]);
|
|
637
|
+
const clampZoom = (z) => Math.round(Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, z)) * 100) / 100;
|
|
638
|
+
const fitCanvas = useCallback(() => {
|
|
639
|
+
const el = canvasViewportRef.current;
|
|
640
|
+
const nodes = activeBlueprint.nodes;
|
|
641
|
+
if (!el || !nodes.length) {
|
|
642
|
+
setZoom(1);
|
|
643
|
+
setPan({ x: 0, y: 0 });
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const pad = 32;
|
|
647
|
+
const minX = Math.min(...nodes.map((n) => n.x));
|
|
648
|
+
const minY = Math.min(...nodes.map((n) => n.y));
|
|
649
|
+
const maxX = Math.max(...nodes.map((n) => n.x + NODE_W));
|
|
650
|
+
const maxY = Math.max(...nodes.map((n) => n.y + NODE_H));
|
|
651
|
+
const graphW = Math.max(1, maxX - minX);
|
|
652
|
+
const graphH = Math.max(1, maxY - minY);
|
|
653
|
+
const viewW = Math.max(240, el.clientWidth - pad * 2);
|
|
654
|
+
const viewH = Math.max(200, el.clientHeight - pad * 2);
|
|
655
|
+
const fittedZoom = clampZoom(Math.min(viewW / graphW, viewH / graphH, 1));
|
|
656
|
+
const panX = Math.round((el.clientWidth - graphW * fittedZoom) / 2 - minX * fittedZoom);
|
|
657
|
+
const panY = Math.round((el.clientHeight - graphH * fittedZoom) / 2 - minY * fittedZoom);
|
|
658
|
+
setZoom(fittedZoom);
|
|
659
|
+
setPan({ x: panX, y: Math.max(16, panY) });
|
|
660
|
+
}, [activeBlueprint.nodes]);
|
|
661
|
+
const handleCanvasPointerDown = (e) => {
|
|
662
|
+
const target = e.target;
|
|
663
|
+
if (target?.closest('[data-flow-node]') ||
|
|
664
|
+
target?.closest('[data-flow-toolbar]') ||
|
|
665
|
+
target?.closest('[role="toolbar"]') ||
|
|
666
|
+
target?.closest('button')) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
670
|
+
setIsPanning(true);
|
|
671
|
+
panDragRef.current = { startX: e.clientX, startY: e.clientY, originX: pan.x, originY: pan.y };
|
|
672
|
+
};
|
|
673
|
+
const handleCanvasPointerMove = (e) => {
|
|
674
|
+
if (nodeDragRef.current) {
|
|
675
|
+
const drag = nodeDragRef.current;
|
|
676
|
+
const dx = (e.clientX - drag.startX) / zoom;
|
|
677
|
+
const dy = (e.clientY - drag.startY) / zoom;
|
|
678
|
+
if (!drag.moved && Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) > 4) {
|
|
679
|
+
drag.moved = true;
|
|
680
|
+
setDraggingNodeId(drag.id);
|
|
681
|
+
}
|
|
682
|
+
if (drag.moved) {
|
|
683
|
+
const nx = Math.max(8, Math.round(drag.originX + dx));
|
|
684
|
+
const ny = Math.max(8, Math.round(drag.originY + dy));
|
|
685
|
+
setBlueprints((prev) => prev.map((b) => b.id === activeBlueprint.id ? { ...b, nodes: b.nodes.map((n) => (n.id === drag.id ? { ...n, x: nx, y: ny } : n)) } : b));
|
|
686
|
+
}
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (!isPanning || !panDragRef.current)
|
|
690
|
+
return;
|
|
691
|
+
const dx = e.clientX - panDragRef.current.startX;
|
|
692
|
+
const dy = e.clientY - panDragRef.current.startY;
|
|
693
|
+
setPan({ x: Math.round(panDragRef.current.originX + dx), y: Math.round(panDragRef.current.originY + dy) });
|
|
694
|
+
};
|
|
695
|
+
const handleCanvasPointerUp = (e) => {
|
|
696
|
+
if (nodeDragRef.current) {
|
|
697
|
+
const drag = nodeDragRef.current;
|
|
698
|
+
nodeDragRef.current = null;
|
|
699
|
+
setDraggingNodeId(null);
|
|
700
|
+
if (drag.moved) {
|
|
701
|
+
pushSnapshot(activeBlueprint.id, drag.snapshot);
|
|
702
|
+
setStatusMessage(`Moved node #${drag.id}`);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (isPanning) {
|
|
706
|
+
try {
|
|
707
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
708
|
+
}
|
|
709
|
+
catch {
|
|
710
|
+
// Ignore
|
|
711
|
+
}
|
|
712
|
+
setIsPanning(false);
|
|
713
|
+
panDragRef.current = null;
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
const handleNodePointerDown = (node, e) => {
|
|
717
|
+
const target = e.target;
|
|
718
|
+
if (target?.closest('button'))
|
|
719
|
+
return;
|
|
720
|
+
e.stopPropagation();
|
|
721
|
+
setSelectedNodeId(node.id);
|
|
722
|
+
nodeDragRef.current = {
|
|
723
|
+
id: node.id,
|
|
724
|
+
startX: e.clientX,
|
|
725
|
+
startY: e.clientY,
|
|
726
|
+
originX: node.x,
|
|
727
|
+
originY: node.y,
|
|
728
|
+
moved: false,
|
|
729
|
+
snapshot: cloneNodes(activeBlueprint.nodes),
|
|
730
|
+
};
|
|
731
|
+
try {
|
|
732
|
+
canvasViewportRef.current?.setPointerCapture(e.pointerId);
|
|
733
|
+
}
|
|
734
|
+
catch {
|
|
735
|
+
// Ignore
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
// Discover live ComfyUI modules from /v1/object_info when backend is available
|
|
739
|
+
useEffect(() => {
|
|
740
|
+
let alive = true;
|
|
741
|
+
objectInfo(wire)
|
|
742
|
+
.then((info) => {
|
|
743
|
+
if (!alive)
|
|
744
|
+
return;
|
|
745
|
+
const existing = new Set(FLOW_MODULE_CATALOG.map((m) => m.type));
|
|
746
|
+
const extra = [];
|
|
747
|
+
for (const [type, spec] of Object.entries(info).slice(0, 50)) {
|
|
748
|
+
if (existing.has(type) || !spec || typeof spec !== 'object')
|
|
749
|
+
continue;
|
|
750
|
+
extra.push({
|
|
751
|
+
type,
|
|
752
|
+
title: spec.display_name || type,
|
|
753
|
+
family: 'comfy',
|
|
754
|
+
pack: spec.category || 'studio-v1 /object_info',
|
|
755
|
+
category: 'sampler',
|
|
756
|
+
inputPorts: ['input'],
|
|
757
|
+
outputPorts: Array.isArray(spec.output) ? spec.output.map(String) : ['OUTPUT'],
|
|
758
|
+
defaultInputs: {},
|
|
759
|
+
pythonSource: `class ${type}(io.ComfyNode):\n # Loaded dynamically from studio-v1 /v1/object_info\n pass`,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
if (extra.length > 0)
|
|
763
|
+
setModuleCatalog([...FLOW_MODULE_CATALOG, ...extra]);
|
|
764
|
+
})
|
|
765
|
+
.catch(() => { });
|
|
766
|
+
return () => {
|
|
767
|
+
alive = false;
|
|
768
|
+
};
|
|
769
|
+
}, [wire]);
|
|
770
|
+
const selectedSpec = moduleCatalog.find((m) => m.type === selectedNode.type);
|
|
771
|
+
const [pythonDraft, setPythonDraft] = useState(() => selectedNode.pythonCode || selectedSpec?.pythonSource || '');
|
|
772
|
+
useEffect(() => {
|
|
773
|
+
const spec = moduleCatalog.find((m) => m.type === selectedNode.type);
|
|
774
|
+
setPythonDraft(selectedNode.pythonCode || spec?.pythonSource || '');
|
|
775
|
+
}, [selectedNode, moduleCatalog]);
|
|
776
|
+
const updateNodeInput = (key, val) => {
|
|
777
|
+
commitGraph((nodes) => nodes.map((n) => (n.id === selectedNode.id ? { ...n, inputs: { ...n.inputs, [key]: val } } : n)), { coalesceKey: `${selectedNode.id}:${key}` });
|
|
778
|
+
};
|
|
779
|
+
const saveNodePythonCode = () => {
|
|
780
|
+
commitGraph((nodes) => nodes.map((n) => (n.id === selectedNode.id ? { ...n, pythonCode: pythonDraft } : n)));
|
|
781
|
+
setStatusMessage(`Saved live Python component class for #${selectedNode.id} ${selectedNode.type}`);
|
|
782
|
+
};
|
|
783
|
+
const addModuleToCanvas = (spec) => {
|
|
784
|
+
const nextId = String(Math.max(0, ...activeBlueprint.nodes.map((n) => Number(n.id) || 0)) + 1);
|
|
785
|
+
const col = spec.category === 'agent'
|
|
786
|
+
? 0
|
|
787
|
+
: spec.category === 'loader'
|
|
788
|
+
? 1
|
|
789
|
+
: spec.category === 'conditioning'
|
|
790
|
+
? 2
|
|
791
|
+
: spec.category === 'sampler' || spec.category === 'decode'
|
|
792
|
+
? 3
|
|
793
|
+
: 4;
|
|
794
|
+
const colX = 25 + col * 245;
|
|
795
|
+
const inCol = activeBlueprint.nodes.filter((n) => Math.abs(n.x - colX) < 100).length;
|
|
796
|
+
const created = {
|
|
797
|
+
id: nextId,
|
|
798
|
+
type: spec.type,
|
|
799
|
+
title: spec.title,
|
|
800
|
+
family: spec.family,
|
|
801
|
+
category: spec.category,
|
|
802
|
+
x: colX,
|
|
803
|
+
y: 30 + inCol * 155,
|
|
804
|
+
inputs: { ...spec.defaultInputs },
|
|
805
|
+
wiresFrom: selectedNode ? [selectedNode.id] : [],
|
|
806
|
+
pythonCode: spec.pythonSource,
|
|
807
|
+
};
|
|
808
|
+
commitGraph((nodes) => [...nodes, created]);
|
|
809
|
+
setSelectedNodeId(nextId);
|
|
810
|
+
setStatusMessage(`Added ${spec.family === 'langflow' ? 'Langflow' : 'ComfyUI'} node #${nextId} ${spec.type} to Flow canvas`);
|
|
811
|
+
};
|
|
812
|
+
const toggleWire = (fromId, toId) => {
|
|
813
|
+
if (fromId === toId)
|
|
814
|
+
return;
|
|
815
|
+
commitGraph((nodes) => nodes.map((n) => {
|
|
816
|
+
if (n.id !== toId)
|
|
817
|
+
return n;
|
|
818
|
+
const exists = n.wiresFrom.includes(fromId);
|
|
819
|
+
return {
|
|
820
|
+
...n,
|
|
821
|
+
wiresFrom: exists ? n.wiresFrom.filter((w) => w !== fromId) : [...n.wiresFrom, fromId],
|
|
822
|
+
};
|
|
823
|
+
}));
|
|
824
|
+
setConnectingFromId(null);
|
|
825
|
+
setStatusMessage(`Wired #${fromId} → #${toId}`);
|
|
826
|
+
};
|
|
827
|
+
const deleteNode = useCallback((nodeId) => {
|
|
828
|
+
if (activeBlueprint.nodes.length <= 1)
|
|
829
|
+
return;
|
|
830
|
+
const target = activeBlueprint.nodes.find((n) => n.id === nodeId);
|
|
831
|
+
commitGraph((nodes) => nodes.filter((n) => n.id !== nodeId).map((n) => ({ ...n, wiresFrom: n.wiresFrom.filter((w) => w !== nodeId) })));
|
|
832
|
+
const fallback = activeBlueprint.nodes.find((n) => n.id !== nodeId);
|
|
833
|
+
if (fallback)
|
|
834
|
+
setSelectedNodeId(fallback.id);
|
|
835
|
+
setStatusMessage(`Deleted node #${nodeId}${target ? ` (${target.type})` : ''}`);
|
|
836
|
+
}, [activeBlueprint.nodes, commitGraph]);
|
|
837
|
+
// Keyboard shortcuts: Cmd/Ctrl+Z undo, Cmd/Ctrl+Shift+Z or Ctrl+Y redo, Delete/Backspace delete node
|
|
838
|
+
useEffect(() => {
|
|
839
|
+
if (section !== 'canvas' && section !== 'comfy' && section !== 'agents')
|
|
840
|
+
return;
|
|
841
|
+
const onKeyDown = (e) => {
|
|
842
|
+
const target = e.target;
|
|
843
|
+
const tag = target?.tagName;
|
|
844
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || target?.isContentEditable)
|
|
845
|
+
return;
|
|
846
|
+
const mod = e.metaKey || e.ctrlKey;
|
|
847
|
+
if (mod && !e.shiftKey && e.key.toLowerCase() === 'z') {
|
|
848
|
+
e.preventDefault();
|
|
849
|
+
undo();
|
|
850
|
+
}
|
|
851
|
+
else if ((mod && e.shiftKey && e.key.toLowerCase() === 'z') || (e.ctrlKey && e.key.toLowerCase() === 'y')) {
|
|
852
|
+
e.preventDefault();
|
|
853
|
+
redo();
|
|
854
|
+
}
|
|
855
|
+
else if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
856
|
+
// Only with focus on the canvas: a Backspace elsewhere must not delete a node.
|
|
857
|
+
if (selectedNode && activeBlueprint.nodes.length > 1 && target && canvasViewportRef.current?.contains(target)) {
|
|
858
|
+
e.preventDefault();
|
|
859
|
+
deleteNode(selectedNode.id);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
window.addEventListener('keydown', onKeyDown);
|
|
864
|
+
return () => window.removeEventListener('keydown', onKeyDown);
|
|
865
|
+
}, [section, undo, redo, deleteNode, selectedNode, activeBlueprint.nodes.length]);
|
|
866
|
+
const autoLayout = () => {
|
|
867
|
+
const order = {
|
|
868
|
+
agent: 0,
|
|
869
|
+
loader: 1,
|
|
870
|
+
conditioning: 2,
|
|
871
|
+
sampler: 3,
|
|
872
|
+
decode: 3,
|
|
873
|
+
output: 4,
|
|
874
|
+
};
|
|
875
|
+
commitGraph((nodes) => {
|
|
876
|
+
const counts = {};
|
|
877
|
+
const sorted = [...nodes].sort((x, y) => order[x.category] - order[y.category] || Number(x.id) - Number(y.id));
|
|
878
|
+
return sorted.map((n) => {
|
|
879
|
+
const col = order[n.category];
|
|
880
|
+
const row = counts[col] ?? 0;
|
|
881
|
+
counts[col] = row + 1;
|
|
882
|
+
return { ...n, x: 25 + col * 245, y: 30 + row * 155 };
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
setPan({ x: 0, y: 0 });
|
|
886
|
+
setStatusMessage(`Auto-aligned ${activeBlueprint.nodes.length} Langflow + ComfyUI nodes`);
|
|
887
|
+
};
|
|
888
|
+
const compiledComfyPrompt = useMemo(() => {
|
|
889
|
+
const out = {};
|
|
890
|
+
for (const n of activeBlueprint.nodes) {
|
|
891
|
+
const spec = moduleCatalog.find((m) => m.type === n.type);
|
|
892
|
+
const wiredInputs = { ...n.inputs };
|
|
893
|
+
n.wiresFrom.forEach((sourceId, idx) => {
|
|
894
|
+
const portName = spec?.inputPorts[idx] || (idx === 0 ? 'model' : idx === 1 ? 'positive' : `input_${idx}`);
|
|
895
|
+
wiredInputs[portName] = [sourceId, 0];
|
|
896
|
+
});
|
|
897
|
+
out[n.id] = {
|
|
898
|
+
class_type: n.type,
|
|
899
|
+
inputs: wiredInputs,
|
|
900
|
+
_meta: { title: n.title, family: n.family },
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
return out;
|
|
904
|
+
}, [activeBlueprint, moduleCatalog]);
|
|
905
|
+
// /v1/prompt only queues the graph. Nodes show what the engine's work-log says: Queued, Running, and Done only when it closes the run.
|
|
906
|
+
// Only the run in flight may write state; a new run, another template or leaving the page ends the one before.
|
|
907
|
+
const followed = useRef(runs());
|
|
908
|
+
useEffect(() => {
|
|
909
|
+
const f = followed.current;
|
|
910
|
+
f.stop();
|
|
911
|
+
setRunningFlow(false);
|
|
912
|
+
setNodeRunStatus({});
|
|
913
|
+
return () => f.stop();
|
|
914
|
+
}, [activeBlueprint.id]);
|
|
915
|
+
const runFlowPlayground = async () => {
|
|
916
|
+
if (runningFlow)
|
|
917
|
+
return;
|
|
918
|
+
const mine = followed.current.start();
|
|
919
|
+
setRunningFlow(true);
|
|
920
|
+
const nodes = activeBlueprint.nodes;
|
|
921
|
+
const mark = (state) => setNodeRunStatus(state ? Object.fromEntries(nodes.map((n) => [n.id, state])) : {});
|
|
922
|
+
const logs = [];
|
|
923
|
+
const say = (line, status) => {
|
|
924
|
+
logs.push(`[${formatClock()}] ${line}`);
|
|
925
|
+
setPlaygroundOutput([...logs]);
|
|
926
|
+
setStatusMessage(status);
|
|
927
|
+
};
|
|
928
|
+
say(`Sending ${nodes.length} nodes of ${activeBlueprint.name} to /v1/prompt`, `Sending "${activeBlueprint.name}" to /v1/prompt…`);
|
|
929
|
+
try {
|
|
930
|
+
const end = await run(wire, compiledComfyPrompt, (state, note) => {
|
|
931
|
+
if (!mine.current())
|
|
932
|
+
return;
|
|
933
|
+
setRunningFlow(false);
|
|
934
|
+
mark(state);
|
|
935
|
+
say(`${state[0].toUpperCase()}${state.slice(1)}${note ? ` · ${note}` : ''}`, `"${activeBlueprint.name}" is ${state}${note ? `: ${note}` : ''}`);
|
|
936
|
+
}, { signal: mine.signal });
|
|
937
|
+
if (mine.current() && (end === 'queued' || end === 'running'))
|
|
938
|
+
say(`Still ${end}; no result yet`, `"${activeBlueprint.name}" is still ${end}; no result yet`);
|
|
939
|
+
}
|
|
940
|
+
catch (e) {
|
|
941
|
+
if (!mine.current())
|
|
942
|
+
return;
|
|
943
|
+
mark(null);
|
|
944
|
+
const why = e instanceof Error ? e.message : String(e);
|
|
945
|
+
say(`Not run · ${why}`, `"${activeBlueprint.name}" did not run: ${why}`);
|
|
946
|
+
}
|
|
947
|
+
finally {
|
|
948
|
+
if (mine.current())
|
|
949
|
+
setRunningFlow(false);
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
// Copilot asks the model to edit the graph and applies exactly the edit it answers with.
|
|
953
|
+
const [copilotBusy, setCopilotBusy] = useState(false);
|
|
954
|
+
const runCopilot = async () => {
|
|
955
|
+
const text = copilotInput.trim();
|
|
956
|
+
if (!text || copilotBusy)
|
|
957
|
+
return;
|
|
958
|
+
setCopilotBusy(true);
|
|
959
|
+
setStatusMessage(`Asking Flow Copilot: "${text}"…`);
|
|
960
|
+
try {
|
|
961
|
+
const said = await complete(wire, {
|
|
962
|
+
model: BRAIN,
|
|
963
|
+
messages: [
|
|
964
|
+
{ role: 'system', content: 'Mutate the Hanzo Flow (Langflow + ComfyUI) graph using the flow_mutate_graph MCP tool.' },
|
|
965
|
+
{ role: 'user', content: JSON.stringify({ instruction: text, graph: compiledComfyPrompt }) },
|
|
966
|
+
],
|
|
967
|
+
tools: [
|
|
968
|
+
{
|
|
969
|
+
type: 'function',
|
|
970
|
+
function: {
|
|
971
|
+
name: 'flow_mutate_graph',
|
|
972
|
+
description: 'Pure function: (Graph, Instruction) -> Graph',
|
|
973
|
+
parameters: {
|
|
974
|
+
type: 'object',
|
|
975
|
+
properties: {
|
|
976
|
+
add_node_type: { type: 'string' },
|
|
977
|
+
auto_layout: { type: 'boolean' },
|
|
978
|
+
},
|
|
979
|
+
},
|
|
980
|
+
},
|
|
981
|
+
},
|
|
982
|
+
],
|
|
983
|
+
}, () => { });
|
|
984
|
+
const got = graphEdit(said.calls);
|
|
985
|
+
const named = 'edit' in got && got.edit.addNodeType ? moduleCatalog.find((m) => m.type === got.edit.addNodeType) : undefined;
|
|
986
|
+
if (named) {
|
|
987
|
+
addModuleToCanvas(named);
|
|
988
|
+
setStatusMessage(`Copilot added ${named.type}`);
|
|
989
|
+
}
|
|
990
|
+
else if ('edit' in got && got.edit.autoLayout) {
|
|
991
|
+
autoLayout();
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
setStatusMessage(`Copilot made no change: ${'why' in got ? got.why : 'it named a node this canvas does not have'}`);
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
setCopilotInput('');
|
|
998
|
+
}
|
|
999
|
+
catch (e) {
|
|
1000
|
+
setStatusMessage(`Copilot made no change: ${e instanceof Error ? e.message : String(e)}`);
|
|
1001
|
+
}
|
|
1002
|
+
finally {
|
|
1003
|
+
setCopilotBusy(false);
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
const exportJson = () => {
|
|
1007
|
+
const blob = new Blob([JSON.stringify(compiledComfyPrompt, null, 2)], { type: 'application/json' });
|
|
1008
|
+
download(`${activeBlueprint.id}.flow.json`, blob);
|
|
1009
|
+
};
|
|
1010
|
+
const importJson = () => {
|
|
1011
|
+
const input = document.createElement('input');
|
|
1012
|
+
input.type = 'file';
|
|
1013
|
+
input.accept = '.json';
|
|
1014
|
+
input.onchange = async () => {
|
|
1015
|
+
const f = input.files?.[0];
|
|
1016
|
+
if (!f)
|
|
1017
|
+
return;
|
|
1018
|
+
try {
|
|
1019
|
+
const raw = JSON.parse(await f.text());
|
|
1020
|
+
const entries = Object.entries(raw).filter(([, v]) => v && typeof v === 'object' && typeof v.class_type === 'string');
|
|
1021
|
+
if (!entries.length)
|
|
1022
|
+
return;
|
|
1023
|
+
const nodes = entries.map(([id, item], idx) => {
|
|
1024
|
+
const scalar = {};
|
|
1025
|
+
const wiresFrom = [];
|
|
1026
|
+
for (const [k, v] of Object.entries(item.inputs ?? {})) {
|
|
1027
|
+
if (Array.isArray(v) && typeof v[0] === 'string') {
|
|
1028
|
+
if (!wiresFrom.includes(v[0]))
|
|
1029
|
+
wiresFrom.push(v[0]);
|
|
1030
|
+
}
|
|
1031
|
+
else if (typeof v === 'string' || typeof v === 'number') {
|
|
1032
|
+
scalar[k] = v;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
const spec = moduleCatalog.find((m) => m.type === item.class_type);
|
|
1036
|
+
return {
|
|
1037
|
+
id,
|
|
1038
|
+
type: item.class_type || 'CustomNode',
|
|
1039
|
+
title: item._meta?.title || spec?.title || item.class_type || `Node #${id}`,
|
|
1040
|
+
family: item._meta?.family === 'langflow' || spec?.family === 'langflow' ? 'langflow' : 'comfy',
|
|
1041
|
+
category: spec?.category || 'sampler',
|
|
1042
|
+
x: 25 + (idx % 4) * 245,
|
|
1043
|
+
y: 30 + Math.floor(idx / 4) * 155,
|
|
1044
|
+
inputs: scalar,
|
|
1045
|
+
wiresFrom,
|
|
1046
|
+
};
|
|
1047
|
+
});
|
|
1048
|
+
const id = `flow-${Date.now().toString(36)}`;
|
|
1049
|
+
setBlueprints((prev) => [
|
|
1050
|
+
{
|
|
1051
|
+
id,
|
|
1052
|
+
name: f.name.replace(/\.json$/i, ''),
|
|
1053
|
+
kind: 'Hybrid Langflow + ComfyUI',
|
|
1054
|
+
engine: 'Imported Flow JSON',
|
|
1055
|
+
description: `Imported ${nodes.length} nodes from ${f.name}`,
|
|
1056
|
+
nodes,
|
|
1057
|
+
},
|
|
1058
|
+
...prev,
|
|
1059
|
+
]);
|
|
1060
|
+
setActiveBlueprintId(id);
|
|
1061
|
+
setSelectedNodeId(nodes[0].id);
|
|
1062
|
+
setStatusMessage(`Imported "${f.name}" (${nodes.length} nodes) into Hanzo Flow`);
|
|
1063
|
+
}
|
|
1064
|
+
catch {
|
|
1065
|
+
setStatusMessage(`Could not parse "${f.name}" as a Flow / ComfyUI JSON graph`);
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
input.click();
|
|
1069
|
+
};
|
|
1070
|
+
const TABS = [
|
|
1071
|
+
{ id: 'canvas', label: 'Canvas' },
|
|
1072
|
+
{ id: 'comfy', label: 'ComfyUI' },
|
|
1073
|
+
{ id: 'agents', label: 'Agents & MCP' },
|
|
1074
|
+
{ id: 'code', label: 'Python' },
|
|
1075
|
+
{ id: 'publish', label: 'Publish' },
|
|
1076
|
+
];
|
|
1077
|
+
const langflowCount = activeBlueprint.nodes.filter((n) => n.family === 'langflow').length;
|
|
1078
|
+
const comfyCount = activeBlueprint.nodes.filter((n) => n.family === 'comfy').length;
|
|
1079
|
+
const filteredCatalog = useMemo(() => moduleCatalog
|
|
1080
|
+
.filter((m) => {
|
|
1081
|
+
if (section === 'comfy')
|
|
1082
|
+
return m.family === 'comfy';
|
|
1083
|
+
if (section === 'agents')
|
|
1084
|
+
return m.family === 'langflow';
|
|
1085
|
+
return familyFilter === 'all' ? true : m.family === familyFilter;
|
|
1086
|
+
})
|
|
1087
|
+
.filter((m) => {
|
|
1088
|
+
const q = searchQuery.trim().toLowerCase();
|
|
1089
|
+
if (!q)
|
|
1090
|
+
return true;
|
|
1091
|
+
return m.type.toLowerCase().includes(q) || m.title.toLowerCase().includes(q) || m.pack.toLowerCase().includes(q);
|
|
1092
|
+
}), [moduleCatalog, section, familyFilter, searchQuery]);
|
|
1093
|
+
const visibleCatalog = catalogExpanded || searchQuery.trim().length > 0 ? filteredCatalog : filteredCatalog.slice(0, 5);
|
|
1094
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, minW: 0, width: "100%", bg: "var(--background)", p: "$3", $md: { p: '$4' }, gap: "$3", overflowY: "auto", overflowX: "hidden", "data-slot": "flow-studio", children: [_jsxs(YStack, { gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", flexWrap: "wrap", gap: "$2.5", minW: 0, children: [_jsxs(YStack, { gap: 2, flex: 1, minW: 200, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Workflow, { size: 16, color: "$ink" }), _jsx(SizableText, { render: "h1", size: "$4", fontWeight: "600", color: "$ink", letterSpacing: -0.25, numberOfLines: 1, children: "Hanzo Flow \u2014 Visual workflow builder" })] }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 2, children: statusMessage })] }), _jsxs(XStack, { items: "center", gap: "$1.5", flexWrap: "wrap", shrink: 0, maxW: "100%", children: [_jsx(DropdownMenu, { minWidth: 210, trigger: _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Import or export flow JSON", items: "center", gap: "$1.5", px: "$3", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(Download, { size: 13, color: "$ink" }), _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$ink", children: "JSON" }), _jsx(ChevronDown, { size: 12, color: "$soft" })] }), items: [
|
|
1095
|
+
{ key: 'import', label: 'Import JSON', description: 'Load Langflow or ComfyUI graph', icon: _jsx(Upload, { size: 13, color: "$soft" }), onSelect: importJson },
|
|
1096
|
+
{ key: 'export', label: 'Export JSON', description: 'Download compiled /v1/prompt graph', icon: _jsx(Download, { size: 13, color: "$soft" }), onSelect: exportJson },
|
|
1097
|
+
{ type: 'separator', key: 's' },
|
|
1098
|
+
{ key: 'publish', label: 'Publish API / MCP', description: 'Inspect REST & MCP payload', icon: _jsx(Terminal, { size: 13, color: "$soft" }), onSelect: () => switchSection('publish') },
|
|
1099
|
+
] }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Back to Hanzo Studio", onClick: () => host.open('/studio'), items: "center", gap: "$1.5", px: "$3", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(ArrowLeft, { size: 13, color: "$ink" }), _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$ink", children: "Back to Studio" })] })] })] }), _jsx(XStack, { role: "tablist", "aria-label": "Flow sections", gap: "$1.5", pt: "$1", pb: "$0.5", overflowX: "auto", flexWrap: "nowrap", width: "100%", display: "flex", $md: { display: 'none' }, style: { scrollbarWidth: 'none' }, children: TABS.map((t) => {
|
|
1100
|
+
const on = section === t.id;
|
|
1101
|
+
return (_jsx(XStack, { render: _jsx("button", { type: "button" }), role: "tab", "aria-selected": on, onClick: () => switchSection(t.id), px: "$3", minH: 44, "$max-sm": { minH: 44 }, items: "center", rounded: 999, borderWidth: 1, borderColor: on ? '$ink' : 'var(--border-strong)', bg: on ? 'var(--surface-card-emphasis)' : 'transparent', cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: _jsx(SizableText, { size: "$1", fontWeight: on ? '600' : '500', color: on ? '$ink' : '$soft', children: t.label }) }, t.id));
|
|
1102
|
+
}) })] }), section === 'canvas' || section === 'comfy' || section === 'agents' ? (_jsxs(YStack, { gap: "$3", flex: 1, minW: 0, width: "100%", $xl: { flexDirection: 'row', items: 'flex-start' }, children: [_jsxs(YStack, { width: "100%", minW: 0, $xl: { width: 276, shrink: 0 }, $xxl: { width: 288 }, gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", children: [_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "600", color: "$ink", children: "1. Flow templates" }), _jsx(YStack, { gap: "$1.5", role: "list", "aria-label": "Flow templates", minW: 0, children: blueprints.map((b) => {
|
|
1103
|
+
const on = b.id === activeBlueprint.id;
|
|
1104
|
+
return (_jsx(YStack, { role: "listitem", width: "100%", minW: 0, children: _jsxs(YStack, { render: _jsx("button", { type: "button" }), onClick: () => {
|
|
1105
|
+
setActiveBlueprintId(b.id);
|
|
1106
|
+
setSelectedNodeId(b.nodes[0]?.id ?? '1');
|
|
1107
|
+
setConnectingFromId(null);
|
|
1108
|
+
setNodeRunStatus({});
|
|
1109
|
+
setZoom(1);
|
|
1110
|
+
setPan({ x: 0, y: 0 });
|
|
1111
|
+
}, width: "100%", minW: 0, minH: 44, "$max-sm": { minH: 44 }, p: "$2.5", rounded: "$3", borderWidth: 1, borderColor: on ? '$ink' : 'var(--border-strong)', bg: on ? 'var(--surface-card-emphasis)' : 'var(--background)', hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, gap: 3, items: "flex-start", cursor: "pointer", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 2, children: b.name }), _jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", text: "left", numberOfLines: 1, children: `${b.kind} · ${b.nodes.length} nodes` })] }) }, b.id));
|
|
1112
|
+
}) })] }), _jsxs(YStack, { gap: "$2", pt: "$2.5", borderTopWidth: 1, borderColor: "var(--border)", minW: 0, children: [_jsxs(XStack, { justify: "space-between", items: "center", gap: "$2", children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "600", color: "$ink", children: "2. Component library" }), _jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", children: `${filteredCatalog.length} nodes` })] }), _jsx(FlowInput, { "aria-label": "Search Langflow and ComfyUI components", ...{
|
|
1113
|
+
placeholder: 'Search ZenAgent, RAG, MCP, Wan…',
|
|
1114
|
+
value: searchQuery,
|
|
1115
|
+
}, onChange: (e) => setSearchQuery(e.currentTarget.value) }), section !== 'comfy' && section !== 'agents' ? (_jsx(XStack, { gap: "$1.5", flexWrap: "wrap", children: [
|
|
1116
|
+
{ id: 'all', label: 'All' },
|
|
1117
|
+
{ id: 'langflow', label: 'Agents' },
|
|
1118
|
+
{ id: 'comfy', label: 'ComfyUI' },
|
|
1119
|
+
].map((f) => {
|
|
1120
|
+
const on = familyFilter === f.id;
|
|
1121
|
+
return (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-pressed": on, onClick: () => setFamilyFilter(f.id), px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, items: "center", rounded: 999, borderWidth: 1, borderColor: on ? '$ink' : 'var(--border-strong)', bg: on ? 'var(--surface-card-emphasis)' : 'transparent', hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, cursor: "pointer", children: _jsx(SizableText, { size: "$1", fontWeight: on ? '600' : '500', color: on ? '$ink' : '$soft', children: f.label }) }, f.id));
|
|
1122
|
+
}) })) : null, _jsxs(YStack, { gap: "$1.5", maxH: 280, overflowY: "auto", pt: "$1", minW: 0, children: [visibleCatalog.map((spec) => (_jsxs(XStack, { render: _jsx("button", { type: "button" }), onClick: () => addModuleToCanvas(spec), width: "100%", minW: 0, minH: 44, "$max-sm": { minH: 44 }, p: "$2.5", rounded: "$3", borderWidth: 1, borderColor: "var(--border)", bg: "var(--background)", justify: "space-between", items: "center", gap: "$2", cursor: "pointer", hoverStyle: { bg: '$hover', borderColor: 'var(--border-strong)' }, focusVisibleStyle: RING, children: [_jsxs(YStack, { gap: 2, flex: 1, minW: 0, items: "flex-start", children: [_jsxs(XStack, { items: "center", gap: "$1.5", maxW: "100%", children: [_jsx(XStack, { width: 7, height: 7, rounded: 99, bg: spec.family === 'langflow' ? '$ink' : 'transparent', borderWidth: spec.family === 'langflow' ? 0 : 1.5, borderColor: "$soft", shrink: 0 }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, children: `+ ${spec.type}` })] }), _jsx(SizableText, { size: "$1", color: "$soft", text: "left", numberOfLines: 1, children: `${spec.title} · ${spec.pack}` })] }), _jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", shrink: 0, children: spec.outputPorts[0] || 'OUT' })] }, spec.type))), !searchQuery.trim() && filteredCatalog.length > 5 ? (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-expanded": catalogExpanded, onClick: () => setCatalogExpanded((v) => !v), width: "100%", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 30, height: 30 }, px: "$2.5", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$soft", children: catalogExpanded ? 'Show fewer nodes' : `Show all ${filteredCatalog.length} nodes` }) })) : null] })] })] }), _jsxs(YStack, { width: "100%", minW: 0, $xl: { flex: 1 }, gap: "$3", p: "$3.5", rounded: "$4", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", children: [_jsxs(XStack, { items: "flex-start", justify: "space-between", flexWrap: "wrap", gap: "$2.5", minW: 0, children: [_jsxs(YStack, { gap: 2, flex: 1, minW: 200, children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "600", color: "$ink", children: activeBlueprint.name }), _jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", children: `${activeBlueprint.nodes.length} nodes (${langflowCount} Langflow · ${comfyCount} ComfyUI) · ${activeBlueprint.engine}` })] }), _jsxs(XStack, { gap: "$1.5", items: "center", flexWrap: "wrap", shrink: 0, children: [_jsx(XStack, { render: _jsx("button", { type: "button" }), onClick: autoLayout, px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, items: "center", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: _jsx(SizableText, { size: "$1", color: "$ink", children: "Auto-layout" }) }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), onClick: () => switchSection('code'), px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, items: "center", gap: "$1", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(Code, { size: 12, color: "$ink" }), _jsx(SizableText, { size: "$1", color: "$ink", children: "Edit Python" })] }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Run flow (/v1/prompt)", disabled: runningFlow, onClick: () => void runFlowPlayground(), px: "$4", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, items: "center", gap: "$1.5", rounded: 999, bg: "$ink", opacity: runningFlow ? 0.65 : 1, cursor: runningFlow ? 'default' : 'pointer', hoverStyle: runningFlow ? undefined : { opacity: 0.9 }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(Play, { size: 12, color: "$background" }), _jsx(SizableText, { size: "$2", color: "$background", fontWeight: "600", children: runningFlow ? 'Running…' : 'Run flow' })] })] })] }), _jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", minW: 0, children: [_jsx(FlowInput, { "aria-label": "Flow Copilot instruction", flex: 1, minW: 180, rounded: 999, px: "$3.5", ...{
|
|
1123
|
+
placeholder: 'Ask Copilot to add a node or tidy the layout…',
|
|
1124
|
+
value: copilotInput,
|
|
1125
|
+
onKeyDown: (e) => {
|
|
1126
|
+
if (e.key === 'Enter')
|
|
1127
|
+
void runCopilot();
|
|
1128
|
+
},
|
|
1129
|
+
}, onChange: (e) => setCopilotInput(e.currentTarget.value) }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), onClick: () => void runCopilot(), disabled: copilotBusy, opacity: copilotBusy ? 0.6 : 1, px: "$3", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 34, height: 34 }, items: "center", gap: "$1.5", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(Wand2, { size: 13, color: "$ink" }), _jsx(SizableText, { size: "$1", fontWeight: "600", color: "$ink", children: copilotBusy ? 'Asking…' : 'Mutate flow' })] })] }), _jsxs("div", { ref: canvasViewportRef, onPointerDown: handleCanvasPointerDown, onPointerMove: handleCanvasPointerMove, onPointerUp: handleCanvasPointerUp, onPointerCancel: handleCanvasPointerUp, style: {
|
|
1130
|
+
position: 'relative',
|
|
1131
|
+
width: '100%',
|
|
1132
|
+
minHeight: 460,
|
|
1133
|
+
height: 480,
|
|
1134
|
+
borderRadius: 12,
|
|
1135
|
+
border: '1px solid var(--border-strong)',
|
|
1136
|
+
backgroundColor: 'var(--background)',
|
|
1137
|
+
backgroundImage: 'radial-gradient(color-mix(in srgb, var(--foreground) 12%, transparent) 1px, transparent 1px)',
|
|
1138
|
+
backgroundSize: `${Math.round(20 * zoom)}px ${Math.round(20 * zoom)}px`,
|
|
1139
|
+
backgroundPosition: `${pan.x}px ${pan.y}px`,
|
|
1140
|
+
overflow: 'hidden',
|
|
1141
|
+
cursor: isPanning ? 'grabbing' : 'grab',
|
|
1142
|
+
userSelect: 'none',
|
|
1143
|
+
touchAction: 'none',
|
|
1144
|
+
}, children: [_jsxs("div", { style: {
|
|
1145
|
+
position: 'absolute',
|
|
1146
|
+
inset: 0,
|
|
1147
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
1148
|
+
transformOrigin: '0 0',
|
|
1149
|
+
transition: isPanning || draggingNodeId || reducedMotion() ? 'none' : 'transform 140ms ease-out',
|
|
1150
|
+
}, children: [_jsx("svg", { width: 1400, height: 560, style: { position: 'absolute', inset: 0, pointerEvents: 'none', overflow: 'visible' }, children: activeBlueprint.nodes.flatMap((targetNode) => targetNode.wiresFrom.map((sourceId, wireIdx) => {
|
|
1151
|
+
const sourceNode = activeBlueprint.nodes.find((n) => n.id === sourceId);
|
|
1152
|
+
if (!sourceNode)
|
|
1153
|
+
return null;
|
|
1154
|
+
const x1 = sourceNode.x + NODE_W;
|
|
1155
|
+
const y1 = sourceNode.y + 52;
|
|
1156
|
+
const x2 = targetNode.x;
|
|
1157
|
+
const y2 = targetNode.y + 38 + wireIdx * 18;
|
|
1158
|
+
const cx1 = x1 + Math.max(45, (x2 - x1) * 0.5);
|
|
1159
|
+
const cx2 = x2 - Math.max(45, (x2 - x1) * 0.5);
|
|
1160
|
+
const isRunningWire = nodeRunStatus[targetNode.id] === 'running' || nodeRunStatus[sourceId] === 'running';
|
|
1161
|
+
const isDoneWire = nodeRunStatus[sourceId] === 'done' && nodeRunStatus[targetNode.id] === 'done';
|
|
1162
|
+
const stroke = isRunningWire
|
|
1163
|
+
? 'var(--foreground)'
|
|
1164
|
+
: isDoneWire
|
|
1165
|
+
? 'var(--state-success)'
|
|
1166
|
+
: sourceNode.family === 'langflow'
|
|
1167
|
+
? 'color-mix(in srgb, var(--foreground) 52%, transparent)'
|
|
1168
|
+
: 'color-mix(in srgb, var(--foreground) 30%, transparent)';
|
|
1169
|
+
return (_jsxs("g", { children: [_jsx("path", { d: `M ${x1} ${y1} C ${cx1} ${y1}, ${cx2} ${y2}, ${x2} ${y2}`, fill: "none", stroke: stroke, strokeWidth: isRunningWire ? 2.6 : isDoneWire ? 2.1 : 1.6, strokeDasharray: sourceNode.family === 'comfy' && !isRunningWire && !isDoneWire ? '4 3' : undefined }), _jsx("circle", { cx: x1, cy: y1, r: 3.5, fill: stroke }), _jsx("circle", { cx: x2, cy: y2, r: 3.5, fill: stroke })] }, `${sourceId}->${targetNode.id}-${wireIdx}`));
|
|
1170
|
+
})) }), activeBlueprint.nodes.map((node) => {
|
|
1171
|
+
const selected = node.id === selectedNode.id;
|
|
1172
|
+
const runState = nodeRunStatus[node.id];
|
|
1173
|
+
const isRunning = runState === 'running';
|
|
1174
|
+
const isDone = runState === 'done';
|
|
1175
|
+
const pill = runState === 'queued' ? 'Queued' : runState === 'failed' ? 'Failed' : isRunning ? 'Running' : '';
|
|
1176
|
+
const spec = moduleCatalog.find((m) => m.type === node.type);
|
|
1177
|
+
const familyLabel = node.family === 'langflow' ? 'Langflow' : 'ComfyUI';
|
|
1178
|
+
return (_jsx("div", { "data-flow-node": "1", role: "group", tabIndex: 0, "aria-label": `Node ${node.id}: ${node.title}`, onPointerDown: (e) => handleNodePointerDown(node, e), onFocus: () => setSelectedNodeId(node.id), onKeyDown: (e) => {
|
|
1179
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
1180
|
+
setSelectedNodeId(node.id);
|
|
1181
|
+
}
|
|
1182
|
+
}, style: {
|
|
1183
|
+
position: 'absolute',
|
|
1184
|
+
left: node.x,
|
|
1185
|
+
top: node.y,
|
|
1186
|
+
width: NODE_W,
|
|
1187
|
+
cursor: draggingNodeId === node.id ? 'grabbing' : 'grab',
|
|
1188
|
+
outline: 'none',
|
|
1189
|
+
}, children: _jsxs(YStack, { width: "100%", p: "$2.5", rounded: "$3", borderWidth: isRunning || selected ? 2 : 1, borderColor: isRunning
|
|
1190
|
+
? 'var(--foreground)'
|
|
1191
|
+
: isDone
|
|
1192
|
+
? 'var(--state-success)'
|
|
1193
|
+
: selected
|
|
1194
|
+
? 'var(--foreground)'
|
|
1195
|
+
: 'var(--border-strong)', bg: selected || isRunning ? 'var(--surface-card-emphasis)' : 'var(--surface-card)', boxShadow: isRunning ? '0 0 0 3px var(--ring-halo), var(--shadow-sheet-2)' : 'var(--shadow-sheet-2)', items: "flex-start", gap: "$1", children: [_jsxs(XStack, { justify: "space-between", items: "center", width: "100%", gap: "$1.5", children: [_jsxs(XStack, { items: "center", gap: "$1.5", flex: 1, minW: 0, children: [_jsx(XStack, { width: 7, height: 7, rounded: 99, bg: isDone ? 'var(--state-success)' : isRunning || node.family === 'langflow' ? 'var(--foreground)' : 'transparent', borderWidth: !isDone && !isRunning && node.family === 'comfy' ? 1.5 : 0, borderColor: "$soft", shrink: 0 }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, flex: 1, minW: 0, children: `#${node.id} ${node.title}` })] }), pill ? (_jsx(XStack, { px: "$1.5", height: 20, rounded: 999, bg: "var(--surface-card-emphasis)", borderWidth: 1, borderColor: "$ink", items: "center", shrink: 0, children: _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$ink", fontWeight: "600", children: pill }) })) : isDone ? (_jsx(XStack, { width: 18, height: 18, rounded: 999, bg: "var(--state-success-bg)", borderWidth: 1, borderColor: "var(--state-success)", items: "center", justify: "center", shrink: 0, "aria-label": "Done", ...{ title: 'Done' }, children: _jsx(Check, { size: 11, color: "var(--state-success)", "aria-hidden": true }) })) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", text: "left", numberOfLines: 1, children: `${familyLabel} · ${node.type} → ${(spec?.outputPorts ?? ['OUT']).join(',')}` }), _jsx(YStack, { gap: 1, pt: 2, width: "100%", items: "flex-start", children: Object.entries(node.inputs)
|
|
1196
|
+
.slice(0, 2)
|
|
1197
|
+
.map(([k, v]) => (_jsx(SizableText, { size: "$1", color: "$soft", text: "left", numberOfLines: 1, children: `${k}: ${String(v)}` }, k))) }), _jsxs(XStack, { justify: "space-between", items: "center", pt: "$1", width: "100%", gap: "$1", children: [connectingFromId && connectingFromId !== node.id ? (_jsx(XStack, { render: _jsx("button", { type: "button" }), onClick: () => toggleWire(connectingFromId, node.id), px: "$2", height: 24, "$max-sm": { minH: 44, height: 'auto' }, items: "center", rounded: 999, bg: "var(--state-success-bg)", borderWidth: 1, borderColor: "var(--state-success)", cursor: "pointer", focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", color: "var(--state-success)", children: node.wiresFrom.includes(connectingFromId) ? 'Unlink' : 'Connect input' }) })) : (_jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", children: node.wiresFrom.length > 0 ? `← [${node.wiresFrom.map((w) => `#${w}`).join(', ')}]` : 'Entry' })), _jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-pressed": connectingFromId === node.id, onClick: () => setConnectingFromId(connectingFromId === node.id ? null : node.id), px: "$2", height: 24, "$max-sm": { minH: 44, height: 'auto' }, items: "center", rounded: 999, bg: connectingFromId === node.id ? 'var(--surface-card-emphasis)' : 'transparent', borderWidth: 1, borderColor: connectingFromId === node.id ? '$ink' : 'var(--border-strong)', cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontWeight: connectingFromId === node.id ? '600' : '400', color: connectingFromId === node.id ? '$ink' : '$soft', children: connectingFromId === node.id ? 'Wiring…' : 'Wire out' }) })] })] }) }, node.id));
|
|
1198
|
+
})] }), _jsxs(XStack, { "data-flow-toolbar": "1", role: "toolbar", "aria-label": "Canvas viewport and history controls", position: "absolute", b: 12, l: 12, p: "$1", gap: "$1", items: "center", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--popover)", boxShadow: "var(--shadow-sheet-2)", z: 10, children: [_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Zoom out", disabled: zoom <= MIN_ZOOM, onClick: () => setZoom((z) => clampZoom(z - 0.1)), minW: 44, minH: 44, "$max-sm": { minW: 44, minH: 44 }, $md: { minW: 28, minH: 28, width: 28, height: 28 }, rounded: "$2", items: "center", justify: "center", opacity: zoom <= MIN_ZOOM ? 0.4 : 1, cursor: zoom <= MIN_ZOOM ? 'default' : 'pointer', hoverStyle: zoom <= MIN_ZOOM ? undefined : { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(Minus, { size: 13, color: "$ink" }) }), _jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": `Zoom ${Math.round(zoom * 100)}%, reset to 100%`, onClick: () => {
|
|
1199
|
+
setZoom(1);
|
|
1200
|
+
setPan({ x: 0, y: 0 });
|
|
1201
|
+
}, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, px: "$1.5", rounded: "$2", items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$ink", children: `${Math.round(zoom * 100)}%` }) }), _jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Zoom in", disabled: zoom >= MAX_ZOOM, onClick: () => setZoom((z) => clampZoom(z + 0.1)), minW: 44, minH: 44, "$max-sm": { minW: 44, minH: 44 }, $md: { minW: 28, minH: 28, width: 28, height: 28 }, rounded: "$2", items: "center", justify: "center", opacity: zoom >= MAX_ZOOM ? 0.4 : 1, cursor: zoom >= MAX_ZOOM ? 'default' : 'pointer', hoverStyle: zoom >= MAX_ZOOM ? undefined : { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(Plus, { size: 13, color: "$ink" }) }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Fit flow to canvas", onClick: fitCanvas, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, px: "$2", gap: "$1", rounded: "$2", items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: [_jsx(Maximize2, { size: 12, color: "$soft" }), _jsx(SizableText, { size: "$1", color: "$ink", children: "Fit" })] }), _jsx(XStack, { width: 1, height: 16, bg: "var(--border)", mx: "$0.5" }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Undo", disabled: !canUndo, onClick: undo, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, px: "$2", gap: "$1", rounded: "$2", items: "center", justify: "center", opacity: canUndo ? 1 : 0.4, cursor: canUndo ? 'pointer' : 'default', hoverStyle: canUndo ? { bg: '$hover' } : undefined, focusVisibleStyle: RING, children: [_jsx(Undo2, { size: 12, color: "$ink" }), _jsx(SizableText, { size: "$1", color: "$ink", children: "Undo" })] }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Redo", disabled: !canRedo, onClick: redo, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, px: "$2", gap: "$1", rounded: "$2", items: "center", justify: "center", opacity: canRedo ? 1 : 0.4, cursor: canRedo ? 'pointer' : 'default', hoverStyle: canRedo ? { bg: '$hover' } : undefined, focusVisibleStyle: RING, children: [_jsx(Redo2, { size: 12, color: "$ink" }), _jsx(SizableText, { size: "$1", color: "$ink", children: "Redo" })] })] })] }), _jsxs(YStack, { p: "$2.5", pb: "$3", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", gap: "$1", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", children: "Step-through execution log" }), _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", children: "Drag canvas to pan \u00B7 \u2318Z undo \u00B7 Del remove node" })] }), playgroundOutput.slice(-5).map((line, i) => (_jsx(SizableText, { size: "$1", color: /\] Done/.test(line) ? 'var(--state-success)' : '$soft', fontFamily: "$mono", children: line }, i)))] })] }), _jsxs(YStack, { width: "100%", minW: 0, $xl: { width: 268, shrink: 0 }, $xxl: { width: 280 }, gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", children: [_jsxs(XStack, { justify: "space-between", items: "center", gap: "$2", minW: 0, children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "600", color: "$ink", numberOfLines: 1, flex: 1, minW: 0, children: `#${selectedNode.id} ${selectedNode.title}` }), activeBlueprint.nodes.length > 1 ? (_jsx(XStack, { render: _jsx("button", { type: "button" }), onClick: () => deleteNode(selectedNode.id), px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, items: "center", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, shrink: 0, children: _jsx(SizableText, { size: "$1", color: "$soft", children: "Delete" }) })) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", children: `${selectedNode.family === 'langflow' ? 'Langflow' : 'ComfyUI'} · class_type: ${selectedNode.type}` }), _jsx(YStack, { gap: "$2.5", pt: "$1", minW: 0, children: Object.entries(selectedNode.inputs).map(([key, val]) => {
|
|
1202
|
+
const isMultiline = typeof val === 'string' && MULTILINE_INPUT_KEYS.has(key);
|
|
1203
|
+
return (_jsxs(YStack, { gap: "$1", minW: 0, children: [_jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", children: key }), isMultiline ? (_jsx(FlowInspectorTextarea, { "aria-label": `Node input ${key}`, lineHeight: 19, style: { resize: 'none' }, ...{ value: String(val), rows: 3 }, onChange: (e) => {
|
|
1204
|
+
updateNodeInput(key, e.currentTarget.value);
|
|
1205
|
+
} })) : (_jsx(FlowInput, { "aria-label": `Node input ${key}`, ...{
|
|
1206
|
+
type: typeof val === 'number' ? 'number' : 'text',
|
|
1207
|
+
value: String(val),
|
|
1208
|
+
}, onChange: (e) => {
|
|
1209
|
+
const raw = e.currentTarget.value;
|
|
1210
|
+
updateNodeInput(key, typeof val === 'number' ? Number(raw) : raw);
|
|
1211
|
+
} }))] }, key));
|
|
1212
|
+
}) })] })] })) : null, section === 'code' ? (_jsxs(YStack, { gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", minW: 0, children: [_jsxs(XStack, { justify: "space-between", items: "center", flexWrap: "wrap", gap: "$2", children: [_jsxs(YStack, { gap: 2, flex: 1, minW: 200, children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "600", color: "$ink", children: `Python component source: #${selectedNode.id} ${selectedNode.type}` }), _jsx(SizableText, { size: "$1", color: "$soft", children: "Every Langflow and ComfyUI (studio_compat) node is a Python class you can inspect and customize in place." })] }), _jsx(XStack, { render: _jsx("button", { type: "button" }), onClick: saveNodePythonCode, px: "$4", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, items: "center", rounded: 999, bg: "$ink", cursor: "pointer", hoverStyle: { opacity: 0.9 }, focusVisibleStyle: RING, shrink: 0, children: _jsx(SizableText, { size: "$2", color: "$background", fontWeight: "600", children: "Save Python component" }) })] }), _jsx(FlowTextarea, { "aria-label": "Python node class source code", lineHeight: 20, ...{ value: pythonDraft, rows: 16 }, onChange: (e) => setPythonDraft(e.currentTarget.value) })] })) : null, section === 'publish' ? (_jsxs(YStack, { gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "var(--border)", bg: "var(--surface-card)", minW: 0, children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "600", color: "$ink", children: "Publish flow \u2014 REST API, ComfyUI /v1/prompt JSON, or MCP server tool" }), _jsx(SizableText, { size: "$1", color: "$soft", children: "Every Hanzo Flow graph can be called over HTTP (POST /v1/prompt or /v1/flows/run), loaded as JSON in Python, or exposed as an MCP tool to Hanzo Dev and Claude Code." }), _jsx(YStack, { p: "$3", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", maxH: 460, overflow: "scroll", minW: 0, children: _jsx(SizableText, { fontFamily: "$mono", size: "$1", color: "$ink", whiteSpace: "pre", children: JSON.stringify(compiledComfyPrompt, null, 2) }) })] })) : null] }));
|
|
1213
|
+
}
|