@foresthubai/workflow-builder 0.3.0 → 0.4.0

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 -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/toolbars/CanvasTabsToolbar.d.ts +11 -0
  15. package/dist/toolbars/CanvasTabsToolbar.d.ts.map +1 -0
  16. package/dist/toolbars/CanvasTabsToolbar.js +101 -0
  17. package/dist/toolbars/CanvasTabsToolbar.js.map +1 -0
  18. package/package.json +2 -2
  19. package/src/BuilderLayout.tsx +345 -345
  20. package/src/Canvas.tsx +261 -261
  21. package/src/CanvasEditor.tsx +142 -142
  22. package/src/CanvasTabsToolbar.tsx +176 -176
  23. package/src/RightConfigPanel.tsx +266 -266
  24. package/src/WorkflowBuilder.tsx +412 -412
  25. package/src/cn.ts +6 -6
  26. package/src/components/ui/add-button.tsx +39 -39
  27. package/src/components/ui/alert-dialog.tsx +141 -141
  28. package/src/components/ui/alert.tsx +59 -59
  29. package/src/components/ui/badge.tsx +36 -36
  30. package/src/components/ui/button.tsx +85 -85
  31. package/src/components/ui/card.tsx +79 -79
  32. package/src/components/ui/checkbox.tsx +28 -28
  33. package/src/components/ui/collapsible.tsx +9 -9
  34. package/src/components/ui/command.tsx +153 -153
  35. package/src/components/ui/delete-button.tsx +23 -23
  36. package/src/components/ui/dialog.tsx +125 -125
  37. package/src/components/ui/dropdown-menu.tsx +198 -198
  38. package/src/components/ui/input.tsx +55 -55
  39. package/src/components/ui/label.tsx +24 -24
  40. package/src/components/ui/readonly-banner.tsx +15 -15
  41. package/src/components/ui/resizable.tsx +43 -43
  42. package/src/components/ui/scroll-area.tsx +102 -102
  43. package/src/components/ui/select.tsx +160 -160
  44. package/src/components/ui/separator.tsx +29 -29
  45. package/src/components/ui/switch.tsx +27 -27
  46. package/src/components/ui/textarea.tsx +51 -51
  47. package/src/components/ui/toast.tsx +127 -127
  48. package/src/components/ui/toaster.tsx +33 -33
  49. package/src/components/ui/toggle-group.tsx +59 -59
  50. package/src/components/ui/toggle.tsx +43 -43
  51. package/src/components/ui/tooltip.tsx +32 -32
  52. package/src/dialogs/NodePickerDialog.tsx +84 -84
  53. package/src/dialogs/ValidationDialog.tsx +184 -184
  54. package/src/graph/BaseNode.tsx +557 -557
  55. package/src/graph/CustomEdge.tsx +185 -185
  56. package/src/graph/CustomNode.tsx +16 -16
  57. package/src/graph/FunctionCallNode.tsx +30 -30
  58. package/src/graph/PortHandle.tsx +189 -189
  59. package/src/graph/reactFlowRegistry.ts +26 -26
  60. package/src/hooks/use-toast.ts +125 -125
  61. package/src/hooks/useAvailableVariables.ts +20 -20
  62. package/src/hooks/useCanvasHistory.ts +22 -22
  63. package/src/hooks/useCanvasTabs.ts +168 -168
  64. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
  65. package/src/hooks/useFunctionRegistry.ts +26 -26
  66. package/src/hooks/useFunctions.ts +44 -44
  67. package/src/hooks/useGraph.ts +161 -161
  68. package/src/hooks/useNodeDefinitions.ts +82 -82
  69. package/src/hooks/useParamErrors.ts +26 -26
  70. package/src/hooks/useResolvedTheme.ts +30 -30
  71. package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
  72. package/src/hooks/useSuppressThemeTransition.ts +79 -79
  73. package/src/hooks/useWorkflowSerialization.ts +127 -127
  74. package/src/i18n/index.ts +53 -53
  75. package/src/i18n/locales/de.json +501 -501
  76. package/src/i18n/locales/en.json +557 -557
  77. package/src/index.ts +27 -27
  78. package/src/inputs/ExpressionInput.tsx +297 -297
  79. package/src/inputs/ParameterEditor.tsx +515 -515
  80. package/src/inputs/PortSection.tsx +144 -144
  81. package/src/panels/BuilderSidebar.tsx +301 -301
  82. package/src/panels/ChannelConfigPanel.tsx +49 -49
  83. package/src/panels/ChannelsPanel.tsx +28 -28
  84. package/src/panels/DebugConsolePanel.tsx +73 -73
  85. package/src/panels/DebugContextPanel.tsx +77 -77
  86. package/src/panels/DebugExternalIOPanel.tsx +180 -180
  87. package/src/panels/DiagnosticsPanel.tsx +170 -170
  88. package/src/panels/EdgeConfigPanel.tsx +104 -104
  89. package/src/panels/FunctionConfigPanel.tsx +179 -179
  90. package/src/panels/FunctionListPanel.tsx +45 -45
  91. package/src/panels/MemoryConfigPanel.tsx +55 -55
  92. package/src/panels/MemoryPanel.tsx +40 -40
  93. package/src/panels/ModelConfigPanel.tsx +41 -41
  94. package/src/panels/ModelsPanel.tsx +36 -36
  95. package/src/panels/NodeConfigPanel.tsx +630 -630
  96. package/src/panels/NodeLibrary.tsx +288 -288
  97. package/src/panels/ResourceConfigPanel.tsx +132 -132
  98. package/src/panels/ResourceListPanel.tsx +113 -113
  99. package/src/panels/VariableConfigPanel.tsx +161 -161
  100. package/src/panels/VariablesPanel.tsx +145 -145
  101. package/src/stores/canvasStore.test.ts +44 -44
  102. package/src/stores/canvasStore.ts +245 -245
  103. package/src/stores/debugStore.ts +74 -74
  104. package/src/stores/diagnosticsStore.ts +130 -130
  105. package/src/stores/editorStore.ts +202 -202
  106. package/src/styles/index.css +526 -526
  107. package/src/utils/categoryConstants.ts +26 -26
  108. package/src/utils/channelOperations.ts +86 -86
  109. package/src/utils/connectionRules.ts +137 -137
  110. package/src/utils/functionOperations.ts +179 -179
  111. package/src/utils/graphOperations.ts +550 -550
  112. package/src/utils/history.ts +207 -207
  113. package/src/utils/memoryOperations.ts +57 -57
  114. package/src/utils/migrateFunctionNodes.ts +107 -107
  115. package/src/utils/modelOperations.ts +55 -55
  116. package/src/utils/paramDisplay.ts +71 -71
  117. package/src/utils/resourceHelpers.ts +32 -32
  118. package/src/utils/translation.ts +28 -28
  119. package/src/utils/variableOperations.ts +75 -75
  120. package/tailwind-preset.ts +166 -166
