@foresthubai/workflow-builder 0.4.3 → 0.4.4

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.
Files changed (120) hide show
  1. package/LICENSE +661 -661
  2. package/NOTICE +16 -16
  3. package/README.md +110 -110
  4. package/dist/components/ui/command.d.ts +2 -2
  5. package/dist/components/ui/input.d.ts +1 -1
  6. package/dist/components/ui/resizable.d.ts +1 -1
  7. package/dist/components/ui/textarea.d.ts +1 -1
  8. package/dist/graph/BaseNode.js +10 -10
  9. package/dist/graph/reactFlowRegistry.d.ts.map +1 -1
  10. package/package.json +2 -2
  11. package/src/BuilderLayout.tsx +345 -345
  12. package/src/Canvas.tsx +261 -261
  13. package/src/CanvasEditor.tsx +142 -142
  14. package/src/CanvasTabsToolbar.tsx +176 -176
  15. package/src/RightConfigPanel.tsx +266 -266
  16. package/src/WorkflowBuilder.tsx +408 -408
  17. package/src/cn.ts +6 -6
  18. package/src/components/ui/add-button.tsx +39 -39
  19. package/src/components/ui/alert-dialog.tsx +141 -141
  20. package/src/components/ui/alert.tsx +59 -59
  21. package/src/components/ui/badge.tsx +36 -36
  22. package/src/components/ui/button.tsx +85 -85
  23. package/src/components/ui/card.tsx +79 -79
  24. package/src/components/ui/checkbox.tsx +28 -28
  25. package/src/components/ui/collapsible.tsx +9 -9
  26. package/src/components/ui/command.tsx +153 -153
  27. package/src/components/ui/delete-button.tsx +23 -23
  28. package/src/components/ui/dialog.tsx +125 -125
  29. package/src/components/ui/dropdown-menu.tsx +198 -198
  30. package/src/components/ui/input.tsx +55 -55
  31. package/src/components/ui/label.tsx +24 -24
  32. package/src/components/ui/readonly-banner.tsx +15 -15
  33. package/src/components/ui/resizable.tsx +43 -43
  34. package/src/components/ui/scroll-area.tsx +102 -102
  35. package/src/components/ui/select.tsx +160 -160
  36. package/src/components/ui/separator.tsx +29 -29
  37. package/src/components/ui/switch.tsx +27 -27
  38. package/src/components/ui/textarea.tsx +51 -51
  39. package/src/components/ui/toast.tsx +127 -127
  40. package/src/components/ui/toaster.tsx +33 -33
  41. package/src/components/ui/toggle-group.tsx +59 -59
  42. package/src/components/ui/toggle.tsx +43 -43
  43. package/src/components/ui/tooltip.tsx +32 -32
  44. package/src/dialogs/NodePickerDialog.tsx +84 -84
  45. package/src/dialogs/ValidationDialog.tsx +184 -184
  46. package/src/graph/BaseNode.tsx +557 -557
  47. package/src/graph/CustomEdge.tsx +185 -185
  48. package/src/graph/CustomNode.tsx +16 -16
  49. package/src/graph/FunctionCallNode.tsx +30 -30
  50. package/src/graph/PortHandle.tsx +189 -189
  51. package/src/graph/reactFlowRegistry.ts +26 -26
  52. package/src/hooks/use-toast.ts +125 -125
  53. package/src/hooks/useAvailableVariables.ts +20 -20
  54. package/src/hooks/useCanvasHistory.ts +22 -22
  55. package/src/hooks/useCanvasTabs.ts +168 -168
  56. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
  57. package/src/hooks/useFunctionRegistry.ts +26 -26
  58. package/src/hooks/useFunctions.ts +44 -44
  59. package/src/hooks/useGraph.ts +161 -161
  60. package/src/hooks/useNodeDefinitions.ts +82 -82
  61. package/src/hooks/useParamErrors.ts +26 -26
  62. package/src/hooks/useResolvedTheme.ts +30 -30
  63. package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
  64. package/src/hooks/useSuppressThemeTransition.ts +79 -79
  65. package/src/hooks/useWorkflowSerialization.ts +141 -141
  66. package/src/i18n/index.ts +53 -53
  67. package/src/i18n/locales/de.json +501 -501
  68. package/src/i18n/locales/en.json +557 -557
  69. package/src/index.ts +27 -27
  70. package/src/inputs/ExpressionInput.tsx +297 -297
  71. package/src/inputs/ParameterEditor.tsx +515 -515
  72. package/src/inputs/PortSection.tsx +144 -144
  73. package/src/panels/BuilderSidebar.tsx +301 -301
  74. package/src/panels/ChannelConfigPanel.tsx +49 -49
  75. package/src/panels/ChannelsPanel.tsx +28 -28
  76. package/src/panels/DebugConsolePanel.tsx +73 -73
  77. package/src/panels/DebugContextPanel.tsx +77 -77
  78. package/src/panels/DebugExternalIOPanel.tsx +180 -180
  79. package/src/panels/DiagnosticsPanel.tsx +170 -170
  80. package/src/panels/EdgeConfigPanel.tsx +104 -104
  81. package/src/panels/FunctionConfigPanel.tsx +179 -179
  82. package/src/panels/FunctionListPanel.tsx +45 -45
  83. package/src/panels/MemoryConfigPanel.tsx +55 -55
  84. package/src/panels/MemoryPanel.tsx +40 -40
  85. package/src/panels/ModelConfigPanel.tsx +41 -41
  86. package/src/panels/ModelsPanel.tsx +36 -36
  87. package/src/panels/NodeConfigPanel.tsx +630 -630
  88. package/src/panels/NodeLibrary.tsx +288 -288
  89. package/src/panels/ResourceConfigPanel.tsx +132 -132
  90. package/src/panels/ResourceListPanel.tsx +113 -113
  91. package/src/panels/VariableConfigPanel.tsx +161 -161
  92. package/src/panels/VariablesPanel.tsx +145 -145
  93. package/src/stores/canvasStore.test.ts +44 -44
  94. package/src/stores/canvasStore.ts +245 -245
  95. package/src/stores/debugStore.ts +74 -74
  96. package/src/stores/diagnosticsStore.ts +130 -130
  97. package/src/stores/editorStore.ts +190 -190
  98. package/src/styles/index.css +526 -526
  99. package/src/utils/categoryConstants.ts +26 -26
  100. package/src/utils/channelOperations.ts +86 -86
  101. package/src/utils/connectionRules.ts +137 -137
  102. package/src/utils/functionOperations.ts +179 -179
  103. package/src/utils/graphOperations.ts +550 -550
  104. package/src/utils/history.ts +207 -207
  105. package/src/utils/memoryOperations.ts +57 -57
  106. package/src/utils/migrateFunctionNodes.ts +107 -107
  107. package/src/utils/modelOperations.ts +55 -55
  108. package/src/utils/paramDisplay.ts +71 -71
  109. package/src/utils/resourceHelpers.ts +32 -32
  110. package/src/utils/translation.ts +28 -28
  111. package/src/utils/variableOperations.ts +75 -75
  112. package/tailwind-preset.ts +166 -166
  113. package/dist/lib/utils.d.ts +0 -3
  114. package/dist/lib/utils.d.ts.map +0 -1
  115. package/dist/lib/utils.js +0 -6
  116. package/dist/lib/utils.js.map +0 -1
  117. package/dist/toolbars/CanvasTabsToolbar.d.ts +0 -11
  118. package/dist/toolbars/CanvasTabsToolbar.d.ts.map +0 -1
  119. package/dist/toolbars/CanvasTabsToolbar.js +0 -101
  120. package/dist/toolbars/CanvasTabsToolbar.js.map +0 -1
