@foresthubai/workflow-builder 0.3.0 → 0.4.1

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 (124) hide show
  1. package/LICENSE +661 -661
  2. package/NOTICE +16 -16
  3. package/README.md +110 -93
  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/dist/lib/utils.d.ts +3 -0
  11. package/dist/lib/utils.d.ts.map +1 -0
  12. package/dist/lib/utils.js +6 -0
  13. package/dist/lib/utils.js.map +1 -0
  14. package/dist/stores/editorStore.d.ts +0 -1
  15. package/dist/stores/editorStore.d.ts.map +1 -1
  16. package/dist/stores/editorStore.js +1 -11
  17. package/dist/stores/editorStore.js.map +1 -1
  18. package/dist/toolbars/CanvasTabsToolbar.d.ts +11 -0
  19. package/dist/toolbars/CanvasTabsToolbar.d.ts.map +1 -0
  20. package/dist/toolbars/CanvasTabsToolbar.js +101 -0
  21. package/dist/toolbars/CanvasTabsToolbar.js.map +1 -0
  22. package/package.json +2 -2
  23. package/src/BuilderLayout.tsx +345 -345
  24. package/src/Canvas.tsx +261 -261
  25. package/src/CanvasEditor.tsx +142 -142
  26. package/src/CanvasTabsToolbar.tsx +176 -176
  27. package/src/RightConfigPanel.tsx +266 -266
  28. package/src/WorkflowBuilder.tsx +412 -412
  29. package/src/cn.ts +6 -6
  30. package/src/components/ui/add-button.tsx +39 -39
  31. package/src/components/ui/alert-dialog.tsx +141 -141
  32. package/src/components/ui/alert.tsx +59 -59
  33. package/src/components/ui/badge.tsx +36 -36
  34. package/src/components/ui/button.tsx +85 -85
  35. package/src/components/ui/card.tsx +79 -79
  36. package/src/components/ui/checkbox.tsx +28 -28
  37. package/src/components/ui/collapsible.tsx +9 -9
  38. package/src/components/ui/command.tsx +153 -153
  39. package/src/components/ui/delete-button.tsx +23 -23
  40. package/src/components/ui/dialog.tsx +125 -125
  41. package/src/components/ui/dropdown-menu.tsx +198 -198
  42. package/src/components/ui/input.tsx +55 -55
  43. package/src/components/ui/label.tsx +24 -24
  44. package/src/components/ui/readonly-banner.tsx +15 -15
  45. package/src/components/ui/resizable.tsx +43 -43
  46. package/src/components/ui/scroll-area.tsx +102 -102
  47. package/src/components/ui/select.tsx +160 -160
  48. package/src/components/ui/separator.tsx +29 -29
  49. package/src/components/ui/switch.tsx +27 -27
  50. package/src/components/ui/textarea.tsx +51 -51
  51. package/src/components/ui/toast.tsx +127 -127
  52. package/src/components/ui/toaster.tsx +33 -33
  53. package/src/components/ui/toggle-group.tsx +59 -59
  54. package/src/components/ui/toggle.tsx +43 -43
  55. package/src/components/ui/tooltip.tsx +32 -32
  56. package/src/dialogs/NodePickerDialog.tsx +84 -84
  57. package/src/dialogs/ValidationDialog.tsx +184 -184
  58. package/src/graph/BaseNode.tsx +557 -557
  59. package/src/graph/CustomEdge.tsx +185 -185
  60. package/src/graph/CustomNode.tsx +16 -16
  61. package/src/graph/FunctionCallNode.tsx +30 -30
  62. package/src/graph/PortHandle.tsx +189 -189
  63. package/src/graph/reactFlowRegistry.ts +26 -26
  64. package/src/hooks/use-toast.ts +125 -125
  65. package/src/hooks/useAvailableVariables.ts +20 -20
  66. package/src/hooks/useCanvasHistory.ts +22 -22
  67. package/src/hooks/useCanvasTabs.ts +168 -168
  68. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
  69. package/src/hooks/useFunctionRegistry.ts +26 -26
  70. package/src/hooks/useFunctions.ts +44 -44
  71. package/src/hooks/useGraph.ts +161 -161
  72. package/src/hooks/useNodeDefinitions.ts +82 -82
  73. package/src/hooks/useParamErrors.ts +26 -26
  74. package/src/hooks/useResolvedTheme.ts +30 -30
  75. package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
  76. package/src/hooks/useSuppressThemeTransition.ts +79 -79
  77. package/src/hooks/useWorkflowSerialization.ts +127 -127
  78. package/src/i18n/index.ts +53 -53
  79. package/src/i18n/locales/de.json +501 -501
  80. package/src/i18n/locales/en.json +557 -557
  81. package/src/index.ts +27 -27
  82. package/src/inputs/ExpressionInput.tsx +297 -297
  83. package/src/inputs/ParameterEditor.tsx +515 -515
  84. package/src/inputs/PortSection.tsx +144 -144
  85. package/src/panels/BuilderSidebar.tsx +301 -301
  86. package/src/panels/ChannelConfigPanel.tsx +49 -49
  87. package/src/panels/ChannelsPanel.tsx +28 -28
  88. package/src/panels/DebugConsolePanel.tsx +73 -73
  89. package/src/panels/DebugContextPanel.tsx +77 -77
  90. package/src/panels/DebugExternalIOPanel.tsx +180 -180
  91. package/src/panels/DiagnosticsPanel.tsx +170 -170
  92. package/src/panels/EdgeConfigPanel.tsx +104 -104
  93. package/src/panels/FunctionConfigPanel.tsx +179 -179
  94. package/src/panels/FunctionListPanel.tsx +45 -45
  95. package/src/panels/MemoryConfigPanel.tsx +55 -55
  96. package/src/panels/MemoryPanel.tsx +40 -40
  97. package/src/panels/ModelConfigPanel.tsx +41 -41
  98. package/src/panels/ModelsPanel.tsx +36 -36
  99. package/src/panels/NodeConfigPanel.tsx +630 -630
  100. package/src/panels/NodeLibrary.tsx +288 -288
  101. package/src/panels/ResourceConfigPanel.tsx +132 -132
  102. package/src/panels/ResourceListPanel.tsx +113 -113
  103. package/src/panels/VariableConfigPanel.tsx +161 -161
  104. package/src/panels/VariablesPanel.tsx +145 -145
  105. package/src/stores/canvasStore.test.ts +44 -44
  106. package/src/stores/canvasStore.ts +245 -245
  107. package/src/stores/debugStore.ts +74 -74
  108. package/src/stores/diagnosticsStore.ts +130 -130
  109. package/src/stores/editorStore.ts +190 -202
  110. package/src/styles/index.css +526 -526
  111. package/src/utils/categoryConstants.ts +26 -26
  112. package/src/utils/channelOperations.ts +86 -86
  113. package/src/utils/connectionRules.ts +137 -137
  114. package/src/utils/functionOperations.ts +179 -179
  115. package/src/utils/graphOperations.ts +550 -550
  116. package/src/utils/history.ts +207 -207
  117. package/src/utils/memoryOperations.ts +57 -57
  118. package/src/utils/migrateFunctionNodes.ts +107 -107
  119. package/src/utils/modelOperations.ts +55 -55
  120. package/src/utils/paramDisplay.ts +71 -71
  121. package/src/utils/resourceHelpers.ts +32 -32
  122. package/src/utils/translation.ts +28 -28
  123. package/src/utils/variableOperations.ts +75 -75
  124. package/tailwind-preset.ts +166 -166
