@hanzo/studio 0.1.11 → 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/flow.js CHANGED
@@ -1,45 +1,92 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { SizableText, XStack, YStack } from '@hanzo/gui';
3
- import { Boxes, Code, Download, Layers, Play, Sparkles, Terminal, Upload, Wand2, Workflow, } from '@hanzogui/lucide-icons-2';
4
- import { createElement, useEffect, useMemo, useState } from 'react';
5
- export function parseFlowSection(path) {
6
- const clean = (path ?? '').replace(/^\/+|\/+$/g, '').split('/')[0] ?? '';
7
- if (clean === 'hybrid' || clean === 'comfy' || clean === 'agents' || clean === 'code' || clean === 'publish') {
8
- return clean;
9
- }
10
- return 'canvas';
11
- }
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 };
12
59
  export function flowNav(host, go) {
13
60
  const active = parseFlowSection(host.path);
14
61
  return [
15
62
  {
16
63
  id: 'make',
17
- label: 'Hanzo Flow (Langflow + Comfy)',
64
+ label: 'Hanzo Flow',
18
65
  links: [
19
66
  {
20
67
  id: 'canvas',
21
- label: 'Flow Canvas & Playground',
68
+ label: 'Flow canvas & playground',
22
69
  active: active === 'canvas',
23
70
  icon: createElement(Workflow, { size: 16 }),
24
71
  onPress: () => go(''),
25
72
  },
26
73
  {
27
74
  id: 'comfy',
28
- label: 'ComfyUI Node Extensions',
75
+ label: 'ComfyUI node extensions',
29
76
  active: active === 'comfy',
30
77
  icon: createElement(Layers, { size: 16 }),
31
78
  onPress: () => go('comfy'),
32
79
  },
33
80
  {
34
81
  id: 'agents',
35
- label: 'Langflow Agents, RAG & MCP',
82
+ label: 'Langflow agents, RAG & MCP',
36
83
  active: active === 'agents',
37
84
  icon: createElement(Boxes, { size: 16 }),
38
85
  onPress: () => go('agents'),
39
86
  },
40
87
  {
41
88
  id: 'code',
42
- label: 'Python Node Code Editor',
89
+ label: 'Python node code editor',
43
90
  active: active === 'code',
44
91
  icon: createElement(Code, { size: 16 }),
45
92
  onPress: () => go('code'),
@@ -459,7 +506,23 @@ export const FLOW_BLUEPRINTS = [
459
506
  ],
460
507
  },
461
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
+ }
462
524
  export function FlowStudio({ host }) {
525
+ const wire = useWire(host);
463
526
  const [section, setSection] = useState(() => parseFlowSection(host.path));
464
527
  useEffect(() => {
465
528
  setSection(parseFlowSection(host.path));
@@ -470,36 +533,214 @@ export function FlowStudio({ host }) {
470
533
  };
471
534
  const [blueprints, setBlueprints] = useState(() => FLOW_BLUEPRINTS.map((b) => ({
472
535
  ...b,
473
- nodes: b.nodes.map((n) => ({ ...n, inputs: { ...n.inputs }, wiresFrom: [...n.wiresFrom] })),
536
+ nodes: cloneNodes(b.nodes),
474
537
  })));
475
538
  const [activeBlueprintId, setActiveBlueprintId] = useState(FLOW_BLUEPRINTS[0].id);
476
539
  const activeBlueprint = blueprints.find((b) => b.id === activeBlueprintId) ?? blueprints[0];
477
540
  const [selectedNodeId, setSelectedNodeId] = useState(activeBlueprint.nodes[0]?.id ?? '1');
478
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);
479
557
  const [moduleCatalog, setModuleCatalog] = useState(() => [...FLOW_MODULE_CATALOG]);
480
558
  const [familyFilter, setFamilyFilter] = useState('all');
481
559
  const [searchQuery, setSearchQuery] = useState('');
482
560
  const [connectingFromId, setConnectingFromId] = useState(null);
483
- const [executingNodeId, setExecutingNodeId] = useState(null);
561
+ const [runningFlow, setRunningFlow] = useState(false);
562
+ const [nodeRunStatus, setNodeRunStatus] = useState({});
484
563
  const [copilotInput, setCopilotInput] = useState('');
485
- const [statusMessage, setStatusMessage] = useState('Hanzo Flow · Langflow Agent Nodes + ComfyUI Native-Compat Engine (/v1/object_info & /v1/prompt)');
564
+ const [statusMessage, setStatusMessage] = useState('Hanzo Flow · Langflow agent nodes + ComfyUI native engine (/v1/object_info & /v1/prompt)');
486
565
  const [playgroundOutput, setPlaygroundOutput] = useState([
487
- '[Ready] Hybrid graph loaded: ChatInput → VectorStoreRAG → ZenAgentNode → UNETLoader → CLIPTextEncode → KSampler → MMAudioVideoToAudio → SaveWEBM',
566
+ `[${formatClock()}] Ready · ${FLOW_BLUEPRINTS[0].nodes.length} nodes loaded (${FLOW_BLUEPRINTS[0].engine})`,
488
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
+ };
489
738
  // Discover live ComfyUI modules from /v1/object_info when backend is available
490
739
  useEffect(() => {
491
740
  let alive = true;
492
- const apiBase = host.api || 'https://api.hanzo.ai';
493
- const token = host.token();
494
- const headers = {};
495
- if (token)
496
- headers.Authorization = `Bearer ${token}`;
497
- if (host.org)
498
- headers['X-Org-Id'] = host.org;
499
- fetch(`${apiBase}/v1/object_info`, { headers })
500
- .then((r) => (r.ok ? r.json() : null))
741
+ objectInfo(wire)
501
742
  .then((info) => {
502
- if (!alive || !info || typeof info !== 'object')
743
+ if (!alive)
503
744
  return;
504
745
  const existing = new Set(FLOW_MODULE_CATALOG.map((m) => m.type));
505
746
  const extra = [];
@@ -525,7 +766,7 @@ export function FlowStudio({ host }) {
525
766
  return () => {
526
767
  alive = false;
527
768
  };
528
- }, [host]);
769
+ }, [wire]);
529
770
  const selectedSpec = moduleCatalog.find((m) => m.type === selectedNode.type);
530
771
  const [pythonDraft, setPythonDraft] = useState(() => selectedNode.pythonCode || selectedSpec?.pythonSource || '');
531
772
  useEffect(() => {
@@ -533,20 +774,10 @@ export function FlowStudio({ host }) {
533
774
  setPythonDraft(selectedNode.pythonCode || spec?.pythonSource || '');
534
775
  }, [selectedNode, moduleCatalog]);
535
776
  const updateNodeInput = (key, val) => {
536
- setBlueprints((prev) => prev.map((b) => b.id === activeBlueprint.id
537
- ? {
538
- ...b,
539
- nodes: b.nodes.map((n) => (n.id === selectedNode.id ? { ...n, inputs: { ...n.inputs, [key]: val } } : n)),
540
- }
541
- : b));
777
+ commitGraph((nodes) => nodes.map((n) => (n.id === selectedNode.id ? { ...n, inputs: { ...n.inputs, [key]: val } } : n)), { coalesceKey: `${selectedNode.id}:${key}` });
542
778
  };
543
779
  const saveNodePythonCode = () => {
544
- setBlueprints((prev) => prev.map((b) => b.id === activeBlueprint.id
545
- ? {
546
- ...b,
547
- nodes: b.nodes.map((n) => (n.id === selectedNode.id ? { ...n, pythonCode: pythonDraft } : n)),
548
- }
549
- : b));
780
+ commitGraph((nodes) => nodes.map((n) => (n.id === selectedNode.id ? { ...n, pythonCode: pythonDraft } : n)));
550
781
  setStatusMessage(`Saved live Python component class for #${selectedNode.id} ${selectedNode.type}`);
551
782
  };
552
783
  const addModuleToCanvas = (spec) => {
@@ -574,49 +805,64 @@ export function FlowStudio({ host }) {
574
805
  wiresFrom: selectedNode ? [selectedNode.id] : [],
575
806
  pythonCode: spec.pythonSource,
576
807
  };
577
- setBlueprints((prev) => prev.map((b) => (b.id === activeBlueprint.id ? { ...b, nodes: [...b.nodes, created] } : b)));
808
+ commitGraph((nodes) => [...nodes, created]);
578
809
  setSelectedNodeId(nextId);
579
810
  setStatusMessage(`Added ${spec.family === 'langflow' ? 'Langflow' : 'ComfyUI'} node #${nextId} ${spec.type} to Flow canvas`);
580
811
  };
581
812
  const toggleWire = (fromId, toId) => {
582
813
  if (fromId === toId)
583
814
  return;
584
- setBlueprints((prev) => prev.map((b) => {
585
- if (b.id !== activeBlueprint.id)
586
- return b;
815
+ commitGraph((nodes) => nodes.map((n) => {
816
+ if (n.id !== toId)
817
+ return n;
818
+ const exists = n.wiresFrom.includes(fromId);
587
819
  return {
588
- ...b,
589
- nodes: b.nodes.map((n) => {
590
- if (n.id !== toId)
591
- return n;
592
- const exists = n.wiresFrom.includes(fromId);
593
- return {
594
- ...n,
595
- wiresFrom: exists ? n.wiresFrom.filter((w) => w !== fromId) : [...n.wiresFrom, fromId],
596
- };
597
- }),
820
+ ...n,
821
+ wiresFrom: exists ? n.wiresFrom.filter((w) => w !== fromId) : [...n.wiresFrom, fromId],
598
822
  };
599
823
  }));
600
824
  setConnectingFromId(null);
601
825
  setStatusMessage(`Wired #${fromId} → #${toId}`);
602
826
  };
603
- const deleteNode = (nodeId) => {
827
+ const deleteNode = useCallback((nodeId) => {
604
828
  if (activeBlueprint.nodes.length <= 1)
605
829
  return;
606
- setBlueprints((prev) => prev.map((b) => {
607
- if (b.id !== activeBlueprint.id)
608
- return b;
609
- return {
610
- ...b,
611
- nodes: b.nodes
612
- .filter((n) => n.id !== nodeId)
613
- .map((n) => ({ ...n, wiresFrom: n.wiresFrom.filter((w) => w !== nodeId) })),
614
- };
615
- }));
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) })));
616
832
  const fallback = activeBlueprint.nodes.find((n) => n.id !== nodeId);
617
833
  if (fallback)
618
834
  setSelectedNodeId(fallback.id);
619
- };
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]);
620
866
  const autoLayout = () => {
621
867
  const order = {
622
868
  agent: 0,
@@ -626,21 +872,17 @@ export function FlowStudio({ host }) {
626
872
  decode: 3,
627
873
  output: 4,
628
874
  };
629
- const counts = {};
630
- setBlueprints((prev) => prev.map((b) => {
631
- if (b.id !== activeBlueprint.id)
632
- return b;
633
- const sorted = [...b.nodes].sort((x, y) => order[x.category] - order[y.category] || Number(x.id) - Number(y.id));
634
- return {
635
- ...b,
636
- nodes: sorted.map((n) => {
637
- const col = order[n.category];
638
- const row = counts[col] ?? 0;
639
- counts[col] = row + 1;
640
- return { ...n, x: 25 + col * 245, y: 30 + row * 155 };
641
- }),
642
- };
643
- }));
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 });
644
886
  setStatusMessage(`Auto-aligned ${activeBlueprint.nodes.length} Langflow + ComfyUI nodes`);
645
887
  };
646
888
  const compiledComfyPrompt = useMemo(() => {
@@ -660,110 +902,110 @@ export function FlowStudio({ host }) {
660
902
  }
661
903
  return out;
662
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]);
663
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])) : {});
664
922
  const logs = [];
665
- setStatusMessage(`Running "${activeBlueprint.name}" step-by-step across Langflow + ComfyUI engine…`);
666
- for (const node of activeBlueprint.nodes) {
667
- setExecutingNodeId(node.id);
668
- logs.push(`[Step #${node.id} · ${node.family.toUpperCase()}] ${node.type} (${node.title}) → OK`);
923
+ const say = (line, status) => {
924
+ logs.push(`[${formatClock()}] ${line}`);
669
925
  setPlaygroundOutput([...logs]);
670
- await new Promise((r) => setTimeout(r, 120));
671
- }
926
+ setStatusMessage(status);
927
+ };
928
+ say(`Sending ${nodes.length} nodes of ${activeBlueprint.name} to /v1/prompt`, `Sending "${activeBlueprint.name}" to /v1/prompt…`);
672
929
  try {
673
- const token = host.token();
674
- const headers = { 'Content-Type': 'application/json' };
675
- if (token)
676
- headers.Authorization = `Bearer ${token}`;
677
- if (host.org)
678
- headers['X-Org-Id'] = host.org;
679
- const apiBase = host.api || 'https://api.hanzo.ai';
680
- await fetch(`${apiBase}/v1/prompt`, {
681
- method: 'POST',
682
- headers,
683
- body: JSON.stringify({ prompt: compiledComfyPrompt }),
684
- }).catch(() => null);
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}`);
685
946
  }
686
947
  finally {
687
- setExecutingNodeId(null);
688
- logs.push(`[Done] Dispatched ${activeBlueprint.nodes.length} nodes to /v1/prompt · Output landed in /studio Library`);
689
- setPlaygroundOutput([...logs]);
690
- setStatusMessage(`✓ Completed Flow run "${activeBlueprint.name}" (${activeBlueprint.nodes.length} nodes)`);
948
+ if (mine.current())
949
+ setRunningFlow(false);
691
950
  }
692
951
  };
952
+ // Copilot asks the model to edit the graph and applies exactly the edit it answers with.
953
+ const [copilotBusy, setCopilotBusy] = useState(false);
693
954
  const runCopilot = async () => {
694
955
  const text = copilotInput.trim();
695
- if (!text)
956
+ if (!text || copilotBusy)
696
957
  return;
697
- setStatusMessage(`Agent mutating Flow graph via /v1/chat/completions + MCP tool flow_mutate_graph: "${text}"…`);
958
+ setCopilotBusy(true);
959
+ setStatusMessage(`Asking Flow Copilot: "${text}"…`);
698
960
  try {
699
- const token = host.token();
700
- const headers = { 'Content-Type': 'application/json' };
701
- if (token)
702
- headers.Authorization = `Bearer ${token}`;
703
- if (host.org)
704
- headers['X-Org-Id'] = host.org;
705
- const apiBase = host.api || 'https://api.hanzo.ai';
706
- await fetch(`${apiBase}/v1/chat/completions`, {
707
- method: 'POST',
708
- headers,
709
- body: JSON.stringify({
710
- model: 'zen5',
711
- messages: [
712
- { role: 'system', content: 'Mutate the Hanzo Flow (Langflow + ComfyUI) graph using the flow_mutate_graph MCP tool.' },
713
- { role: 'user', content: JSON.stringify({ instruction: text, graph: compiledComfyPrompt }) },
714
- ],
715
- tools: [
716
- {
717
- type: 'function',
718
- function: {
719
- name: 'flow_mutate_graph',
720
- description: 'Pure function: (Graph, Instruction) -> Graph',
721
- parameters: {
722
- type: 'object',
723
- properties: {
724
- add_node_type: { type: 'string' },
725
- auto_layout: { type: 'boolean' },
726
- },
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' },
727
978
  },
728
979
  },
729
980
  },
730
- ],
731
- tool_choice: 'auto',
732
- }),
733
- }).catch(() => null);
734
- }
735
- catch {
736
- // Pure client-side graph reducer fallback
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('');
737
998
  }
738
- const lower = text.toLowerCase();
739
- const match = moduleCatalog.find((m) => lower.includes(m.type.toLowerCase())) ||
740
- (lower.includes('rag') || lower.includes('vector')
741
- ? moduleCatalog.find((m) => m.type === 'VectorStoreRAG')
742
- : lower.includes('mcp')
743
- ? moduleCatalog.find((m) => m.type === 'MCPToolNode')
744
- : lower.includes('agent') || lower.includes('zen')
745
- ? moduleCatalog.find((m) => m.type === 'ZenAgentNode')
746
- : lower.includes('controlnet') || lower.includes('depth')
747
- ? moduleCatalog.find((m) => m.type === 'ControlNetApplyAdvanced')
748
- : lower.includes('demucs') || lower.includes('stem')
749
- ? moduleCatalog.find((m) => m.type === 'DemucsStemSeparation')
750
- : lower.includes('upscale')
751
- ? moduleCatalog.find((m) => m.type === 'UltimateSDUpscale')
752
- : null);
753
- if (match) {
754
- addModuleToCanvas(match);
999
+ catch (e) {
1000
+ setStatusMessage(`Copilot made no change: ${e instanceof Error ? e.message : String(e)}`);
755
1001
  }
756
- else {
757
- autoLayout();
1002
+ finally {
1003
+ setCopilotBusy(false);
758
1004
  }
759
- setCopilotInput('');
760
1005
  };
761
1006
  const exportJson = () => {
762
1007
  const blob = new Blob([JSON.stringify(compiledComfyPrompt, null, 2)], { type: 'application/json' });
763
- const a = document.createElement('a');
764
- a.href = URL.createObjectURL(blob);
765
- a.download = `${activeBlueprint.id}.flow.json`;
766
- a.click();
1008
+ download(`${activeBlueprint.id}.flow.json`, blob);
767
1009
  };
768
1010
  const importJson = () => {
769
1011
  const input = document.createElement('input');
@@ -826,123 +1068,146 @@ export function FlowStudio({ host }) {
826
1068
  input.click();
827
1069
  };
828
1070
  const TABS = [
829
- { id: 'canvas', label: 'Flow Canvas & Playground', badge: `${activeBlueprint.nodes.length} Nodes` },
830
- { id: 'comfy', label: 'ComfyUI Node Extensions', badge: `${moduleCatalog.filter((m) => m.family === 'comfy').length} Modules` },
831
- { id: 'agents', label: 'Langflow Agents, RAG & MCP', badge: `${moduleCatalog.filter((m) => m.family === 'langflow').length} Nodes` },
832
- { id: 'code', label: 'Python Node Code Editor', badge: 'Live Class' },
833
- { id: 'publish', label: 'Publish REST / MCP / JSON', badge: 'API & MCP' },
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' },
834
1076
  ];
835
- return (_jsxs(YStack, { flex: 1, minH: 0, bg: "$background", p: "$3", gap: "$3", overflow: "scroll", "data-slot": "flow-studio", children: [_jsxs(YStack, { gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "var(--pane-fill, var(--sheet-1))", children: [_jsxs(XStack, { items: "center", justify: "space-between", flexWrap: "wrap", gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$2.5", flexWrap: "wrap", children: [_jsx(Workflow, { size: 16 }), _jsx(SizableText, { size: "$3", fontWeight: "600", children: "Hanzo Flow \u2014 Langflow + ComfyUI Native-Compat Workflow Builder" }), _jsx(SizableText, { size: "$1", color: "$soft", children: statusMessage })] }), _jsxs(XStack, { items: "center", gap: "$2", flexWrap: "wrap", children: [_jsxs(XStack, { render: "button", onPress: importJson, items: "center", gap: "$1.5", px: "$3", height: 30, rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Upload, { size: 13 }), _jsx(SizableText, { size: "$1", children: "Import Langflow / Comfy JSON" })] }), _jsxs(XStack, { render: "button", onPress: exportJson, items: "center", gap: "$1.5", px: "$3", height: 30, rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Download, { size: 13 }), _jsx(SizableText, { size: "$1", children: "Export Flow JSON" })] }), _jsxs(XStack, { render: "a", ...{ href: '/studio' }, items: "center", gap: "$1.5", px: "$3", height: 30, rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", style: { textDecoration: 'none' }, children: [_jsx(Sparkles, { size: 13 }), _jsx(SizableText, { size: "$1", fontWeight: "600", children: "\u2190 Back to Hanzo Studio (/studio)" })] })] })] }), _jsx(XStack, { gap: "$2", flexWrap: "wrap", pt: "$1", children: TABS.map((t) => {
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) => {
836
1100
  const on = section === t.id;
837
- return (_jsxs(XStack, { render: "button", onPress: () => switchSection(t.id), px: "$3", height: 34, items: "center", gap: "$2", rounded: 999, borderWidth: 1, borderColor: on ? '$ink' : '$borderColor', bg: on ? '$ink' : 'transparent', cursor: "pointer", children: [_jsx(SizableText, { size: "$2", fontWeight: on ? '600' : '500', color: on ? '$background' : '$ink', children: t.label }), _jsx(SizableText, { size: "$1", color: on ? '$background' : '$soft', style: { opacity: on ? 0.8 : 1 }, children: t.badge })] }, t.id));
838
- }) })] }), section === 'canvas' || section === 'comfy' || section === 'agents' ? (_jsxs(XStack, { gap: "$3", flex: 1, minH: 540, flexWrap: "wrap", children: [_jsxs(YStack, { width: 310, grow: 1, maxW: 350, gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "var(--pane-fill, var(--sheet-1))", children: [_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", children: "1. Flow Templates" }), _jsx(YStack, { gap: "$1.5", role: "list", "aria-label": "Starters", children: blueprints.map((b) => {
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) => {
839
1103
  const on = b.id === activeBlueprint.id;
840
- return (_jsxs(YStack, { render: "button", onPress: () => {
841
- setActiveBlueprintId(b.id);
842
- setSelectedNodeId(b.nodes[0]?.id ?? '1');
843
- setConnectingFromId(null);
844
- }, p: "$2", rounded: "$3", borderWidth: 1, borderColor: on ? '$ink' : '$borderColor', bg: on ? '$hover' : 'transparent', gap: 2, cursor: "pointer", style: { textAlign: 'left' }, children: [_jsx(XStack, { justify: "space-between", items: "center", children: _jsx(SizableText, { size: "$1", fontWeight: "600", numberOfLines: 1, children: b.name }) }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, style: { fontFamily: 'ui-monospace, monospace' }, children: `${b.kind} · ${b.nodes.length} nodes` })] }, b.id));
845
- }) })] }), _jsxs(YStack, { gap: "$1.5", pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", children: [_jsxs(XStack, { justify: "space-between", items: "center", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", children: "2. Component Library" }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${moduleCatalog.length} nodes` })] }), _jsx("input", { "aria-label": "Search Langflow and ComfyUI components", placeholder: "Search ZenAgent, RAG, MCP, Wan, KSampler, Qwen\u2026", value: searchQuery, onChange: (e) => setSearchQuery(e.currentTarget.value), style: {
846
- width: '100%',
847
- height: 32,
848
- borderRadius: 8,
849
- padding: '0 10px',
850
- background: 'rgba(255,255,255,0.04)',
851
- border: '1px solid rgba(255,255,255,0.12)',
852
- color: 'inherit',
853
- font: 'inherit',
854
- fontSize: 12,
855
- } }), _jsx(XStack, { gap: 4, flexWrap: "wrap", children: [
856
- { id: 'all', label: 'ALL' },
857
- { id: 'langflow', label: 'LANGFLOW AGENTS' },
858
- { id: 'comfy', label: 'COMFYUI NODES' },
859
- ].map((f) => (_jsx(XStack, { render: "button", onPress: () => setFamilyFilter(f.id), px: "$2", height: 22, items: "center", rounded: 999, borderWidth: 1, borderColor: familyFilter === f.id ? '$ink' : '$borderColor', bg: familyFilter === f.id ? '$ink' : 'transparent', cursor: "pointer", children: _jsx(SizableText, { size: "$1", color: familyFilter === f.id ? '$background' : '$soft', children: f.label }) }, f.id))) }), _jsx(YStack, { gap: 6, maxH: 270, overflow: "scroll", pt: "$1", children: moduleCatalog
860
- .filter((m) => {
861
- if (section === 'comfy')
862
- return m.family === 'comfy';
863
- if (section === 'agents')
864
- return m.family === 'langflow';
865
- return familyFilter === 'all' ? true : m.family === familyFilter;
866
- })
867
- .filter((m) => {
868
- const q = searchQuery.trim().toLowerCase();
869
- if (!q)
870
- return true;
871
- return m.type.toLowerCase().includes(q) || m.title.toLowerCase().includes(q) || m.pack.toLowerCase().includes(q);
872
- })
873
- .map((spec) => (_jsxs(XStack, { render: "button", onPress: () => addModuleToCanvas(spec), p: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", justify: "space-between", items: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, style: { textAlign: 'left' }, children: [_jsxs(YStack, { gap: 1, flex: 1, minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$1.5", children: [_jsx("span", { style: {
874
- width: 7,
875
- height: 7,
876
- borderRadius: 99,
877
- background: spec.family === 'langflow' ? '#3ddc84' : '#38bdf8',
878
- display: 'inline-block',
879
- } }), _jsx(SizableText, { size: "$1", fontWeight: "600", numberOfLines: 1, children: `+ ${spec.type}` })] }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: `${spec.title} · ${spec.pack}` })] }), _jsx(SizableText, { size: "$1", color: "$soft", style: { fontFamily: 'ui-monospace, monospace' }, children: spec.outputPorts[0] || 'OUT' })] }, spec.type))) })] })] }), _jsxs(YStack, { flex: 2, minW: 440, gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "var(--pane-fill, var(--sheet-1))", children: [_jsxs(XStack, { items: "center", justify: "space-between", flexWrap: "wrap", gap: "$2", children: [_jsxs(YStack, { children: [_jsx(SizableText, { size: "$3", fontWeight: "600", children: activeBlueprint.name }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${activeBlueprint.nodes.length} nodes (${activeBlueprint.nodes.filter((n) => n.family === 'langflow').length} Langflow · ${activeBlueprint.nodes.filter((n) => n.family === 'comfy').length} ComfyUI) · ${activeBlueprint.engine}` })] }), _jsxs(XStack, { gap: "$1.5", items: "center", flexWrap: "wrap", children: [_jsx(XStack, { render: "button", onPress: autoLayout, px: "$2.5", height: 30, items: "center", rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: _jsx(SizableText, { size: "$1", children: "Auto-Layout" }) }), _jsxs(XStack, { render: "button", onPress: () => switchSection('code'), px: "$2.5", height: 30, items: "center", gap: "$1", rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Code, { size: 12 }), _jsx(SizableText, { size: "$1", children: "Edit Python Node" })] }), _jsx(XStack, { render: "button", onPress: () => switchSection('publish'), px: "$2.5", height: 30, items: "center", rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: _jsx(SizableText, { size: "$1", children: "Publish API / MCP" }) }), _jsxs(XStack, { render: "button", onPress: () => void runFlowPlayground(), px: "$3.5", height: 32, items: "center", gap: "$1.5", rounded: 999, bg: "$ink", cursor: "pointer", children: [_jsx(Play, { size: 13 }), _jsx(SizableText, { size: "$1", color: "$background", fontWeight: "600", children: "Run Flow (/v1/prompt)" })] })] })] }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsx("input", { "aria-label": "Flow Copilot instruction", placeholder: "Ask Flow Copilot to add or wire nodes (e.g. 'Add Vector RAG', 'Add MCP tool', 'Add ControlNet depth', 'Add Demucs stems')\u2026", value: copilotInput, onChange: (e) => setCopilotInput(e.currentTarget.value), onKeyDown: (e) => {
880
- if (e.key === 'Enter')
881
- void runCopilot();
882
- }, style: {
883
- flex: 1,
884
- height: 34,
885
- borderRadius: 999,
886
- padding: '0 14px',
887
- background: 'rgba(255,255,255,0.04)',
888
- border: '1px solid rgba(255,255,255,0.12)',
889
- color: 'inherit',
890
- font: 'inherit',
891
- fontSize: 12,
892
- } }), _jsxs(XStack, { render: "button", onPress: () => void runCopilot(), px: "$3", height: 34, items: "center", gap: "$1.5", rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Wand2, { size: 13 }), _jsx(SizableText, { size: "$1", fontWeight: "600", children: "Mutate Flow" })] })] }), _jsx(YStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "#07080d", minH: 380, overflow: "scroll", style: {
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: {
893
1130
  position: 'relative',
894
- backgroundImage: 'radial-gradient(rgba(255,255,255,0.08) 1px, transparent 1px)',
895
- backgroundSize: '20px 20px',
896
- }, children: _jsxs("div", { style: { position: 'relative', minWidth: 1240, minHeight: 350 }, children: [_jsx("svg", { width: 1240, height: 350, style: { position: 'absolute', inset: 0, pointerEvents: 'none', overflow: 'visible' }, children: activeBlueprint.nodes.flatMap((targetNode) => targetNode.wiresFrom.map((sourceId, wireIdx) => {
897
- const sourceNode = activeBlueprint.nodes.find((n) => n.id === sourceId);
898
- if (!sourceNode)
899
- return null;
900
- const x1 = sourceNode.x + 215;
901
- const y1 = sourceNode.y + 52;
902
- const x2 = targetNode.x;
903
- const y2 = targetNode.y + 38 + wireIdx * 18;
904
- const cx1 = x1 + Math.max(45, (x2 - x1) * 0.5);
905
- const cx2 = x2 - Math.max(45, (x2 - x1) * 0.5);
906
- const stroke = sourceNode.family === 'langflow' ? '#3ddc84' : '#38bdf8';
907
- return (_jsxs("g", { children: [_jsx("path", { d: `M ${x1} ${y1} C ${cx1} ${y1}, ${cx2} ${y2}, ${x2} ${y2}`, fill: "none", stroke: stroke, strokeWidth: executingNodeId === targetNode.id || executingNodeId === sourceId ? 3.2 : 2, strokeOpacity: 0.82 }), _jsx("circle", { cx: x1, cy: y1, r: 4, fill: stroke }), _jsx("circle", { cx: x2, cy: y2, r: 4, fill: stroke })] }, `${sourceId}->${targetNode.id}-${wireIdx}`));
908
- })) }), activeBlueprint.nodes.map((node) => {
909
- const selected = node.id === selectedNode.id;
910
- const isExecuting = executingNodeId === node.id;
911
- const spec = moduleCatalog.find((m) => m.type === node.type);
912
- const badgeColor = node.family === 'langflow' ? '#3ddc84' : '#38bdf8';
913
- return (_jsxs(YStack, { render: "button", onPress: () => setSelectedNodeId(node.id), width: 215, p: "$2.5", rounded: "$3", borderWidth: selected || isExecuting ? 2 : 1, borderColor: isExecuting ? '#3ddc84' : selected ? '$ink' : '$borderColor', bg: selected ? 'rgba(20,24,36,0.96)' : 'rgba(12,14,22,0.92)', gap: 4, cursor: "pointer", style: {
914
- position: 'absolute',
915
- left: node.x,
916
- top: node.y,
917
- textAlign: 'left',
918
- boxShadow: isExecuting ? '0 0 18px rgba(61,220,132,0.45)' : '0 6px 18px rgba(0,0,0,0.45)',
919
- }, children: [_jsx(XStack, { justify: "space-between", items: "center", children: _jsxs(XStack, { items: "center", gap: "$1.5", flex: 1, minW: 0, children: [_jsx("span", { style: { width: 8, height: 8, borderRadius: 99, background: badgeColor, display: 'inline-block', flexShrink: 0 } }), _jsx(SizableText, { size: "$1", fontWeight: "600", numberOfLines: 1, children: `#${node.id} ${node.title}` })] }) }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, style: { fontFamily: 'ui-monospace, monospace', fontSize: 10 }, children: `${node.family.toUpperCase()} · ${node.type} → ${(spec?.outputPorts ?? ['OUT']).join(',')}` }), _jsx(YStack, { gap: 1, pt: 2, children: Object.entries(node.inputs)
920
- .slice(0, 2)
921
- .map(([k, v]) => (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, style: { fontSize: 11 }, children: `${k}: ${String(v)}` }, k))) }), _jsxs(XStack, { justify: "space-between", items: "center", pt: 4, children: [connectingFromId && connectingFromId !== node.id ? (_jsx(XStack, { render: "span", onPress: (e) => {
922
- e.stopPropagation?.();
923
- toggleWire(connectingFromId, node.id);
924
- }, px: "$2", height: 20, items: "center", rounded: 999, bg: "rgba(61,220,132,0.18)", borderWidth: 1, borderColor: "#3ddc84", children: _jsx(SizableText, { size: "$1", style: { fontSize: 10, color: '#3ddc84' }, children: node.wiresFrom.includes(connectingFromId) ? '⊖ Unlink' : '⊕ Connect Input' }) })) : (_jsx(SizableText, { size: "$1", color: "$soft", style: { fontSize: 10 }, children: node.wiresFrom.length > 0 ? `← [${node.wiresFrom.map((w) => `#${w}`).join(', ')}]` : 'entry' })), _jsx(XStack, { render: "span", onPress: (e) => {
925
- e.stopPropagation?.();
926
- setConnectingFromId(connectingFromId === node.id ? null : node.id);
927
- }, px: "$2", height: 20, items: "center", rounded: 999, borderWidth: 1, borderColor: connectingFromId === node.id ? '$ink' : '$borderColor', children: _jsx(SizableText, { size: "$1", color: "$soft", style: { fontSize: 10 }, children: connectingFromId === node.id ? 'Wiring…' : 'Wire Out →' }) })] })] }, node.id));
928
- })] }) }), _jsxs(YStack, { p: "$2.5", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", bg: "#06070b", gap: 4, children: [_jsx(SizableText, { size: "$1", fontWeight: "600", children: "Step-Through Playground Execution Log" }), playgroundOutput.slice(-4).map((line, i) => (_jsx(SizableText, { size: "$1", color: "$soft", style: { fontFamily: 'ui-monospace, monospace', fontSize: 11 }, children: line }, i)))] })] }), _jsxs(YStack, { width: 300, grow: 1, maxW: 350, gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "var(--pane-fill, var(--sheet-1))", children: [_jsxs(XStack, { justify: "space-between", items: "center", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, children: `#${selectedNode.id} ${selectedNode.title}` }), activeBlueprint.nodes.length > 1 ? (_jsx(XStack, { render: "button", onPress: () => deleteNode(selectedNode.id), px: "$2", height: 24, items: "center", rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", children: _jsx(SizableText, { size: "$1", color: "$soft", children: "Delete" }) })) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", style: { fontFamily: 'ui-monospace, monospace' }, children: `${selectedNode.family.toUpperCase()} · class_type: ${selectedNode.type}` }), _jsx(YStack, { gap: "$2.5", pt: "$1", children: Object.entries(selectedNode.inputs).map(([key, val]) => (_jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: key }), _jsx("input", { "aria-label": `Node input ${key}`, type: typeof val === 'number' ? 'number' : 'text', value: String(val), onChange: (e) => updateNodeInput(key, typeof val === 'number' ? Number(e.currentTarget.value) : e.currentTarget.value), style: {
929
- width: '100%',
930
- height: 34,
931
- borderRadius: 8,
932
- padding: '0 10px',
933
- background: 'rgba(255,255,255,0.04)',
934
- border: '1px solid rgba(255,255,255,0.12)',
935
- color: 'inherit',
936
- font: 'inherit',
937
- } })] }, key))) })] })] })) : null, section === 'code' ? (_jsxs(YStack, { gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "var(--pane-fill, var(--sheet-1))", children: [_jsxs(XStack, { justify: "space-between", items: "center", flexWrap: "wrap", gap: "$2", children: [_jsxs(YStack, { children: [_jsx(SizableText, { size: "$3", fontWeight: "600", 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: "button", onPress: saveNodePythonCode, px: "$3.5", height: 32, items: "center", rounded: 999, bg: "$ink", cursor: "pointer", children: _jsx(SizableText, { size: "$1", color: "$background", fontWeight: "600", children: "Save Python Component" }) })] }), _jsx("textarea", { "aria-label": "Python node class source code", value: pythonDraft, onChange: (e) => setPythonDraft(e.currentTarget.value), rows: 16, style: {
938
- width: '100%',
939
- borderRadius: 10,
940
- padding: 14,
941
- background: '#06070b',
942
- border: '1px solid rgba(255,255,255,0.14)',
943
- color: '#e2e8f0',
944
- fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
945
- fontSize: 13,
946
- lineHeight: 1.5,
947
- } })] })) : null, section === 'publish' ? (_jsxs(YStack, { gap: "$3", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "var(--pane-fill, var(--sheet-1))", children: [_jsx(SizableText, { size: "$3", fontWeight: "600", 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: "$borderColor", bg: "#06070b", maxH: 460, overflow: "scroll", children: _jsx("pre", { style: { margin: 0, fontSize: 12, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', color: '#e2e8f0' }, children: JSON.stringify(compiledComfyPrompt, null, 2) }) })] })) : null] }));
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] }));
948
1213
  }