@@ -1,170 +1,170 @@
1
- import { useState } from "react";
2
- import { useTranslation } from "react-i18next";
3
- import { Badge } from "../components/ui/badge";
4
- import { AlertCircle, AlertTriangle, CheckCircle2, ChevronDown } from "lucide-react";
5
- import { cn } from "../cn";
6
- import { useDiagnosticsStore } from "../stores/diagnosticsStore";
7
- import { getOrCreateCanvasStore } from "../stores/canvasStore";
8
- import { useNodeDefinitions } from "../hooks/useNodeDefinitions";
9
- import type { Diagnostic } from "@foresthubai/workflow-core/diagnostics";
10
-
11
- interface DiagnosticsPanelProps {
12
- canvasId: string;
13
- onSelectNode: (nodeId: string) => void;
14
- onSelectEdge: (edgeId: string) => void;
15
- }
16
-
17
- interface DiagnosticGroup {
18
- entityId: string;
19
- entityType: "node" | "edge";
20
- label: string;
21
- diagnostics: Diagnostic[];
22
- errorCount: number;
23
- warningCount: number;
24
- }
25
-
26
- export const DiagnosticsPanel = ({ canvasId, onSelectNode, onSelectEdge }: DiagnosticsPanelProps) => {
27
- const { t } = useTranslation();
28
- const { getNodeDefinition } = useNodeDefinitions();
29
-
30
- const byNodeId = useDiagnosticsStore((s) => s.byNodeId);
31
- const byEdgeId = useDiagnosticsStore((s) => s.byEdgeId);
32
- const useCanvasStore = getOrCreateCanvasStore(canvasId);
33
- const nodes = useCanvasStore((s) => s.nodes);
34
- const edges = useCanvasStore((s) => s.edges);
35
-
36
- // Build groups
37
- const groups: DiagnosticGroup[] = [];
38
-
39
- // Node groups
40
- for (const [nodeId, diags] of Object.entries(byNodeId)) {
41
- if (diags.length === 0) continue;
42
- const node = nodes.find((n) => n.id === nodeId);
43
- const nodeDef = node ? getNodeDefinition(node.data) : undefined;
44
- const label = (node?.data?.label as string) || nodeDef?.label || nodeId;
45
- groups.push({
46
- entityId: nodeId,
47
- entityType: "node",
48
- label,
49
- diagnostics: diags,
50
- errorCount: diags.filter((d) => d.severity === "error").length,
51
- warningCount: diags.filter((d) => d.severity === "warning").length,
52
- });
53
- }
54
-
55
- // Edge groups
56
- for (const [edgeId, diags] of Object.entries(byEdgeId)) {
57
- if (diags.length === 0) continue;
58
- const edge = edges.find((e) => e.id === edgeId);
59
- const sourceNode = edge ? nodes.find((n) => n.id === edge.source) : undefined;
60
- const targetNode = edge ? nodes.find((n) => n.id === edge.target) : undefined;
61
- const sourceDef = sourceNode ? getNodeDefinition(sourceNode.data) : undefined;
62
- const targetDef = targetNode ? getNodeDefinition(targetNode.data) : undefined;
63
- const sourceLabel = (sourceNode?.data?.label as string) || sourceDef?.label || "?";
64
- const targetLabel = (targetNode?.data?.label as string) || targetDef?.label || "?";
65
- const label = `${sourceLabel} → ${targetLabel}`;
66
- groups.push({
67
- entityId: edgeId,
68
- entityType: "edge",
69
- label,
70
- diagnostics: diags,
71
- errorCount: diags.filter((d) => d.severity === "error").length,
72
- warningCount: diags.filter((d) => d.severity === "warning").length,
73
- });
74
- }
75
-
76
- // IO variable diagnostics are surfaced on the IO sidebar tab itself
77
- // (red ring on cards + count badge on the tab icon) — not duplicated here.
78
-
79
- // Sort: errors first, then warnings; within same severity, nodes before edges;
80
- // within same type, alphabetical by label so the panel order stays stable
81
- // regardless of which nodes ReactFlow currently has mounted (virtualization
82
- // can reshuffle the diagnostics store's insertion order on pan/select).
83
- groups.sort((a, b) => {
84
- const aHasError = a.errorCount > 0 ? 0 : 1;
85
- const bHasError = b.errorCount > 0 ? 0 : 1;
86
- if (aHasError !== bHasError) return aHasError - bHasError;
87
- const aType = a.entityType === "node" ? 0 : 1;
88
- const bType = b.entityType === "node" ? 0 : 1;
89
- if (aType !== bType) return aType - bType;
90
- return a.label.localeCompare(b.label);
91
- });
92
-
93
- if (groups.length === 0) {
94
- return (
95
- <div className="flex flex-col items-center justify-center gap-2 py-12 text-muted-foreground">
96
- <CheckCircle2 className="w-8 h-8 text-success" />
97
- <span className="text-sm">{t("noIssuesFound")}</span>
98
- </div>
99
- );
100
- }
101
-
102
- return (
103
- <div className="flex flex-col gap-1">
104
- {groups.map((group) => (
105
- <DiagnosticGroupItem
106
- key={`${group.entityType}-${group.entityId}`}
107
- group={group}
108
- onSelect={() => (group.entityType === "node" ? onSelectNode(group.entityId) : onSelectEdge(group.entityId))}
109
- />
110
- ))}
111
- </div>
112
- );
113
- };
114
-
115
- function DiagnosticGroupItem({ group, onSelect }: { group: DiagnosticGroup; onSelect: () => void }) {
116
- const [open, setOpen] = useState(true);
117
-
118
- return (
119
- <div>
120
- <button
121
- type="button"
122
- onClick={() => {
123
- setOpen((v) => !v);
124
- onSelect();
125
- }}
126
- className="flex items-center gap-2 w-full px-2 py-1.5 rounded-md hover:bg-muted/50 text-left text-sm"
127
- >
128
- <ChevronDown className={cn("w-3.5 h-3.5 shrink-0 transition-transform", !open && "-rotate-90")} />
129
- <span className="truncate flex-1 font-medium">{group.label}</span>
130
- <div className="flex items-center gap-1">
131
- {group.errorCount > 0 && (
132
- <Badge
133
- variant="outline"
134
- className="text-[10px] px-1.5 py-0 h-4 leading-4 border-destructive/40 text-destructive bg-destructive/10"
135
- >
136
- {group.errorCount}
137
- </Badge>
138
- )}
139
- {group.warningCount > 0 && (
140
- <Badge
141
- variant="outline"
142
- className="text-[10px] px-1.5 py-0 h-4 leading-4 border-warning/40 text-warning bg-warning/10"
143
- >
144
- {group.warningCount}
145
- </Badge>
146
- )}
147
- </div>
148
- </button>
149
- {open && (
150
- <div className="ml-3 border-l border-border/50 pl-2 flex flex-col gap-0.5 pb-1">
151
- {group.diagnostics.map((diag, i) => (
152
- <button
153
- key={i}
154
- type="button"
155
- onClick={onSelect}
156
- className="flex items-start gap-1.5 px-2 py-1 rounded text-xs text-left hover:bg-muted/50 transition-colors w-full"
157
- >
158
- {diag.severity === "error" ? (
159
- <AlertTriangle className="w-3.5 h-3.5 text-destructive shrink-0 mt-0.5" />
160
- ) : (
161
- <AlertCircle className="w-3.5 h-3.5 text-warning shrink-0 mt-0.5" />
162
- )}
163
- <span className="text-muted-foreground">{diag.message}</span>
164
- </button>
165
- ))}
166
- </div>
167
- )}
168
- </div>
169
- );
170
- }
1
+ import { useState } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Badge } from "../components/ui/badge";
4
+ import { AlertCircle, AlertTriangle, CheckCircle2, ChevronDown } from "lucide-react";
5
+ import { cn } from "../cn";
6
+ import { useDiagnosticsStore } from "../stores/diagnosticsStore";
7
+ import { getOrCreateCanvasStore } from "../stores/canvasStore";
8
+ import { useNodeDefinitions } from "../hooks/useNodeDefinitions";
9
+ import type { Diagnostic } from "@foresthubai/workflow-core/diagnostics";
10
+
11
+ interface DiagnosticsPanelProps {
12
+ canvasId: string;
13
+ onSelectNode: (nodeId: string) => void;
14
+ onSelectEdge: (edgeId: string) => void;
15
+ }
16
+
17
+ interface DiagnosticGroup {
18
+ entityId: string;
19
+ entityType: "node" | "edge";
20
+ label: string;
21
+ diagnostics: Diagnostic[];
22
+ errorCount: number;
23
+ warningCount: number;
24
+ }
25
+
26
+ export const DiagnosticsPanel = ({ canvasId, onSelectNode, onSelectEdge }: DiagnosticsPanelProps) => {
27
+ const { t } = useTranslation();
28
+ const { getNodeDefinition } = useNodeDefinitions();
29
+
30
+ const byNodeId = useDiagnosticsStore((s) => s.byNodeId);
31
+ const byEdgeId = useDiagnosticsStore((s) => s.byEdgeId);
32
+ const useCanvasStore = getOrCreateCanvasStore(canvasId);
33
+ const nodes = useCanvasStore((s) => s.nodes);
34
+ const edges = useCanvasStore((s) => s.edges);
35
+
36
+ // Build groups
37
+ const groups: DiagnosticGroup[] = [];
38
+
39
+ // Node groups
40
+ for (const [nodeId, diags] of Object.entries(byNodeId)) {
41
+ if (diags.length === 0) continue;
42
+ const node = nodes.find((n) => n.id === nodeId);
43
+ const nodeDef = node ? getNodeDefinition(node.data) : undefined;
44
+ const label = (node?.data?.label as string) || nodeDef?.label || nodeId;
45
+ groups.push({
46
+ entityId: nodeId,
47
+ entityType: "node",
48
+ label,
49
+ diagnostics: diags,
50
+ errorCount: diags.filter((d) => d.severity === "error").length,
51
+ warningCount: diags.filter((d) => d.severity === "warning").length,
52
+ });
53
+ }
54
+
55
+ // Edge groups
56
+ for (const [edgeId, diags] of Object.entries(byEdgeId)) {
57
+ if (diags.length === 0) continue;
58
+ const edge = edges.find((e) => e.id === edgeId);
59
+ const sourceNode = edge ? nodes.find((n) => n.id === edge.source) : undefined;
60
+ const targetNode = edge ? nodes.find((n) => n.id === edge.target) : undefined;
61
+ const sourceDef = sourceNode ? getNodeDefinition(sourceNode.data) : undefined;
62
+ const targetDef = targetNode ? getNodeDefinition(targetNode.data) : undefined;
63
+ const sourceLabel = (sourceNode?.data?.label as string) || sourceDef?.label || "?";
64
+ const targetLabel = (targetNode?.data?.label as string) || targetDef?.label || "?";
65
+ const label = `${sourceLabel} → ${targetLabel}`;
66
+ groups.push({
67
+ entityId: edgeId,
68
+ entityType: "edge",
69
+ label,
70
+ diagnostics: diags,
71
+ errorCount: diags.filter((d) => d.severity === "error").length,
72
+ warningCount: diags.filter((d) => d.severity === "warning").length,
73
+ });
74
+ }
75
+
76
+ // IO variable diagnostics are surfaced on the IO sidebar tab itself
77
+ // (red ring on cards + count badge on the tab icon) — not duplicated here.
78
+
79
+ // Sort: errors first, then warnings; within same severity, nodes before edges;
80
+ // within same type, alphabetical by label so the panel order stays stable
81
+ // regardless of which nodes ReactFlow currently has mounted (virtualization
82
+ // can reshuffle the diagnostics store's insertion order on pan/select).
83
+ groups.sort((a, b) => {
84
+ const aHasError = a.errorCount > 0 ? 0 : 1;
85
+ const bHasError = b.errorCount > 0 ? 0 : 1;
86
+ if (aHasError !== bHasError) return aHasError - bHasError;
87
+ const aType = a.entityType === "node" ? 0 : 1;
88
+ const bType = b.entityType === "node" ? 0 : 1;
89
+ if (aType !== bType) return aType - bType;
90
+ return a.label.localeCompare(b.label);
91
+ });
92
+
93
+ if (groups.length === 0) {
94
+ return (
95
+ <div className="flex flex-col items-center justify-center gap-2 py-12 text-muted-foreground">
96
+ <CheckCircle2 className="w-8 h-8 text-success" />
97
+ <span className="text-sm">{t("noIssuesFound")}</span>
98
+ </div>
99
+ );
100
+ }
101
+
102
+ return (
103
+ <div className="flex flex-col gap-1">
104
+ {groups.map((group) => (
105
+ <DiagnosticGroupItem
106
+ key={`${group.entityType}-${group.entityId}`}
107
+ group={group}
108
+ onSelect={() => (group.entityType === "node" ? onSelectNode(group.entityId) : onSelectEdge(group.entityId))}
109
+ />
110
+ ))}
111
+ </div>
112
+ );
113
+ };
114
+
115
+ function DiagnosticGroupItem({ group, onSelect }: { group: DiagnosticGroup; onSelect: () => void }) {
116
+ const [open, setOpen] = useState(true);
117
+
118
+ return (
119
+ <div>
120
+ <button
121
+ type="button"
122
+ onClick={() => {
123
+ setOpen((v) => !v);
124
+ onSelect();
125
+ }}
126
+ className="flex items-center gap-2 w-full px-2 py-1.5 rounded-md hover:bg-muted/50 text-left text-sm"
127
+ >
128
+ <ChevronDown className={cn("w-3.5 h-3.5 shrink-0 transition-transform", !open && "-rotate-90")} />
129
+ <span className="truncate flex-1 font-medium">{group.label}</span>
130
+ <div className="flex items-center gap-1">
131
+ {group.errorCount > 0 && (
132
+ <Badge
133
+ variant="outline"
134
+ className="text-[10px] px-1.5 py-0 h-4 leading-4 border-destructive/40 text-destructive bg-destructive/10"
135
+ >
136
+ {group.errorCount}
137
+ </Badge>
138
+ )}
139
+ {group.warningCount > 0 && (
140
+ <Badge
141
+ variant="outline"
142
+ className="text-[10px] px-1.5 py-0 h-4 leading-4 border-warning/40 text-warning bg-warning/10"
143
+ >
144
+ {group.warningCount}
145
+ </Badge>
146
+ )}
147
+ </div>
148
+ </button>
149
+ {open && (
150
+ <div className="ml-3 border-l border-border/50 pl-2 flex flex-col gap-0.5 pb-1">
151
+ {group.diagnostics.map((diag, i) => (
152
+ <button
153
+ key={i}
154
+ type="button"
155
+ onClick={onSelect}
156
+ className="flex items-start gap-1.5 px-2 py-1 rounded text-xs text-left hover:bg-muted/50 transition-colors w-full"
157
+ >
158
+ {diag.severity === "error" ? (
159
+ <AlertTriangle className="w-3.5 h-3.5 text-destructive shrink-0 mt-0.5" />
160
+ ) : (
161
+ <AlertCircle className="w-3.5 h-3.5 text-warning shrink-0 mt-0.5" />
162
+ )}
163
+ <span className="text-muted-foreground">{diag.message}</span>
164
+ </button>
165
+ ))}
166
+ </div>
167
+ )}
168
+ </div>
169
+ );
170
+ }
@@ -1,104 +1,104 @@
1
- import { useCallback } from "react";
2
- import { useTranslation } from "react-i18next";
3
- import { Button } from "../components/ui/button";
4
- import { Separator } from "../components/ui/separator";
5
- import { ChevronRight } from "lucide-react";
6
- import { getEdgeDefinition } from "@foresthubai/workflow-core/edge";
7
- import type { EdgeData, EdgeType } from "@foresthubai/workflow-core/edge";
8
- import ParameterEditor from "../inputs/ParameterEditor";
9
- import { useEditorStore } from "../stores/editorStore";
10
- import { isReadOnly } from "../WorkflowBuilder";
11
- import { useDiagnosticsStore } from "../stores/diagnosticsStore";
12
- import { useParamErrors } from "../hooks/useParamErrors";
13
- import { ReadOnlyBanner } from "../components/ui/readonly-banner";
14
- import { DeleteButton } from "../components/ui/delete-button";
15
- import { getEdgeDescription } from "../utils/translation";
16
-
17
- interface EdgeConfigPanelProps {
18
- canvasId: string;
19
- edgeId: string;
20
- edgeType: EdgeType;
21
- edgeData: EdgeData;
22
- sourceControlEdgeCount: number;
23
- onEdgeUpdate: (edgeId: string, updates: Record<string, unknown>) => void;
24
- onEdgeDelete: (edgeId: string) => void;
25
- onClose: () => void;
26
- }
27
-
28
- export const EdgeConfigPanel = ({
29
- canvasId,
30
- edgeId,
31
- edgeType,
32
- edgeData,
33
- sourceControlEdgeCount,
34
- onEdgeUpdate,
35
- onEdgeDelete,
36
- onClose,
37
- }: EdgeConfigPanelProps) => {
38
- const { t } = useTranslation();
39
- const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
40
- const definition = getEdgeDefinition(edgeType);
41
-
42
- // Read per-parameter error state from diagnostics store
43
- const edgeDiags = useDiagnosticsStore((s) => s.byEdgeId[edgeId]);
44
- const paramErrors = useParamErrors(edgeDiags);
45
-
46
- const handleParamChange = useCallback(
47
- (paramId: string, value: unknown) => {
48
- onEdgeUpdate(edgeId, { [paramId]: value });
49
- },
50
- [edgeId, onEdgeUpdate],
51
- );
52
-
53
- return (
54
- <div className="p-4 space-y-4">
55
- {/* Header - matches NodeConfigPanel layout */}
56
- <div className="flex items-center justify-between">
57
- <div>
58
- <h3 className="font-semibold text-lg">{definition.label}</h3>
59
- <p className="text-sm text-muted-foreground">{getEdgeDescription(t, definition, edgeType)}</p>
60
- </div>
61
- <Button variant="ghost" size="icon" onClick={onClose}>
62
- <ChevronRight className="h-4 w-4" />
63
- </Button>
64
- </div>
65
- {readOnly && <ReadOnlyBanner />}
66
-
67
- <Separator />
68
-
69
- <div className={readOnly ? "pointer-events-none opacity-60" : ""}>
70
- {definition.parameters.length > 0 ? (
71
- definition.parameters.map((param) => {
72
- const isDescriptionOptional =
73
- param.id === "description" &&
74
- sourceControlEdgeCount <= 1 &&
75
- (edgeType === "agentChoice" || edgeType === "agentDelegate");
76
- const effectiveParam = isDescriptionOptional ? { ...param, optional: true } : param;
77
-
78
- return (
79
- <ParameterEditor
80
- key={param.id}
81
- canvasId={canvasId}
82
- parameter={effectiveParam}
83
- value={edgeData[param.id]}
84
- allArguments={edgeData}
85
- onChange={(value) => handleParamChange(param.id, value)}
86
- errors={paramErrors.get(param.id)}
87
- translationPrefix={`edges.${edgeType}`}
88
- />
89
- );
90
- })
91
- ) : (
92
- <p className="text-sm text-muted-foreground">{t("noEdgeParams")}</p>
93
- )}
94
- </div>
95
-
96
- {!readOnly && (
97
- <>
98
- <Separator />
99
- <DeleteButton onClick={() => onEdgeDelete(edgeId)}>{t("deleteEdge")}</DeleteButton>
100
- </>
101
- )}
102
- </div>
103
- );
104
- };
1
+ import { useCallback } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Button } from "../components/ui/button";
4
+ import { Separator } from "../components/ui/separator";
5
+ import { ChevronRight } from "lucide-react";
6
+ import { getEdgeDefinition } from "@foresthubai/workflow-core/edge";
7
+ import type { EdgeData, EdgeType } from "@foresthubai/workflow-core/edge";
8
+ import ParameterEditor from "../inputs/ParameterEditor";
9
+ import { useEditorStore } from "../stores/editorStore";
10
+ import { isReadOnly } from "../WorkflowBuilder";
11
+ import { useDiagnosticsStore } from "../stores/diagnosticsStore";
12
+ import { useParamErrors } from "../hooks/useParamErrors";
13
+ import { ReadOnlyBanner } from "../components/ui/readonly-banner";
14
+ import { DeleteButton } from "../components/ui/delete-button";
15
+ import { getEdgeDescription } from "../utils/translation";
16
+
17
+ interface EdgeConfigPanelProps {
18
+ canvasId: string;
19
+ edgeId: string;
20
+ edgeType: EdgeType;
21
+ edgeData: EdgeData;
22
+ sourceControlEdgeCount: number;
23
+ onEdgeUpdate: (edgeId: string, updates: Record<string, unknown>) => void;
24
+ onEdgeDelete: (edgeId: string) => void;
25
+ onClose: () => void;
26
+ }
27
+
28
+ export const EdgeConfigPanel = ({
29
+ canvasId,
30
+ edgeId,
31
+ edgeType,
32
+ edgeData,
33
+ sourceControlEdgeCount,
34
+ onEdgeUpdate,
35
+ onEdgeDelete,
36
+ onClose,
37
+ }: EdgeConfigPanelProps) => {
38
+ const { t } = useTranslation();
39
+ const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
40
+ const definition = getEdgeDefinition(edgeType);
41
+
42
+ // Read per-parameter error state from diagnostics store
43
+ const edgeDiags = useDiagnosticsStore((s) => s.byEdgeId[edgeId]);
44
+ const paramErrors = useParamErrors(edgeDiags);
45
+
46
+ const handleParamChange = useCallback(
47
+ (paramId: string, value: unknown) => {
48
+ onEdgeUpdate(edgeId, { [paramId]: value });
49
+ },
50
+ [edgeId, onEdgeUpdate],
51
+ );
52
+
53
+ return (
54
+ <div className="p-4 space-y-4">
55
+ {/* Header - matches NodeConfigPanel layout */}
56
+ <div className="flex items-center justify-between">
57
+ <div>
58
+ <h3 className="font-semibold text-lg">{definition.label}</h3>
59
+ <p className="text-sm text-muted-foreground">{getEdgeDescription(t, definition, edgeType)}</p>
60
+ </div>
61
+ <Button variant="ghost" size="icon" onClick={onClose}>
62
+ <ChevronRight className="h-4 w-4" />
63
+ </Button>
64
+ </div>
65
+ {readOnly && <ReadOnlyBanner />}
66
+
67
+ <Separator />
68
+
69
+ <div className={readOnly ? "pointer-events-none opacity-60" : ""}>
70
+ {definition.parameters.length > 0 ? (
71
+ definition.parameters.map((param) => {
72
+ const isDescriptionOptional =
73
+ param.id === "description" &&
74
+ sourceControlEdgeCount <= 1 &&
75
+ (edgeType === "agentChoice" || edgeType === "agentDelegate");
76
+ const effectiveParam = isDescriptionOptional ? { ...param, optional: true } : param;
77
+
78
+ return (
79
+ <ParameterEditor
80
+ key={param.id}
81
+ canvasId={canvasId}
82
+ parameter={effectiveParam}
83
+ value={edgeData[param.id]}
84
+ allArguments={edgeData}
85
+ onChange={(value) => handleParamChange(param.id, value)}
86
+ errors={paramErrors.get(param.id)}
87
+ translationPrefix={`edges.${edgeType}`}
88
+ />
89
+ );
90
+ })
91
+ ) : (
92
+ <p className="text-sm text-muted-foreground">{t("noEdgeParams")}</p>
93
+ )}
94
+ </div>
95
+
96
+ {!readOnly && (
97
+ <>
98
+ <Separator />
99
+ <DeleteButton onClick={() => onEdgeDelete(edgeId)}>{t("deleteEdge")}</DeleteButton>
100
+ </>
101
+ )}
102
+ </div>
103
+ );
104
+ };