@@ -1,49 +1,49 @@
1
- import { useTranslation } from "react-i18next";
2
- import { CHANNEL_DEFINITION, type Channel, type ChannelType } from "@foresthubai/workflow-core/channel";
3
- import { isParameterActive, type Parameter } from "@foresthubai/workflow-core/parameter";
4
- import { useDiagnosticsStore } from "../stores/diagnosticsStore";
5
- import { deleteChannel, updateChannel } from "../utils/channelOperations";
6
- import { ResourceConfigPanel } from "./ResourceConfigPanel";
7
-
8
- interface ChannelConfigPanelProps {
9
- channel: Channel;
10
- onClose: () => void;
11
- }
12
-
13
- export const ChannelConfigPanel = ({ channel, onClose }: ChannelConfigPanelProps) => {
14
- const { t } = useTranslation();
15
-
16
- // `type` is a parameter, so it's exposed through the same `arguments`-shaped
17
- // record ParameterEditor reads — the top-level `type` is mirrored under the
18
- // `type` key so the activation-rule evaluator can see it.
19
- const allArguments: Record<string, unknown> = { ...channel.arguments, type: channel.type };
20
- const parameters = CHANNEL_DEFINITION.parameters.filter((p) => isParameterActive(p, allArguments, false));
21
- const channelDiags = useDiagnosticsStore((s) => s.byChannelId[channel.id]);
22
-
23
- const handleParamChange = (paramId: string, value: unknown) => {
24
- if (paramId === "type") {
25
- updateChannel(channel.id, { type: value as ChannelType });
26
- } else {
27
- updateChannel(channel.id, { arguments: { [paramId]: value } });
28
- }
29
- };
30
-
31
- return (
32
- <ResourceConfigPanel
33
- resetKey={channel.id}
34
- label={channel.label}
35
- labelTitle={t("channelLabel", "Channel label")}
36
- onLabelChange={(label) => updateChannel(channel.id, { label })}
37
- description={t("channelDescription", "Hardware interface declaration")}
38
- parameters={parameters}
39
- getValue={(p: Parameter) => (p.id === "type" ? channel.type : channel.arguments[p.id])}
40
- allArguments={allArguments}
41
- onParamChange={handleParamChange}
42
- diagnostics={channelDiags}
43
- translationPrefix="channels"
44
- deleteLabel={t("deleteChannel", "Delete channel")}
45
- onDelete={() => deleteChannel(channel.id)}
46
- onClose={onClose}
47
- />
48
- );
49
- };
1
+ import { useTranslation } from "react-i18next";
2
+ import { CHANNEL_DEFINITION, type Channel, type ChannelType } from "@foresthubai/workflow-core/channel";
3
+ import { isParameterActive, type Parameter } from "@foresthubai/workflow-core/parameter";
4
+ import { useDiagnosticsStore } from "../stores/diagnosticsStore";
5
+ import { deleteChannel, updateChannel } from "../utils/channelOperations";
6
+ import { ResourceConfigPanel } from "./ResourceConfigPanel";
7
+
8
+ interface ChannelConfigPanelProps {
9
+ channel: Channel;
10
+ onClose: () => void;
11
+ }
12
+
13
+ export const ChannelConfigPanel = ({ channel, onClose }: ChannelConfigPanelProps) => {
14
+ const { t } = useTranslation();
15
+
16
+ // `type` is a parameter, so it's exposed through the same `arguments`-shaped
17
+ // record ParameterEditor reads — the top-level `type` is mirrored under the
18
+ // `type` key so the activation-rule evaluator can see it.
19
+ const allArguments: Record<string, unknown> = { ...channel.arguments, type: channel.type };
20
+ const parameters = CHANNEL_DEFINITION.parameters.filter((p) => isParameterActive(p, allArguments, false));
21
+ const channelDiags = useDiagnosticsStore((s) => s.byChannelId[channel.id]);
22
+
23
+ const handleParamChange = (paramId: string, value: unknown) => {
24
+ if (paramId === "type") {
25
+ updateChannel(channel.id, { type: value as ChannelType });
26
+ } else {
27
+ updateChannel(channel.id, { arguments: { [paramId]: value } });
28
+ }
29
+ };
30
+
31
+ return (
32
+ <ResourceConfigPanel
33
+ resetKey={channel.id}
34
+ label={channel.label}
35
+ labelTitle={t("channelLabel", "Channel label")}
36
+ onLabelChange={(label) => updateChannel(channel.id, { label })}
37
+ description={t("channelDescription", "Hardware interface declaration")}
38
+ parameters={parameters}
39
+ getValue={(p: Parameter) => (p.id === "type" ? channel.type : channel.arguments[p.id])}
40
+ allArguments={allArguments}
41
+ onParamChange={handleParamChange}
42
+ diagnostics={channelDiags}
43
+ translationPrefix="channels"
44
+ deleteLabel={t("deleteChannel", "Delete channel")}
45
+ onDelete={() => deleteChannel(channel.id)}
46
+ onClose={onClose}
47
+ />
48
+ );
49
+ };
@@ -1,28 +1,28 @@
1
- import { useTranslation } from "react-i18next";
2
- import { Cpu, Plus } from "lucide-react";
3
- import { useDiagnosticsStore } from "../stores/diagnosticsStore";
4
- import { useEditorStore } from "../stores/editorStore";
5
- import { addChannel } from "../utils/channelOperations";
6
- import { ResourceListPanel } from "./ResourceListPanel";
7
-
8
- export const ChannelsPanel = () => {
9
- const { t } = useTranslation();
10
- const channels = useEditorStore((s) => s.channels);
11
- const selection = useEditorStore((s) => s.selection);
12
- const selectChannel = useEditorStore((s) => s.selectChannel);
13
- const byChannelId = useDiagnosticsStore((s) => s.byChannelId);
14
-
15
- return (
16
- <ResourceListPanel
17
- items={Object.values(channels)}
18
- selectedId={selection.kind === "channel" ? selection.id : null}
19
- onSelect={selectChannel}
20
- diagnosticsSlot={byChannelId}
21
- badge={(c) => c.type}
22
- emptyIcon={Cpu}
23
- emptyText={t("noChannels")}
24
- emptyHint={t("noChannelsHint")}
25
- addActions={[{ label: t("addChannel"), icon: Plus, onAdd: () => selectChannel(addChannel("GPIOIN").id) }]}
26
- />
27
- );
28
- };
1
+ import { useTranslation } from "react-i18next";
2
+ import { Cpu, Plus } from "lucide-react";
3
+ import { useDiagnosticsStore } from "../stores/diagnosticsStore";
4
+ import { useEditorStore } from "../stores/editorStore";
5
+ import { addChannel } from "../utils/channelOperations";
6
+ import { ResourceListPanel } from "./ResourceListPanel";
7
+
8
+ export const ChannelsPanel = () => {
9
+ const { t } = useTranslation();
10
+ const channels = useEditorStore((s) => s.channels);
11
+ const selection = useEditorStore((s) => s.selection);
12
+ const selectChannel = useEditorStore((s) => s.selectChannel);
13
+ const byChannelId = useDiagnosticsStore((s) => s.byChannelId);
14
+
15
+ return (
16
+ <ResourceListPanel
17
+ items={Object.values(channels)}
18
+ selectedId={selection.kind === "channel" ? selection.id : null}
19
+ onSelect={selectChannel}
20
+ diagnosticsSlot={byChannelId}
21
+ badge={(c) => c.type}
22
+ emptyIcon={Cpu}
23
+ emptyText={t("noChannels")}
24
+ emptyHint={t("noChannelsHint")}
25
+ addActions={[{ label: t("addChannel"), icon: Plus, onAdd: () => selectChannel(addChannel("GPIOIN").id) }]}
26
+ />
27
+ );
28
+ };
@@ -1,73 +1,73 @@
1
- import { Button } from "../components/ui/button";
2
- import { ScrollArea } from "../components/ui/scroll-area";
3
- import { Trash2 } from "lucide-react";
4
- import { useEffect, useRef } from "react";
5
- import { useTranslation } from "react-i18next";
6
- import { useDebugStore, type ConsoleEntry } from "../stores/debugStore";
7
-
8
- export const DebugConsolePanel = () => {
9
- const { t } = useTranslation();
10
- const entries = useDebugStore((s) => s.console);
11
- const clearConsole = useDebugStore((s) => s.clearConsole);
12
- // Ref points at the ScrollArea Viewport (the element with overflow:scroll),
13
- // not the Root — the Root is overflow:hidden and won't scroll.
14
- const scrollRef = useRef<HTMLDivElement>(null);
15
-
16
- // Auto-scroll to bottom on new entries
17
- useEffect(() => {
18
- if (scrollRef.current) {
19
- scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
20
- }
21
- }, [entries]);
22
-
23
- return (
24
- <div className="h-full flex flex-col bg-background border-t border-border">
25
- {/* Header */}
26
- <div className="flex items-center justify-between px-3 py-1.5 border-b border-border/50 shrink-0">
27
- <span className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
28
- {t("debug.console")}
29
- </span>
30
- <Button
31
- variant="ghost"
32
- size="icon"
33
- className="w-6 h-6 text-muted-foreground hover:text-foreground"
34
- onClick={clearConsole}
35
- title={t("debug.clearConsole")}
36
- >
37
- <Trash2 className="w-3.5 h-3.5" />
38
- </Button>
39
- </div>
40
-
41
- {/* Console output. Radix wraps Viewport children in its own div, so
42
- row-spacing utilities (space-y-*) on the Viewport don't reach the
43
- actual rows — apply them on an explicit wrapper instead. */}
44
- <ScrollArea className="flex-1" viewportRef={scrollRef} viewportClassName="p-2">
45
- <div className="font-mono text-xs space-y-0.5">
46
- {entries.length === 0 ? (
47
- <div className="text-muted-foreground text-center py-4">{t("debug.consoleEmpty")}</div>
48
- ) : (
49
- entries.map((entry) => <ConsoleRow key={entry.id} entry={entry} />)
50
- )}
51
- </div>
52
- </ScrollArea>
53
- </div>
54
- );
55
- };
56
-
57
- function ConsoleRow({ entry }: { entry: ConsoleEntry }) {
58
- const time = new Date(entry.timestamp).toLocaleTimeString(undefined, {
59
- hour: "2-digit",
60
- minute: "2-digit",
61
- second: "2-digit",
62
- });
63
-
64
- const colorClass =
65
- entry.type === "error" ? "text-destructive" : entry.type === "system" ? "text-muted-foreground" : "text-foreground";
66
-
67
- return (
68
- <div className={`flex gap-2 leading-relaxed ${colorClass}`}>
69
- <span className="text-muted-foreground/50 shrink-0">{time}</span>
70
- <span className="whitespace-pre-wrap break-all">{entry.text}</span>
71
- </div>
72
- );
73
- }
1
+ import { Button } from "../components/ui/button";
2
+ import { ScrollArea } from "../components/ui/scroll-area";
3
+ import { Trash2 } from "lucide-react";
4
+ import { useEffect, useRef } from "react";
5
+ import { useTranslation } from "react-i18next";
6
+ import { useDebugStore, type ConsoleEntry } from "../stores/debugStore";
7
+
8
+ export const DebugConsolePanel = () => {
9
+ const { t } = useTranslation();
10
+ const entries = useDebugStore((s) => s.console);
11
+ const clearConsole = useDebugStore((s) => s.clearConsole);
12
+ // Ref points at the ScrollArea Viewport (the element with overflow:scroll),
13
+ // not the Root — the Root is overflow:hidden and won't scroll.
14
+ const scrollRef = useRef<HTMLDivElement>(null);
15
+
16
+ // Auto-scroll to bottom on new entries
17
+ useEffect(() => {
18
+ if (scrollRef.current) {
19
+ scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
20
+ }
21
+ }, [entries]);
22
+
23
+ return (
24
+ <div className="h-full flex flex-col bg-background border-t border-border">
25
+ {/* Header */}
26
+ <div className="flex items-center justify-between px-3 py-1.5 border-b border-border/50 shrink-0">
27
+ <span className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
28
+ {t("debug.console")}
29
+ </span>
30
+ <Button
31
+ variant="ghost"
32
+ size="icon"
33
+ className="w-6 h-6 text-muted-foreground hover:text-foreground"
34
+ onClick={clearConsole}
35
+ title={t("debug.clearConsole")}
36
+ >
37
+ <Trash2 className="w-3.5 h-3.5" />
38
+ </Button>
39
+ </div>
40
+
41
+ {/* Console output. Radix wraps Viewport children in its own div, so
42
+ row-spacing utilities (space-y-*) on the Viewport don't reach the
43
+ actual rows — apply them on an explicit wrapper instead. */}
44
+ <ScrollArea className="flex-1" viewportRef={scrollRef} viewportClassName="p-2">
45
+ <div className="font-mono text-xs space-y-0.5">
46
+ {entries.length === 0 ? (
47
+ <div className="text-muted-foreground text-center py-4">{t("debug.consoleEmpty")}</div>
48
+ ) : (
49
+ entries.map((entry) => <ConsoleRow key={entry.id} entry={entry} />)
50
+ )}
51
+ </div>
52
+ </ScrollArea>
53
+ </div>
54
+ );
55
+ };
56
+
57
+ function ConsoleRow({ entry }: { entry: ConsoleEntry }) {
58
+ const time = new Date(entry.timestamp).toLocaleTimeString(undefined, {
59
+ hour: "2-digit",
60
+ minute: "2-digit",
61
+ second: "2-digit",
62
+ });
63
+
64
+ const colorClass =
65
+ entry.type === "error" ? "text-destructive" : entry.type === "system" ? "text-muted-foreground" : "text-foreground";
66
+
67
+ return (
68
+ <div className={`flex gap-2 leading-relaxed ${colorClass}`}>
69
+ <span className="text-muted-foreground/50 shrink-0">{time}</span>
70
+ <span className="whitespace-pre-wrap break-all">{entry.text}</span>
71
+ </div>
72
+ );
73
+ }
@@ -1,77 +1,77 @@
1
- import { Input } from "../components/ui/input";
2
- import { Label } from "../components/ui/label";
3
- import { Switch } from "../components/ui/switch";
4
- import { useTranslation } from "react-i18next";
5
- import { useDebugStore } from "../stores/debugStore";
6
- import { getOrCreateCanvasStore, MAIN_CANVAS_ID } from "../stores/canvasStore";
7
- import type { DataType } from "@foresthubai/workflow-core";
8
-
9
- interface VariableEntry {
10
- key: string;
11
- name: string;
12
- dataType: DataType;
13
- }
14
-
15
- /** Build the list of editable variables from the main canvas store. */
16
- function getVariableEntries(): VariableEntry[] {
17
- const variables = getOrCreateCanvasStore(MAIN_CANVAS_ID).getState().variables;
18
- const entries: VariableEntry[] = [];
19
- for (const v of Object.values(variables)) {
20
- if (v.kind === "declared" || v.kind === "node") {
21
- entries.push({ key: v.name, name: v.name, dataType: v.dataType });
22
- }
23
- }
24
- return entries.sort((a, b) => a.name.localeCompare(b.name));
25
- }
26
-
27
- export const DebugContextPanel = () => {
28
- const { t } = useTranslation();
29
- const context = useDebugStore((s) => s.context);
30
- const updateContextVar = useDebugStore((s) => s.updateContextVar);
31
- const entries = getVariableEntries();
32
-
33
- if (entries.length === 0) {
34
- return <div className="text-sm text-muted-foreground text-center py-4">{t("debug.noVariables")}</div>;
35
- }
36
-
37
- return (
38
- <div className="space-y-3">
39
- {entries.map(({ key, name, dataType }) => {
40
- const value = context[key];
41
- return (
42
- <div key={key} className="space-y-1">
43
- <Label className="text-xs font-medium flex items-center gap-1.5">
44
- <span>{name}</span>
45
- <span className="text-muted-foreground font-mono">({dataType})</span>
46
- </Label>
47
- {dataType === "bool" ? (
48
- <Switch checked={!!value} onCheckedChange={(checked) => updateContextVar(key, checked)} />
49
- ) : dataType === "int" ? (
50
- <Input
51
- type="number"
52
- step={1}
53
- value={(value as number) ?? 0}
54
- onChange={(e) => updateContextVar(key, parseInt(e.target.value) || 0)}
55
- className="h-8 font-mono text-sm"
56
- />
57
- ) : dataType === "float" ? (
58
- <Input
59
- type="number"
60
- step={0.1}
61
- value={(value as number) ?? 0}
62
- onChange={(e) => updateContextVar(key, parseFloat(e.target.value) || 0)}
63
- className="h-8 font-mono text-sm"
64
- />
65
- ) : (
66
- <Input
67
- value={String(value ?? "")}
68
- onChange={(e) => updateContextVar(key, e.target.value)}
69
- className="h-8 font-mono text-sm"
70
- />
71
- )}
72
- </div>
73
- );
74
- })}
75
- </div>
76
- );
77
- };
1
+ import { Input } from "../components/ui/input";
2
+ import { Label } from "../components/ui/label";
3
+ import { Switch } from "../components/ui/switch";
4
+ import { useTranslation } from "react-i18next";
5
+ import { useDebugStore } from "../stores/debugStore";
6
+ import { getOrCreateCanvasStore, MAIN_CANVAS_ID } from "../stores/canvasStore";
7
+ import type { DataType } from "@foresthubai/workflow-core";
8
+
9
+ interface VariableEntry {
10
+ key: string;
11
+ name: string;
12
+ dataType: DataType;
13
+ }
14
+
15
+ /** Build the list of editable variables from the main canvas store. */
16
+ function getVariableEntries(): VariableEntry[] {
17
+ const variables = getOrCreateCanvasStore(MAIN_CANVAS_ID).getState().variables;
18
+ const entries: VariableEntry[] = [];
19
+ for (const v of Object.values(variables)) {
20
+ if (v.kind === "declared" || v.kind === "node") {
21
+ entries.push({ key: v.name, name: v.name, dataType: v.dataType });
22
+ }
23
+ }
24
+ return entries.sort((a, b) => a.name.localeCompare(b.name));
25
+ }
26
+
27
+ export const DebugContextPanel = () => {
28
+ const { t } = useTranslation();
29
+ const context = useDebugStore((s) => s.context);
30
+ const updateContextVar = useDebugStore((s) => s.updateContextVar);
31
+ const entries = getVariableEntries();
32
+
33
+ if (entries.length === 0) {
34
+ return <div className="text-sm text-muted-foreground text-center py-4">{t("debug.noVariables")}</div>;
35
+ }
36
+
37
+ return (
38
+ <div className="space-y-3">
39
+ {entries.map(({ key, name, dataType }) => {
40
+ const value = context[key];
41
+ return (
42
+ <div key={key} className="space-y-1">
43
+ <Label className="text-xs font-medium flex items-center gap-1.5">
44
+ <span>{name}</span>
45
+ <span className="text-muted-foreground font-mono">({dataType})</span>
46
+ </Label>
47
+ {dataType === "bool" ? (
48
+ <Switch checked={!!value} onCheckedChange={(checked) => updateContextVar(key, checked)} />
49
+ ) : dataType === "int" ? (
50
+ <Input
51
+ type="number"
52
+ step={1}
53
+ value={(value as number) ?? 0}
54
+ onChange={(e) => updateContextVar(key, parseInt(e.target.value) || 0)}
55
+ className="h-8 font-mono text-sm"
56
+ />
57
+ ) : dataType === "float" ? (
58
+ <Input
59
+ type="number"
60
+ step={0.1}
61
+ value={(value as number) ?? 0}
62
+ onChange={(e) => updateContextVar(key, parseFloat(e.target.value) || 0)}
63
+ className="h-8 font-mono text-sm"
64
+ />
65
+ ) : (
66
+ <Input
67
+ value={String(value ?? "")}
68
+ onChange={(e) => updateContextVar(key, e.target.value)}
69
+ className="h-8 font-mono text-sm"
70
+ />
71
+ )}
72
+ </div>
73
+ );
74
+ })}
75
+ </div>
76
+ );
77
+ };