@@ -1,107 +1,107 @@
1
- import type { OutputBinding, FunctionCallNode } from "@foresthubai/workflow-core/node";
2
- import type { Expression } from "@foresthubai/workflow-core";
3
- import { toast } from "../hooks/use-toast";
4
- import i18n from "../i18n";
5
- import { getAllCanvasStores } from "../stores/canvasStore";
6
- import { useEditorStore } from "../stores/editorStore";
7
- import { toFunctionInfo, type FunctionInfo } from "@foresthubai/workflow-core/function";
8
- import { paramKey } from "@foresthubai/workflow-core/variable";
9
- import { updateNodeInStore } from "./graphOperations";
10
-
11
- // ============================================================================
12
- // Single-Node Migration — builds the update payload for updateNodeInStore
13
- // ============================================================================
14
-
15
- function buildMigrationUpdate(
16
- node: FunctionCallNode,
17
- latest: FunctionInfo,
18
- ): { arguments: Record<string, unknown>; functionInfo: FunctionInfo } {
19
- const oldArgs = node.arguments;
20
- const newArgs: Record<string, Expression | OutputBinding> = {};
21
-
22
- // Preserve existing input expressions where uid matches; default empty otherwise.
23
- // Always update dataType to match the latest function definition.
24
- for (const arg of latest.arguments) {
25
- const key = paramKey(arg);
26
- const existing = oldArgs[key] as Expression | undefined;
27
- newArgs[key] = existing ? { ...existing, dataType: arg.dataType } : { expression: "", references: [], dataType: arg.dataType };
28
- }
29
-
30
- // Preserve existing output bindings where uid matches; default emit for new returns.
31
- for (const ret of latest.returns) {
32
- const key = paramKey(ret);
33
- const existing = oldArgs[key] as OutputBinding | undefined;
34
- newArgs[key] = existing ?? { active: true, mode: "emit", name: ret.name };
35
- }
36
-
37
- return {
38
- functionInfo: { ...latest },
39
- arguments: newArgs,
40
- };
41
- }
42
-
43
- // ============================================================================
44
- // All-Canvas Migration
45
- // ============================================================================
46
-
47
- /**
48
- * Iterate all canvas stores and migrate any stale FunctionCallNodes
49
- * to match the latest function definitions.
50
- *
51
- * Does NOT create undo history entries — migration is automatic and transparent.
52
- * Uses updateNodeInStore for proper store reactivity.
53
- */
54
- export function migrateFunctionCallNodes(): void {
55
- const allStores = getAllCanvasStores();
56
-
57
- // Latest call-site signatures come from the project-scoped declarations, projected
58
- // to the flat snapshot form a FunctionCall stores (expressions dropped).
59
- const latestFunctions: Record<string, FunctionInfo> = {};
60
- for (const [id, def] of Object.entries(useEditorStore.getState().functions)) {
61
- latestFunctions[id] = toFunctionInfo(def);
62
- }
63
-
64
- // Iterate all canvases and migrate stale FunctionCallNodes
65
- let totalMigrated = 0;
66
-
67
- for (const [, store] of Object.entries(allStores)) {
68
- const nodes = store.getState().nodes;
69
-
70
- for (const node of nodes) {
71
- if (node.data.type !== "FunctionCall") continue;
72
-
73
- const fnNode = node.data as FunctionCallNode;
74
- const latest = latestFunctions[fnNode.functionInfo.id];
75
- if (!latest) continue;
76
-
77
- // Check if migration is needed (version or name change)
78
- if (fnNode.functionInfo.version === latest.version && fnNode.functionInfo.name === latest.name) {
79
- continue;
80
- }
81
-
82
- updateNodeInStore(store, node.id, buildMigrationUpdate(fnNode, latest));
83
- totalMigrated++;
84
- }
85
- }
86
-
87
- if (totalMigrated > 0) {
88
- toast({
89
- title: i18n.t("functionCallNodesMigrated"),
90
- description: i18n.t("functionCallNodesMigratedDesc", { count: totalMigrated }),
91
- });
92
- }
93
- }
94
-
95
- // ============================================================================
96
- // Module-Level Subscription
97
- // ============================================================================
98
-
99
- // Automatically migrate FunctionCallNodes whenever a function declaration changes.
100
- // Declarations are non-undo-tracked editorStore edits, so this is a forward-only
101
- // reconcile — no undo can revert a definition out from under its call sites.
102
- let prevFunctions = useEditorStore.getState().functions;
103
- useEditorStore.subscribe((state) => {
104
- if (state.functions === prevFunctions) return;
105
- prevFunctions = state.functions;
106
- migrateFunctionCallNodes();
107
- });
1
+ import type { OutputBinding, FunctionCallNode } from "@foresthubai/workflow-core/node";
2
+ import type { Expression } from "@foresthubai/workflow-core";
3
+ import { toast } from "../hooks/use-toast";
4
+ import i18n from "../i18n";
5
+ import { getAllCanvasStores } from "../stores/canvasStore";
6
+ import { useEditorStore } from "../stores/editorStore";
7
+ import { toFunctionInfo, type FunctionInfo } from "@foresthubai/workflow-core/function";
8
+ import { paramKey } from "@foresthubai/workflow-core/variable";
9
+ import { updateNodeInStore } from "./graphOperations";
10
+
11
+ // ============================================================================
12
+ // Single-Node Migration — builds the update payload for updateNodeInStore
13
+ // ============================================================================
14
+
15
+ function buildMigrationUpdate(
16
+ node: FunctionCallNode,
17
+ latest: FunctionInfo,
18
+ ): { arguments: Record<string, unknown>; functionInfo: FunctionInfo } {
19
+ const oldArgs = node.arguments;
20
+ const newArgs: Record<string, Expression | OutputBinding> = {};
21
+
22
+ // Preserve existing input expressions where uid matches; default empty otherwise.
23
+ // Always update dataType to match the latest function definition.
24
+ for (const arg of latest.arguments) {
25
+ const key = paramKey(arg);
26
+ const existing = oldArgs[key] as Expression | undefined;
27
+ newArgs[key] = existing ? { ...existing, dataType: arg.dataType } : { expression: "", references: [], dataType: arg.dataType };
28
+ }
29
+
30
+ // Preserve existing output bindings where uid matches; default emit for new returns.
31
+ for (const ret of latest.returns) {
32
+ const key = paramKey(ret);
33
+ const existing = oldArgs[key] as OutputBinding | undefined;
34
+ newArgs[key] = existing ?? { active: true, mode: "emit", name: ret.name };
35
+ }
36
+
37
+ return {
38
+ functionInfo: { ...latest },
39
+ arguments: newArgs,
40
+ };
41
+ }
42
+
43
+ // ============================================================================
44
+ // All-Canvas Migration
45
+ // ============================================================================
46
+
47
+ /**
48
+ * Iterate all canvas stores and migrate any stale FunctionCallNodes
49
+ * to match the latest function definitions.
50
+ *
51
+ * Does NOT create undo history entries — migration is automatic and transparent.
52
+ * Uses updateNodeInStore for proper store reactivity.
53
+ */
54
+ export function migrateFunctionCallNodes(): void {
55
+ const allStores = getAllCanvasStores();
56
+
57
+ // Latest call-site signatures come from the project-scoped declarations, projected
58
+ // to the flat snapshot form a FunctionCall stores (expressions dropped).
59
+ const latestFunctions: Record<string, FunctionInfo> = {};
60
+ for (const [id, def] of Object.entries(useEditorStore.getState().functions)) {
61
+ latestFunctions[id] = toFunctionInfo(def);
62
+ }
63
+
64
+ // Iterate all canvases and migrate stale FunctionCallNodes
65
+ let totalMigrated = 0;
66
+
67
+ for (const [, store] of Object.entries(allStores)) {
68
+ const nodes = store.getState().nodes;
69
+
70
+ for (const node of nodes) {
71
+ if (node.data.type !== "FunctionCall") continue;
72
+
73
+ const fnNode = node.data as FunctionCallNode;
74
+ const latest = latestFunctions[fnNode.functionInfo.id];
75
+ if (!latest) continue;
76
+
77
+ // Check if migration is needed (version or name change)
78
+ if (fnNode.functionInfo.version === latest.version && fnNode.functionInfo.name === latest.name) {
79
+ continue;
80
+ }
81
+
82
+ updateNodeInStore(store, node.id, buildMigrationUpdate(fnNode, latest));
83
+ totalMigrated++;
84
+ }
85
+ }
86
+
87
+ if (totalMigrated > 0) {
88
+ toast({
89
+ title: i18n.t("functionCallNodesMigrated"),
90
+ description: i18n.t("functionCallNodesMigratedDesc", { count: totalMigrated }),
91
+ });
92
+ }
93
+ }
94
+
95
+ // ============================================================================
96
+ // Module-Level Subscription
97
+ // ============================================================================
98
+
99
+ // Automatically migrate FunctionCallNodes whenever a function declaration changes.
100
+ // Declarations are non-undo-tracked editorStore edits, so this is a forward-only
101
+ // reconcile — no undo can revert a definition out from under its call sites.
102
+ let prevFunctions = useEditorStore.getState().functions;
103
+ useEditorStore.subscribe((state) => {
104
+ if (state.functions === prevFunctions) return;
105
+ prevFunctions = state.functions;
106
+ migrateFunctionCallNodes();
107
+ });
@@ -1,55 +1,55 @@
1
- import { ModelRegistry, type ModelType, type Model } from "@foresthubai/workflow-core/model";
2
- import { useEditorStore } from "../stores/editorStore";
3
- import { generateId } from "@foresthubai/workflow-core/id";
4
- import { seedDefaultArguments, uniqueName } from "./resourceHelpers";
5
-
6
- /** Default label prefix per model type. */
7
- const LABEL_PREFIX: Record<ModelType, string> = {
8
- LLMModel: "model",
9
- };
10
-
11
- /** Create a new declared (custom) model of the given type. Returns the new instance. */
12
- export function addModel(type: ModelType): Model {
13
- const id = generateId();
14
- const existing = Object.values(useEditorStore.getState().models).map((m) => m.label);
15
- const instance: Model = {
16
- id,
17
- label: uniqueName(LABEL_PREFIX[type], existing),
18
- type,
19
- arguments: seedDefaultArguments(ModelRegistry.getByType(type)?.parameters ?? []),
20
- };
21
- useEditorStore.getState().setModels((models) => ({ ...models, [id]: instance }));
22
- return instance;
23
- }
24
-
25
- /**
26
- * Apply a partial patch to a declared model. Top-level `label` and the
27
- * `arguments` record merge separately. `type` is fixed at creation.
28
- */
29
- export function updateModel(id: string, patch: { label?: string; arguments?: Record<string, unknown> }): void {
30
- const key = id;
31
- useEditorStore.getState().setModels((models) => {
32
- const existing = models[key];
33
- if (!existing) return models;
34
- return {
35
- ...models,
36
- [key]: {
37
- ...existing,
38
- ...(patch.label !== undefined ? { label: patch.label } : {}),
39
- ...(patch.arguments ? { arguments: { ...existing.arguments, ...patch.arguments } } : {}),
40
- },
41
- };
42
- });
43
- }
44
-
45
- export function deleteModel(id: string): void {
46
- const key = id;
47
- useEditorStore.getState().setModels((models) => {
48
- const { [key]: _drop, ...rest } = models;
49
- return rest;
50
- });
51
- const sel = useEditorStore.getState().selection;
52
- if (sel.kind === "model" && sel.id === id) {
53
- useEditorStore.getState().clearSelection();
54
- }
55
- }
1
+ import { ModelRegistry, type ModelType, type Model } from "@foresthubai/workflow-core/model";
2
+ import { useEditorStore } from "../stores/editorStore";
3
+ import { generateId } from "@foresthubai/workflow-core/id";
4
+ import { seedDefaultArguments, uniqueName } from "./resourceHelpers";
5
+
6
+ /** Default label prefix per model type. */
7
+ const LABEL_PREFIX: Record<ModelType, string> = {
8
+ LLMModel: "model",
9
+ };
10
+
11
+ /** Create a new declared (custom) model of the given type. Returns the new instance. */
12
+ export function addModel(type: ModelType): Model {
13
+ const id = generateId();
14
+ const existing = Object.values(useEditorStore.getState().models).map((m) => m.label);
15
+ const instance: Model = {
16
+ id,
17
+ label: uniqueName(LABEL_PREFIX[type], existing),
18
+ type,
19
+ arguments: seedDefaultArguments(ModelRegistry.getByType(type)?.parameters ?? []),
20
+ };
21
+ useEditorStore.getState().setModels((models) => ({ ...models, [id]: instance }));
22
+ return instance;
23
+ }
24
+
25
+ /**
26
+ * Apply a partial patch to a declared model. Top-level `label` and the
27
+ * `arguments` record merge separately. `type` is fixed at creation.
28
+ */
29
+ export function updateModel(id: string, patch: { label?: string; arguments?: Record<string, unknown> }): void {
30
+ const key = id;
31
+ useEditorStore.getState().setModels((models) => {
32
+ const existing = models[key];
33
+ if (!existing) return models;
34
+ return {
35
+ ...models,
36
+ [key]: {
37
+ ...existing,
38
+ ...(patch.label !== undefined ? { label: patch.label } : {}),
39
+ ...(patch.arguments ? { arguments: { ...existing.arguments, ...patch.arguments } } : {}),
40
+ },
41
+ };
42
+ });
43
+ }
44
+
45
+ export function deleteModel(id: string): void {
46
+ const key = id;
47
+ useEditorStore.getState().setModels((models) => {
48
+ const { [key]: _drop, ...rest } = models;
49
+ return rest;
50
+ });
51
+ const sel = useEditorStore.getState().selection;
52
+ if (sel.kind === "model" && sel.id === id) {
53
+ useEditorStore.getState().clearSelection();
54
+ }
55
+ }
@@ -1,71 +1,71 @@
1
- // Presentation-only formatters for inline node display. These render domain
2
- // values to human-readable text; they live in the builder (not headless
3
- // workflow-core) because formatting for display is an editor concern.
4
- import type { Parameter } from "@foresthubai/workflow-core/parameter";
5
- import type { Reference } from "@foresthubai/workflow-core";
6
- import { refToLookupKey, type Variable } from "@foresthubai/workflow-core/variable";
7
- import type { ResolvedExpr } from "@foresthubai/workflow-core/expression";
8
-
9
- export interface ParamDisplayResult {
10
- text: string;
11
- isInvalid?: boolean;
12
- }
13
-
14
- /** Format a non-expression parameter value for inline display on the node. */
15
- export function formatParamDisplay(
16
- param: Parameter,
17
- value: unknown,
18
- variables: Record<string, Variable>,
19
- channelLabels?: Record<string, string>,
20
- memoryLabels?: Record<string, string>,
21
- modelLabels?: Record<string, string>,
22
- ): ParamDisplayResult {
23
- switch (param.type) {
24
- case "variableSelect": {
25
- const ref = value as Reference | undefined;
26
- if (!ref?.varId) return { text: "" };
27
- const v = variables[refToLookupKey(ref)];
28
- return v ? { text: v.name } : { text: "unknown", isInvalid: true };
29
- }
30
- case "bool":
31
- return { text: (value as boolean) ? "true" : "false" };
32
- case "weekdays": {
33
- const days = value as string[] | undefined;
34
- return { text: !days?.length ? "every day" : days.join(", ") };
35
- }
36
- case "selection": {
37
- const option = param.options.find((o) => o.value === value);
38
- return { text: option?.label ?? String(value ?? "") };
39
- }
40
- case "memorySelect": {
41
- const memoryId = value as string | undefined;
42
- if (!memoryId) return { text: "" };
43
- return memoryLabels?.[memoryId] ? { text: memoryLabels[memoryId] } : { text: "unknown", isInvalid: true };
44
- }
45
- case "channelSelect": {
46
- const channelId = value as string | undefined;
47
- if (!channelId) return { text: "" };
48
- return channelLabels?.[channelId] ? { text: channelLabels[channelId] } : { text: "unknown", isInvalid: true };
49
- }
50
- case "modelSelect": {
51
- // A ModelID is human-meaningful (e.g. "claude-opus-4-7"); show the catalog/
52
- // custom label when known, otherwise the id itself. Staleness is surfaced
53
- // by diagnostics, not inline, since the catalog isn't available headlessly.
54
- const modelId = value as string | undefined;
55
- if (!modelId) return { text: "" };
56
- return { text: modelLabels?.[modelId] ?? modelId };
57
- }
58
- default:
59
- return { text: String(value ?? "") };
60
- }
61
- }
62
-
63
- /** Format an expression for display by replacing variable-reference placeholders with their names. */
64
- export function displayValue(expr: ResolvedExpr): string {
65
- let result = expr.expression;
66
- // Replace each variable reference placeholder with its name
67
- expr.variables.forEach((variable) => {
68
- result = result.replace(/\$\{\}/, variable?.name || "unknown");
69
- });
70
- return result;
71
- }
1
+ // Presentation-only formatters for inline node display. These render domain
2
+ // values to human-readable text; they live in the builder (not headless
3
+ // workflow-core) because formatting for display is an editor concern.
4
+ import type { Parameter } from "@foresthubai/workflow-core/parameter";
5
+ import type { Reference } from "@foresthubai/workflow-core";
6
+ import { refToLookupKey, type Variable } from "@foresthubai/workflow-core/variable";
7
+ import type { ResolvedExpr } from "@foresthubai/workflow-core/expression";
8
+
9
+ export interface ParamDisplayResult {
10
+ text: string;
11
+ isInvalid?: boolean;
12
+ }
13
+
14
+ /** Format a non-expression parameter value for inline display on the node. */
15
+ export function formatParamDisplay(
16
+ param: Parameter,
17
+ value: unknown,
18
+ variables: Record<string, Variable>,
19
+ channelLabels?: Record<string, string>,
20
+ memoryLabels?: Record<string, string>,
21
+ modelLabels?: Record<string, string>,
22
+ ): ParamDisplayResult {
23
+ switch (param.type) {
24
+ case "variableSelect": {
25
+ const ref = value as Reference | undefined;
26
+ if (!ref?.varId) return { text: "" };
27
+ const v = variables[refToLookupKey(ref)];
28
+ return v ? { text: v.name } : { text: "unknown", isInvalid: true };
29
+ }
30
+ case "bool":
31
+ return { text: (value as boolean) ? "true" : "false" };
32
+ case "weekdays": {
33
+ const days = value as string[] | undefined;
34
+ return { text: !days?.length ? "every day" : days.join(", ") };
35
+ }
36
+ case "selection": {
37
+ const option = param.options.find((o) => o.value === value);
38
+ return { text: option?.label ?? String(value ?? "") };
39
+ }
40
+ case "memorySelect": {
41
+ const memoryId = value as string | undefined;
42
+ if (!memoryId) return { text: "" };
43
+ return memoryLabels?.[memoryId] ? { text: memoryLabels[memoryId] } : { text: "unknown", isInvalid: true };
44
+ }
45
+ case "channelSelect": {
46
+ const channelId = value as string | undefined;
47
+ if (!channelId) return { text: "" };
48
+ return channelLabels?.[channelId] ? { text: channelLabels[channelId] } : { text: "unknown", isInvalid: true };
49
+ }
50
+ case "modelSelect": {
51
+ // A ModelID is human-meaningful (e.g. "claude-opus-4-7"); show the catalog/
52
+ // custom label when known, otherwise the id itself. Staleness is surfaced
53
+ // by diagnostics, not inline, since the catalog isn't available headlessly.
54
+ const modelId = value as string | undefined;
55
+ if (!modelId) return { text: "" };
56
+ return { text: modelLabels?.[modelId] ?? modelId };
57
+ }
58
+ default:
59
+ return { text: String(value ?? "") };
60
+ }
61
+ }
62
+
63
+ /** Format an expression for display by replacing variable-reference placeholders with their names. */
64
+ export function displayValue(expr: ResolvedExpr): string {
65
+ let result = expr.expression;
66
+ // Replace each variable reference placeholder with its name
67
+ expr.variables.forEach((variable) => {
68
+ result = result.replace(/\$\{\}/, variable?.name || "unknown");
69
+ });
70
+ return result;
71
+ }
@@ -1,32 +1,32 @@
1
- import type { Parameter } from "@foresthubai/workflow-core/parameter";
2
-
3
- /**
4
- * Build the initial `arguments` record for a new resource instance: each
5
- * parameter that declares a `default` gets seeded. Defaults are `structuredClone`d
6
- * so two instances never share a mutable reference (objects/arrays).
7
- *
8
- * Shared by the registry-backed project primitives (memory, model). Channels
9
- * have conditional, activation-rule parameters and seed inside `channelOperations`
10
- * instead.
11
- */
12
- export function seedDefaultArguments(params: Parameter[]): Record<string, unknown> {
13
- const args: Record<string, unknown> = {};
14
- for (const param of params) {
15
- if ("default" in param && param.default !== undefined) {
16
- args[param.id] = structuredClone(param.default);
17
- }
18
- }
19
- return args;
20
- }
21
-
22
- /**
23
- * Return `desired` if it's free, otherwise append 2, 3, 4… until the result
24
- * doesn't collide with `existing`.
25
- */
26
- export function uniqueName(desired: string, existing: Iterable<string>): string {
27
- const taken = existing instanceof Set ? existing : new Set(existing);
28
- if (!taken.has(desired)) return desired;
29
- let i = 2;
30
- while (taken.has(`${desired}${i}`)) i++;
31
- return `${desired}${i}`;
32
- }
1
+ import type { Parameter } from "@foresthubai/workflow-core/parameter";
2
+
3
+ /**
4
+ * Build the initial `arguments` record for a new resource instance: each
5
+ * parameter that declares a `default` gets seeded. Defaults are `structuredClone`d
6
+ * so two instances never share a mutable reference (objects/arrays).
7
+ *
8
+ * Shared by the registry-backed project primitives (memory, model). Channels
9
+ * have conditional, activation-rule parameters and seed inside `channelOperations`
10
+ * instead.
11
+ */
12
+ export function seedDefaultArguments(params: Parameter[]): Record<string, unknown> {
13
+ const args: Record<string, unknown> = {};
14
+ for (const param of params) {
15
+ if ("default" in param && param.default !== undefined) {
16
+ args[param.id] = structuredClone(param.default);
17
+ }
18
+ }
19
+ return args;
20
+ }
21
+
22
+ /**
23
+ * Return `desired` if it's free, otherwise append 2, 3, 4… until the result
24
+ * doesn't collide with `existing`.
25
+ */
26
+ export function uniqueName(desired: string, existing: Iterable<string>): string {
27
+ const taken = existing instanceof Set ? existing : new Set(existing);
28
+ if (!taken.has(desired)) return desired;
29
+ let i = 2;
30
+ while (taken.has(`${desired}${i}`)) i++;
31
+ return `${desired}${i}`;
32
+ }
@@ -1,28 +1,28 @@
1
- import type { TFunction } from "i18next";
2
- import type { NodeDefinition } from "@foresthubai/workflow-core/node";
3
- import type { Parameter } from "@foresthubai/workflow-core/parameter";
4
-
5
- /**
6
- * Convention-based i18n helpers for description strings only.
7
- *
8
- * Keys follow the pattern:
9
- * nodes.<NodeType>.description
10
- * edges.<EdgeType>.description
11
- * <prefix>.params.<paramId>.description
12
- *
13
- * Labels, categories, port names, and option labels stay as raw English code values.
14
- * Only natural-language descriptions are translated.
15
- */
16
-
17
- export function getNodeDescription(t: TFunction, def: NodeDefinition): string {
18
- return t(`nodes.${def.type}.description`, { defaultValue: def.description });
19
- }
20
-
21
- export function getParamDescription(t: TFunction, translationPrefix: string, param: Parameter): string {
22
- if (!param.description) return "";
23
- return t(`${translationPrefix}.params.${param.id}.description`, { defaultValue: param.description });
24
- }
25
-
26
- export function getEdgeDescription(t: TFunction, def: { description: string }, portType: string): string {
27
- return t(`edges.${portType}.description`, { defaultValue: def.description });
28
- }
1
+ import type { TFunction } from "i18next";
2
+ import type { NodeDefinition } from "@foresthubai/workflow-core/node";
3
+ import type { Parameter } from "@foresthubai/workflow-core/parameter";
4
+
5
+ /**
6
+ * Convention-based i18n helpers for description strings only.
7
+ *
8
+ * Keys follow the pattern:
9
+ * nodes.<NodeType>.description
10
+ * edges.<EdgeType>.description
11
+ * <prefix>.params.<paramId>.description
12
+ *
13
+ * Labels, categories, port names, and option labels stay as raw English code values.
14
+ * Only natural-language descriptions are translated.
15
+ */
16
+
17
+ export function getNodeDescription(t: TFunction, def: NodeDefinition): string {
18
+ return t(`nodes.${def.type}.description`, { defaultValue: def.description });
19
+ }
20
+
21
+ export function getParamDescription(t: TFunction, translationPrefix: string, param: Parameter): string {
22
+ if (!param.description) return "";
23
+ return t(`${translationPrefix}.params.${param.id}.description`, { defaultValue: param.description });
24
+ }
25
+
26
+ export function getEdgeDescription(t: TFunction, def: { description: string }, portType: string): string {
27
+ return t(`edges.${portType}.description`, { defaultValue: def.description });
28
+ }