@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.
- package/LICENSE +661 -661
- package/NOTICE +16 -16
- package/README.md +110 -93
- package/dist/components/ui/command.d.ts +2 -2
- package/dist/components/ui/input.d.ts +1 -1
- package/dist/components/ui/resizable.d.ts +1 -1
- package/dist/components/ui/textarea.d.ts +1 -1
- package/dist/graph/BaseNode.js +10 -10
- package/dist/graph/reactFlowRegistry.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/toolbars/CanvasTabsToolbar.d.ts +11 -0
- package/dist/toolbars/CanvasTabsToolbar.d.ts.map +1 -0
- package/dist/toolbars/CanvasTabsToolbar.js +101 -0
- package/dist/toolbars/CanvasTabsToolbar.js.map +1 -0
- package/package.json +2 -2
- package/src/BuilderLayout.tsx +345 -345
- package/src/Canvas.tsx +261 -261
- package/src/CanvasEditor.tsx +142 -142
- package/src/CanvasTabsToolbar.tsx +176 -176
- package/src/RightConfigPanel.tsx +266 -266
- package/src/WorkflowBuilder.tsx +412 -412
- package/src/cn.ts +6 -6
- package/src/components/ui/add-button.tsx +39 -39
- package/src/components/ui/alert-dialog.tsx +141 -141
- package/src/components/ui/alert.tsx +59 -59
- package/src/components/ui/badge.tsx +36 -36
- package/src/components/ui/button.tsx +85 -85
- package/src/components/ui/card.tsx +79 -79
- package/src/components/ui/checkbox.tsx +28 -28
- package/src/components/ui/collapsible.tsx +9 -9
- package/src/components/ui/command.tsx +153 -153
- package/src/components/ui/delete-button.tsx +23 -23
- package/src/components/ui/dialog.tsx +125 -125
- package/src/components/ui/dropdown-menu.tsx +198 -198
- package/src/components/ui/input.tsx +55 -55
- package/src/components/ui/label.tsx +24 -24
- package/src/components/ui/readonly-banner.tsx +15 -15
- package/src/components/ui/resizable.tsx +43 -43
- package/src/components/ui/scroll-area.tsx +102 -102
- package/src/components/ui/select.tsx +160 -160
- package/src/components/ui/separator.tsx +29 -29
- package/src/components/ui/switch.tsx +27 -27
- package/src/components/ui/textarea.tsx +51 -51
- package/src/components/ui/toast.tsx +127 -127
- package/src/components/ui/toaster.tsx +33 -33
- package/src/components/ui/toggle-group.tsx +59 -59
- package/src/components/ui/toggle.tsx +43 -43
- package/src/components/ui/tooltip.tsx +32 -32
- package/src/dialogs/NodePickerDialog.tsx +84 -84
- package/src/dialogs/ValidationDialog.tsx +184 -184
- package/src/graph/BaseNode.tsx +557 -557
- package/src/graph/CustomEdge.tsx +185 -185
- package/src/graph/CustomNode.tsx +16 -16
- package/src/graph/FunctionCallNode.tsx +30 -30
- package/src/graph/PortHandle.tsx +189 -189
- package/src/graph/reactFlowRegistry.ts +26 -26
- package/src/hooks/use-toast.ts +125 -125
- package/src/hooks/useAvailableVariables.ts +20 -20
- package/src/hooks/useCanvasHistory.ts +22 -22
- package/src/hooks/useCanvasTabs.ts +168 -168
- package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
- package/src/hooks/useFunctionRegistry.ts +26 -26
- package/src/hooks/useFunctions.ts +44 -44
- package/src/hooks/useGraph.ts +161 -161
- package/src/hooks/useNodeDefinitions.ts +82 -82
- package/src/hooks/useParamErrors.ts +26 -26
- package/src/hooks/useResolvedTheme.ts +30 -30
- package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
- package/src/hooks/useSuppressThemeTransition.ts +79 -79
- package/src/hooks/useWorkflowSerialization.ts +127 -127
- package/src/i18n/index.ts +53 -53
- package/src/i18n/locales/de.json +501 -501
- package/src/i18n/locales/en.json +557 -557
- package/src/index.ts +27 -27
- package/src/inputs/ExpressionInput.tsx +297 -297
- package/src/inputs/ParameterEditor.tsx +515 -515
- package/src/inputs/PortSection.tsx +144 -144
- package/src/panels/BuilderSidebar.tsx +301 -301
- package/src/panels/ChannelConfigPanel.tsx +49 -49
- package/src/panels/ChannelsPanel.tsx +28 -28
- package/src/panels/DebugConsolePanel.tsx +73 -73
- package/src/panels/DebugContextPanel.tsx +77 -77
- package/src/panels/DebugExternalIOPanel.tsx +180 -180
- package/src/panels/DiagnosticsPanel.tsx +170 -170
- package/src/panels/EdgeConfigPanel.tsx +104 -104
- package/src/panels/FunctionConfigPanel.tsx +179 -179
- package/src/panels/FunctionListPanel.tsx +45 -45
- package/src/panels/MemoryConfigPanel.tsx +55 -55
- package/src/panels/MemoryPanel.tsx +40 -40
- package/src/panels/ModelConfigPanel.tsx +41 -41
- package/src/panels/ModelsPanel.tsx +36 -36
- package/src/panels/NodeConfigPanel.tsx +630 -630
- package/src/panels/NodeLibrary.tsx +288 -288
- package/src/panels/ResourceConfigPanel.tsx +132 -132
- package/src/panels/ResourceListPanel.tsx +113 -113
- package/src/panels/VariableConfigPanel.tsx +161 -161
- package/src/panels/VariablesPanel.tsx +145 -145
- package/src/stores/canvasStore.test.ts +44 -44
- package/src/stores/canvasStore.ts +245 -245
- package/src/stores/debugStore.ts +74 -74
- package/src/stores/diagnosticsStore.ts +130 -130
- package/src/stores/editorStore.ts +202 -202
- package/src/styles/index.css +526 -526
- package/src/utils/categoryConstants.ts +26 -26
- package/src/utils/channelOperations.ts +86 -86
- package/src/utils/connectionRules.ts +137 -137
- package/src/utils/functionOperations.ts +179 -179
- package/src/utils/graphOperations.ts +550 -550
- package/src/utils/history.ts +207 -207
- package/src/utils/memoryOperations.ts +57 -57
- package/src/utils/migrateFunctionNodes.ts +107 -107
- package/src/utils/modelOperations.ts +55 -55
- package/src/utils/paramDisplay.ts +71 -71
- package/src/utils/resourceHelpers.ts +32 -32
- package/src/utils/translation.ts +28 -28
- package/src/utils/variableOperations.ts +75 -75
- package/tailwind-preset.ts +166 -166
|
@@ -1,515 +1,515 @@
|
|
|
1
|
-
import { Input } from "../components/ui/input";
|
|
2
|
-
import { Textarea } from "../components/ui/textarea";
|
|
3
|
-
import { Label } from "../components/ui/label";
|
|
4
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../components/ui/select";
|
|
5
|
-
import { Switch } from "../components/ui/switch";
|
|
6
|
-
import { Alert, AlertDescription } from "../components/ui/alert";
|
|
7
|
-
import { Button } from "../components/ui/button";
|
|
8
|
-
import { AddButton } from "../components/ui/add-button";
|
|
9
|
-
import { ToggleGroup, ToggleGroupItem } from "../components/ui/toggle-group";
|
|
10
|
-
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
11
|
-
import type { DataType, Expression, Reference } from "@foresthubai/workflow-core";
|
|
12
|
-
import type {
|
|
13
|
-
ExpressionParam,
|
|
14
|
-
ChannelSelectParam,
|
|
15
|
-
MemorySelectParam,
|
|
16
|
-
ModelSelectParam,
|
|
17
|
-
Parameter,
|
|
18
|
-
StringParam,
|
|
19
|
-
} from "@foresthubai/workflow-core/parameter";
|
|
20
|
-
import {
|
|
21
|
-
resolveCapabilities,
|
|
22
|
-
resolveExpressionType,
|
|
23
|
-
resolveChannelTypes,
|
|
24
|
-
resolveMemoryTypes,
|
|
25
|
-
resolveModelTypes,
|
|
26
|
-
} from "@foresthubai/workflow-core/parameter";
|
|
27
|
-
import { useTranslation } from "react-i18next";
|
|
28
|
-
import { useAvailableVariables } from "../hooks/useAvailableVariables";
|
|
29
|
-
import { useEditorStore } from "../stores/editorStore";
|
|
30
|
-
import { varKey, refToLookupKey } from "@foresthubai/workflow-core/variable";
|
|
31
|
-
import type { Channel } from "@foresthubai/workflow-core/channel";
|
|
32
|
-
import type { Memory, MemoryRef } from "@foresthubai/workflow-core/memory";
|
|
33
|
-
import type { ModelCapability } from "@foresthubai/workflow-core/model";
|
|
34
|
-
import ExpressionInput from "./ExpressionInput";
|
|
35
|
-
import { getParamDescription } from "../utils/translation";
|
|
36
|
-
|
|
37
|
-
/** Shared Select component for all reference-select parameter types */
|
|
38
|
-
function ReferenceSelect({
|
|
39
|
-
value,
|
|
40
|
-
options,
|
|
41
|
-
isStale,
|
|
42
|
-
loading,
|
|
43
|
-
placeholder,
|
|
44
|
-
onChange,
|
|
45
|
-
}: {
|
|
46
|
-
value: string | undefined;
|
|
47
|
-
options: { value: string; label: string }[];
|
|
48
|
-
isStale: boolean;
|
|
49
|
-
loading?: boolean;
|
|
50
|
-
placeholder: string;
|
|
51
|
-
onChange: (value: string | undefined) => void;
|
|
52
|
-
}) {
|
|
53
|
-
const NONE = "__none__";
|
|
54
|
-
const selectValue = isStale ? undefined : (value ?? NONE);
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<Select value={selectValue} onValueChange={(v) => onChange(v === NONE ? undefined : v)} disabled={loading}>
|
|
58
|
-
<SelectTrigger>
|
|
59
|
-
<SelectValue
|
|
60
|
-
placeholder={
|
|
61
|
-
isStale ? <span className="text-destructive">Deleted reference</span> : loading ? "Loading..." : placeholder
|
|
62
|
-
}
|
|
63
|
-
/>
|
|
64
|
-
</SelectTrigger>
|
|
65
|
-
<SelectContent>
|
|
66
|
-
<SelectItem value={NONE}>
|
|
67
|
-
<span className="text-muted-foreground italic pr-0.5">None</span>
|
|
68
|
-
</SelectItem>
|
|
69
|
-
{options.map((opt) => (
|
|
70
|
-
<SelectItem key={opt.value} value={opt.value}>
|
|
71
|
-
{opt.label}
|
|
72
|
-
</SelectItem>
|
|
73
|
-
))}
|
|
74
|
-
</SelectContent>
|
|
75
|
-
</Select>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function getExpressionPlaceholder(dataType: DataType): string {
|
|
80
|
-
switch (dataType) {
|
|
81
|
-
case "int":
|
|
82
|
-
case "float":
|
|
83
|
-
return "${var1} + ${var2}";
|
|
84
|
-
case "bool":
|
|
85
|
-
return "${var1} > ${var2}";
|
|
86
|
-
case "string":
|
|
87
|
-
return "hello ${var1}";
|
|
88
|
-
default:
|
|
89
|
-
return "${var1}";
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
interface ParameterEditorProps {
|
|
94
|
-
canvasId: string;
|
|
95
|
-
parameter: Parameter;
|
|
96
|
-
value: unknown;
|
|
97
|
-
allArguments: Record<string, unknown>;
|
|
98
|
-
onChange: (value: unknown) => void;
|
|
99
|
-
errors?: string[];
|
|
100
|
-
translationPrefix?: string;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const ParameterEditor = ({
|
|
104
|
-
canvasId,
|
|
105
|
-
parameter,
|
|
106
|
-
value,
|
|
107
|
-
allArguments,
|
|
108
|
-
onChange,
|
|
109
|
-
errors,
|
|
110
|
-
translationPrefix,
|
|
111
|
-
}: ParameterEditorProps) => {
|
|
112
|
-
const { t } = useTranslation();
|
|
113
|
-
// Do NOT fall back to parameter.default here — each input type handles undefined individually.
|
|
114
|
-
// This preserves the distinction between "user cleared field" and "default value".
|
|
115
|
-
const currentValue = value;
|
|
116
|
-
const { list: variableList, lookup: variables } = useAvailableVariables(canvasId);
|
|
117
|
-
const channels = useEditorStore((s) => s.channels);
|
|
118
|
-
const memory = useEditorStore((s) => s.memory);
|
|
119
|
-
const models = useEditorStore((s) => s.models);
|
|
120
|
-
const availableModels = useEditorStore((s) => s.availableModels);
|
|
121
|
-
|
|
122
|
-
const renderInput = () => {
|
|
123
|
-
switch (parameter.type) {
|
|
124
|
-
case "variableSelect": {
|
|
125
|
-
const ref = currentValue as Reference | undefined;
|
|
126
|
-
const selectedKey = ref?.varId ? refToLookupKey(ref) : undefined;
|
|
127
|
-
const isStale = !!(selectedKey && !variables[selectedKey]);
|
|
128
|
-
const options = variableList.map((v) => ({ value: varKey(v), label: `${v.name} (${v.dataType})` }));
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<ReferenceSelect
|
|
132
|
-
value={selectedKey}
|
|
133
|
-
options={options}
|
|
134
|
-
isStale={isStale}
|
|
135
|
-
placeholder="Select variable..."
|
|
136
|
-
onChange={(key) => {
|
|
137
|
-
if (!key) {
|
|
138
|
-
onChange(undefined);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const variable = variables[key];
|
|
142
|
-
if (!variable) return;
|
|
143
|
-
const newRef: Reference =
|
|
144
|
-
variable.kind === "node"
|
|
145
|
-
? { srcId: variable.nodeId, varId: variable.outputId }
|
|
146
|
-
: variable.kind === "declared"
|
|
147
|
-
? { srcId: "declared", varId: variable.uid }
|
|
148
|
-
: { srcId: "fnarg", varId: variable.uid };
|
|
149
|
-
onChange(newRef);
|
|
150
|
-
}}
|
|
151
|
-
/>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
case "expression": {
|
|
156
|
-
const exprParam = parameter as ExpressionParam;
|
|
157
|
-
// Resolve expressionType — static, args-only lambda, or derived from a referenced variable
|
|
158
|
-
const resolvedType: DataType = resolveExpressionType(exprParam, allArguments, variables);
|
|
159
|
-
// Ensure we have a valid expression object (create empty one if undefined for safety)
|
|
160
|
-
const exprValue: Expression =
|
|
161
|
-
currentValue && typeof currentValue === "object" && "expression" in currentValue
|
|
162
|
-
? (currentValue as Expression)
|
|
163
|
-
: { expression: "", references: [], dataType: resolvedType };
|
|
164
|
-
return (
|
|
165
|
-
<ExpressionInput
|
|
166
|
-
value={exprValue}
|
|
167
|
-
onChange={onChange}
|
|
168
|
-
expressionType={resolvedType}
|
|
169
|
-
availableVariables={variables}
|
|
170
|
-
placeholder={getExpressionPlaceholder(resolvedType)}
|
|
171
|
-
/>
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
case "string":
|
|
176
|
-
if ((parameter as StringParam).multiline) {
|
|
177
|
-
return (
|
|
178
|
-
<Textarea
|
|
179
|
-
value={(currentValue as string) || ""}
|
|
180
|
-
onChange={(e) => onChange(e.target.value)}
|
|
181
|
-
placeholder={String(parameter.default ?? "")}
|
|
182
|
-
rows={4}
|
|
183
|
-
/>
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
return (
|
|
187
|
-
<Input
|
|
188
|
-
value={(currentValue as string) || ""}
|
|
189
|
-
onChange={(e) => onChange(e.target.value)}
|
|
190
|
-
placeholder={String(parameter.default ?? "")}
|
|
191
|
-
/>
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
case "int":
|
|
195
|
-
return (
|
|
196
|
-
<Input
|
|
197
|
-
type="number"
|
|
198
|
-
step={1}
|
|
199
|
-
value={currentValue != null ? (currentValue as number) : ""}
|
|
200
|
-
onChange={(e) => {
|
|
201
|
-
const numValue = parseInt(e.target.value, 10);
|
|
202
|
-
onChange(isNaN(numValue) ? undefined : numValue);
|
|
203
|
-
}}
|
|
204
|
-
placeholder={parameter.default?.toString() || "0"}
|
|
205
|
-
/>
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
case "float":
|
|
209
|
-
return (
|
|
210
|
-
<Input
|
|
211
|
-
type="number"
|
|
212
|
-
step="any"
|
|
213
|
-
className="[&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [-moz-appearance:textfield]"
|
|
214
|
-
value={currentValue != null ? (currentValue as number) : ""}
|
|
215
|
-
onChange={(e) => {
|
|
216
|
-
const numValue = parseFloat(e.target.value);
|
|
217
|
-
onChange(isNaN(numValue) ? undefined : numValue);
|
|
218
|
-
}}
|
|
219
|
-
placeholder={parameter.default?.toString() || "0"}
|
|
220
|
-
/>
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
case "bool": {
|
|
224
|
-
const boolValue = currentValue as boolean;
|
|
225
|
-
return (
|
|
226
|
-
<div className="flex items-center space-x-2">
|
|
227
|
-
<Switch checked={boolValue} onCheckedChange={onChange} />
|
|
228
|
-
<span className="text-sm text-muted-foreground">{boolValue ? "Enabled" : "Disabled"}</span>
|
|
229
|
-
</div>
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
case "selection": {
|
|
234
|
-
const NONE = "__none__";
|
|
235
|
-
const selectValue = (currentValue as string) ?? (parameter.optional ? NONE : "");
|
|
236
|
-
return (
|
|
237
|
-
<Select value={selectValue} onValueChange={(v) => onChange(v === NONE ? undefined : v)}>
|
|
238
|
-
<SelectTrigger>
|
|
239
|
-
<SelectValue placeholder="Select..." />
|
|
240
|
-
</SelectTrigger>
|
|
241
|
-
<SelectContent>
|
|
242
|
-
{parameter.optional && (
|
|
243
|
-
<SelectItem value={NONE}>
|
|
244
|
-
<span className="text-muted-foreground italic pr-0.5">None</span>
|
|
245
|
-
</SelectItem>
|
|
246
|
-
)}
|
|
247
|
-
{parameter.options.map((option) => (
|
|
248
|
-
<SelectItem key={option.value} value={option.value}>
|
|
249
|
-
{option.label}
|
|
250
|
-
</SelectItem>
|
|
251
|
-
))}
|
|
252
|
-
</SelectContent>
|
|
253
|
-
</Select>
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
case "memorySelect": {
|
|
258
|
-
const memoryParam = parameter as ParameterEditorProps["parameter"] & MemorySelectParam;
|
|
259
|
-
const allowedTypes = resolveMemoryTypes(memoryParam, allArguments);
|
|
260
|
-
const matching = Object.values(memory).filter((m: Memory) => allowedTypes.includes(m.type));
|
|
261
|
-
|
|
262
|
-
const selectedId = currentValue as string | undefined;
|
|
263
|
-
const isStale = !!(selectedId && !matching.some((m) => m.id === selectedId));
|
|
264
|
-
const options = matching.map((m) => ({ value: m.id, label: m.label }));
|
|
265
|
-
|
|
266
|
-
return (
|
|
267
|
-
<ReferenceSelect
|
|
268
|
-
value={selectedId}
|
|
269
|
-
options={options}
|
|
270
|
-
isStale={isStale}
|
|
271
|
-
placeholder={t("selectMemory", "Select memory...")}
|
|
272
|
-
onChange={(v) => onChange(v)}
|
|
273
|
-
/>
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
case "modelSelect": {
|
|
278
|
-
const modelParam = parameter as ParameterEditorProps["parameter"] & ModelSelectParam;
|
|
279
|
-
const allowedTypes = resolveModelTypes(modelParam, allArguments);
|
|
280
|
-
const requiredCaps = resolveCapabilities(modelParam, allArguments);
|
|
281
|
-
const hasAllCaps = (caps: ModelCapability[]) =>
|
|
282
|
-
!requiredCaps?.length || requiredCaps.every((c) => caps.includes(c));
|
|
283
|
-
|
|
284
|
-
// Static catalog (props): the always-available models the llmproxy supports.
|
|
285
|
-
const catalogOptions = availableModels
|
|
286
|
-
.filter((m) => hasAllCaps(m.capabilities))
|
|
287
|
-
.map((m) => ({ value: m.id, label: m.label }));
|
|
288
|
-
|
|
289
|
-
// Declared custom models of a compatible type (capabilities default to chat).
|
|
290
|
-
const customOptions = Object.values(models)
|
|
291
|
-
.filter(
|
|
292
|
-
(m) =>
|
|
293
|
-
allowedTypes.includes(m.type) && hasAllCaps((m.arguments.capabilities as ModelCapability[]) ?? ["chat"]),
|
|
294
|
-
)
|
|
295
|
-
.map((m) => ({ value: m.id, label: m.label }));
|
|
296
|
-
|
|
297
|
-
// Catalog first; drop customs shadowed by a catalog id.
|
|
298
|
-
const catalogIds = new Set(catalogOptions.map((o) => o.value));
|
|
299
|
-
const options = [...catalogOptions, ...customOptions.filter((o) => !catalogIds.has(o.value))];
|
|
300
|
-
|
|
301
|
-
const selectedId = currentValue as string | undefined;
|
|
302
|
-
const isStale = !!(selectedId && !options.some((o) => o.value === selectedId));
|
|
303
|
-
|
|
304
|
-
if (options.length === 0) {
|
|
305
|
-
return (
|
|
306
|
-
<Alert variant="destructive">
|
|
307
|
-
<AlertTriangle className="h-4 w-4" />
|
|
308
|
-
<AlertDescription>{t("noModelsAvailable")}</AlertDescription>
|
|
309
|
-
</Alert>
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return (
|
|
314
|
-
<ReferenceSelect
|
|
315
|
-
value={selectedId}
|
|
316
|
-
options={options}
|
|
317
|
-
isStale={isStale}
|
|
318
|
-
placeholder={t("selectModel", "Select model...")}
|
|
319
|
-
onChange={(v) => onChange(v)}
|
|
320
|
-
/>
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
case "time":
|
|
325
|
-
return <Input type="time" value={(currentValue as string) ?? ""} onChange={(e) => onChange(e.target.value)} />;
|
|
326
|
-
|
|
327
|
-
case "weekdays": {
|
|
328
|
-
const DAYS = [
|
|
329
|
-
{ code: "mon", label: "Mon" },
|
|
330
|
-
{ code: "tue", label: "Tue" },
|
|
331
|
-
{ code: "wed", label: "Wed" },
|
|
332
|
-
{ code: "thu", label: "Thu" },
|
|
333
|
-
{ code: "fri", label: "Fri" },
|
|
334
|
-
{ code: "sat", label: "Sat" },
|
|
335
|
-
{ code: "sun", label: "Sun" },
|
|
336
|
-
];
|
|
337
|
-
const selected = (currentValue as string[]) || [];
|
|
338
|
-
const toggle = (code: string) => {
|
|
339
|
-
const next = selected.includes(code) ? selected.filter((d) => d !== code) : [...selected, code];
|
|
340
|
-
onChange(next);
|
|
341
|
-
};
|
|
342
|
-
return (
|
|
343
|
-
<div className="space-y-1.5">
|
|
344
|
-
<div className="flex gap-1">
|
|
345
|
-
{DAYS.map((day) => (
|
|
346
|
-
<button
|
|
347
|
-
key={day.code}
|
|
348
|
-
type="button"
|
|
349
|
-
onClick={() => toggle(day.code)}
|
|
350
|
-
className={`px-2 py-1 text-xs rounded-md border transition-colors ${
|
|
351
|
-
selected.includes(day.code)
|
|
352
|
-
? "bg-primary text-primary-foreground border-primary"
|
|
353
|
-
: "bg-field text-muted-foreground border-input hover:bg-muted/50"
|
|
354
|
-
}`}
|
|
355
|
-
>
|
|
356
|
-
{day.label}
|
|
357
|
-
</button>
|
|
358
|
-
))}
|
|
359
|
-
</div>
|
|
360
|
-
</div>
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
case "memory-refs": {
|
|
365
|
-
const refs = (currentValue as MemoryRef[] | undefined) ?? [];
|
|
366
|
-
// memory-refs bind to MemoryFile-type memories only.
|
|
367
|
-
const allFiles = Object.values(memory).filter((m) => m.type === "MemoryFile");
|
|
368
|
-
const allFilesById = new Map(allFiles.map((m) => [m.id, m]));
|
|
369
|
-
|
|
370
|
-
const replace = (index: number, next: MemoryRef) => onChange(refs.map((r, i) => (i === index ? next : r)));
|
|
371
|
-
const remove = (index: number) => onChange(refs.filter((_, i) => i !== index));
|
|
372
|
-
const add = () => {
|
|
373
|
-
// Pre-select the first unused memory file (if any) so adding a row
|
|
374
|
-
// immediately gives the user a valid binding to start tweaking.
|
|
375
|
-
const usedIds = new Set(refs.map((r) => r.id));
|
|
376
|
-
const firstUnused = allFiles.find((m) => !usedIds.has(m.id));
|
|
377
|
-
onChange([...refs, { id: firstUnused?.id ?? "", mode: "r" as const }]);
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
// Always render existing refs (even when there are 0 memory files left)
|
|
381
|
-
// so the user can delete dangling references after the underlying memory
|
|
382
|
-
// file is removed. Mirror of the output-binding pattern in NodeConfigPanel.
|
|
383
|
-
const canAdd = allFiles.length > refs.length;
|
|
384
|
-
|
|
385
|
-
return (
|
|
386
|
-
<div className="space-y-2">
|
|
387
|
-
{refs.length === 0 && allFiles.length === 0 && (
|
|
388
|
-
<p className="text-xs text-muted-foreground italic px-2 py-1">
|
|
389
|
-
{t(
|
|
390
|
-
"noMemoryFilesForAgent",
|
|
391
|
-
"No memory files declared yet. Add one from the Memory tab in the sidebar.",
|
|
392
|
-
)}
|
|
393
|
-
</p>
|
|
394
|
-
)}
|
|
395
|
-
{refs.map((ref, index) => {
|
|
396
|
-
const file = ref.id ? allFilesById.get(ref.id) : undefined;
|
|
397
|
-
const isStale = !!(ref.id && !file);
|
|
398
|
-
const usedByOthers = new Set(refs.filter((_, i) => i !== index).map((r) => r.id));
|
|
399
|
-
const selectableFiles = allFiles.filter((m) => m.id === ref.id || !usedByOthers.has(m.id));
|
|
400
|
-
|
|
401
|
-
return (
|
|
402
|
-
<div key={index} className="rounded-lg bg-card shadow-sm border border-border p-2 space-y-2 transition-all hover:shadow-md">
|
|
403
|
-
<div className="flex items-center gap-2">
|
|
404
|
-
<Select value={ref.id || undefined} onValueChange={(id) => replace(index, { ...ref, id })}>
|
|
405
|
-
<SelectTrigger className="h-7 text-xs flex-1">
|
|
406
|
-
<SelectValue
|
|
407
|
-
placeholder={
|
|
408
|
-
isStale ? (
|
|
409
|
-
<span className="text-destructive">{t("memoryRefStale", "Deleted memory file")}</span>
|
|
410
|
-
) : (
|
|
411
|
-
t("selectMemoryFile", "Select memory file...")
|
|
412
|
-
)
|
|
413
|
-
}
|
|
414
|
-
/>
|
|
415
|
-
</SelectTrigger>
|
|
416
|
-
<SelectContent>
|
|
417
|
-
{selectableFiles.map((m) => (
|
|
418
|
-
<SelectItem key={m.id} value={m.id}>
|
|
419
|
-
{m.label}
|
|
420
|
-
</SelectItem>
|
|
421
|
-
))}
|
|
422
|
-
</SelectContent>
|
|
423
|
-
</Select>
|
|
424
|
-
<Button
|
|
425
|
-
variant="ghost"
|
|
426
|
-
size="icon"
|
|
427
|
-
className="h-7 w-7 shrink-0"
|
|
428
|
-
onClick={() => remove(index)}
|
|
429
|
-
aria-label={t("removeMemoryRef", "Remove memory ref")}
|
|
430
|
-
>
|
|
431
|
-
<Trash2 className="w-3.5 h-3.5" />
|
|
432
|
-
</Button>
|
|
433
|
-
</div>
|
|
434
|
-
<ToggleGroup
|
|
435
|
-
type="single"
|
|
436
|
-
value={ref.mode}
|
|
437
|
-
onValueChange={(v) => v && replace(index, { ...ref, mode: v as "r" | "rw" })}
|
|
438
|
-
className="gap-0 justify-start"
|
|
439
|
-
>
|
|
440
|
-
<ToggleGroupItem value="r" size="sm" variant="outline" className="h-7 px-3 text-xs rounded-r-none">
|
|
441
|
-
{t("memoryModeRead", "Read")}
|
|
442
|
-
</ToggleGroupItem>
|
|
443
|
-
<ToggleGroupItem
|
|
444
|
-
value="rw"
|
|
445
|
-
size="sm"
|
|
446
|
-
variant="outline"
|
|
447
|
-
className="h-7 px-3 text-xs rounded-l-none -ml-px"
|
|
448
|
-
>
|
|
449
|
-
{t("memoryModeReadWrite", "Read + Write")}
|
|
450
|
-
</ToggleGroupItem>
|
|
451
|
-
</ToggleGroup>
|
|
452
|
-
</div>
|
|
453
|
-
);
|
|
454
|
-
})}
|
|
455
|
-
{canAdd && <AddButton onClick={add}>{t("addMemoryRef", "Add memory ref")}</AddButton>}
|
|
456
|
-
</div>
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
case "channelSelect": {
|
|
461
|
-
const channelParam = parameter as ParameterEditorProps["parameter"] & ChannelSelectParam;
|
|
462
|
-
const allowedTypes = resolveChannelTypes(channelParam, allArguments);
|
|
463
|
-
const matching = Object.values(channels).filter((v: Channel) => allowedTypes.includes(v.type));
|
|
464
|
-
|
|
465
|
-
const selectedId = currentValue as string | undefined;
|
|
466
|
-
const isStale = !!(selectedId && !matching.some((v) => v.id === selectedId));
|
|
467
|
-
const options = matching.map((v) => ({ value: v.id, label: v.label }));
|
|
468
|
-
|
|
469
|
-
return (
|
|
470
|
-
<ReferenceSelect
|
|
471
|
-
value={selectedId}
|
|
472
|
-
options={options}
|
|
473
|
-
isStale={isStale}
|
|
474
|
-
placeholder={t("selectChannel")}
|
|
475
|
-
onChange={(v) => onChange(v)}
|
|
476
|
-
/>
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Exhaustiveness check - fails if a parameter type is not handled
|
|
481
|
-
default: {
|
|
482
|
-
const _exhaustive: never = parameter;
|
|
483
|
-
return _exhaustive;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const hasError = errors && errors.length > 0;
|
|
489
|
-
|
|
490
|
-
return (
|
|
491
|
-
<div className={`space-y-2 ${hasError ? "ring-1 ring-destructive rounded-md p-2" : ""}`}>
|
|
492
|
-
<Label className="text-sm font-medium">
|
|
493
|
-
{parameter.label}
|
|
494
|
-
{parameter.optional !== true && <span className="text-destructive ml-1">*</span>}
|
|
495
|
-
</Label>
|
|
496
|
-
{parameter.description && (
|
|
497
|
-
<p className="text-xs text-muted-foreground">
|
|
498
|
-
{translationPrefix ? getParamDescription(t, translationPrefix, parameter) : parameter.description}
|
|
499
|
-
</p>
|
|
500
|
-
)}
|
|
501
|
-
{renderInput()}
|
|
502
|
-
{hasError && (
|
|
503
|
-
<div className="space-y-0.5">
|
|
504
|
-
{errors.map((msg, i) => (
|
|
505
|
-
<p key={i} className="text-xs text-destructive">
|
|
506
|
-
{msg}
|
|
507
|
-
</p>
|
|
508
|
-
))}
|
|
509
|
-
</div>
|
|
510
|
-
)}
|
|
511
|
-
</div>
|
|
512
|
-
);
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
export default ParameterEditor;
|
|
1
|
+
import { Input } from "../components/ui/input";
|
|
2
|
+
import { Textarea } from "../components/ui/textarea";
|
|
3
|
+
import { Label } from "../components/ui/label";
|
|
4
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../components/ui/select";
|
|
5
|
+
import { Switch } from "../components/ui/switch";
|
|
6
|
+
import { Alert, AlertDescription } from "../components/ui/alert";
|
|
7
|
+
import { Button } from "../components/ui/button";
|
|
8
|
+
import { AddButton } from "../components/ui/add-button";
|
|
9
|
+
import { ToggleGroup, ToggleGroupItem } from "../components/ui/toggle-group";
|
|
10
|
+
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
11
|
+
import type { DataType, Expression, Reference } from "@foresthubai/workflow-core";
|
|
12
|
+
import type {
|
|
13
|
+
ExpressionParam,
|
|
14
|
+
ChannelSelectParam,
|
|
15
|
+
MemorySelectParam,
|
|
16
|
+
ModelSelectParam,
|
|
17
|
+
Parameter,
|
|
18
|
+
StringParam,
|
|
19
|
+
} from "@foresthubai/workflow-core/parameter";
|
|
20
|
+
import {
|
|
21
|
+
resolveCapabilities,
|
|
22
|
+
resolveExpressionType,
|
|
23
|
+
resolveChannelTypes,
|
|
24
|
+
resolveMemoryTypes,
|
|
25
|
+
resolveModelTypes,
|
|
26
|
+
} from "@foresthubai/workflow-core/parameter";
|
|
27
|
+
import { useTranslation } from "react-i18next";
|
|
28
|
+
import { useAvailableVariables } from "../hooks/useAvailableVariables";
|
|
29
|
+
import { useEditorStore } from "../stores/editorStore";
|
|
30
|
+
import { varKey, refToLookupKey } from "@foresthubai/workflow-core/variable";
|
|
31
|
+
import type { Channel } from "@foresthubai/workflow-core/channel";
|
|
32
|
+
import type { Memory, MemoryRef } from "@foresthubai/workflow-core/memory";
|
|
33
|
+
import type { ModelCapability } from "@foresthubai/workflow-core/model";
|
|
34
|
+
import ExpressionInput from "./ExpressionInput";
|
|
35
|
+
import { getParamDescription } from "../utils/translation";
|
|
36
|
+
|
|
37
|
+
/** Shared Select component for all reference-select parameter types */
|
|
38
|
+
function ReferenceSelect({
|
|
39
|
+
value,
|
|
40
|
+
options,
|
|
41
|
+
isStale,
|
|
42
|
+
loading,
|
|
43
|
+
placeholder,
|
|
44
|
+
onChange,
|
|
45
|
+
}: {
|
|
46
|
+
value: string | undefined;
|
|
47
|
+
options: { value: string; label: string }[];
|
|
48
|
+
isStale: boolean;
|
|
49
|
+
loading?: boolean;
|
|
50
|
+
placeholder: string;
|
|
51
|
+
onChange: (value: string | undefined) => void;
|
|
52
|
+
}) {
|
|
53
|
+
const NONE = "__none__";
|
|
54
|
+
const selectValue = isStale ? undefined : (value ?? NONE);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Select value={selectValue} onValueChange={(v) => onChange(v === NONE ? undefined : v)} disabled={loading}>
|
|
58
|
+
<SelectTrigger>
|
|
59
|
+
<SelectValue
|
|
60
|
+
placeholder={
|
|
61
|
+
isStale ? <span className="text-destructive">Deleted reference</span> : loading ? "Loading..." : placeholder
|
|
62
|
+
}
|
|
63
|
+
/>
|
|
64
|
+
</SelectTrigger>
|
|
65
|
+
<SelectContent>
|
|
66
|
+
<SelectItem value={NONE}>
|
|
67
|
+
<span className="text-muted-foreground italic pr-0.5">None</span>
|
|
68
|
+
</SelectItem>
|
|
69
|
+
{options.map((opt) => (
|
|
70
|
+
<SelectItem key={opt.value} value={opt.value}>
|
|
71
|
+
{opt.label}
|
|
72
|
+
</SelectItem>
|
|
73
|
+
))}
|
|
74
|
+
</SelectContent>
|
|
75
|
+
</Select>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getExpressionPlaceholder(dataType: DataType): string {
|
|
80
|
+
switch (dataType) {
|
|
81
|
+
case "int":
|
|
82
|
+
case "float":
|
|
83
|
+
return "${var1} + ${var2}";
|
|
84
|
+
case "bool":
|
|
85
|
+
return "${var1} > ${var2}";
|
|
86
|
+
case "string":
|
|
87
|
+
return "hello ${var1}";
|
|
88
|
+
default:
|
|
89
|
+
return "${var1}";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface ParameterEditorProps {
|
|
94
|
+
canvasId: string;
|
|
95
|
+
parameter: Parameter;
|
|
96
|
+
value: unknown;
|
|
97
|
+
allArguments: Record<string, unknown>;
|
|
98
|
+
onChange: (value: unknown) => void;
|
|
99
|
+
errors?: string[];
|
|
100
|
+
translationPrefix?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const ParameterEditor = ({
|
|
104
|
+
canvasId,
|
|
105
|
+
parameter,
|
|
106
|
+
value,
|
|
107
|
+
allArguments,
|
|
108
|
+
onChange,
|
|
109
|
+
errors,
|
|
110
|
+
translationPrefix,
|
|
111
|
+
}: ParameterEditorProps) => {
|
|
112
|
+
const { t } = useTranslation();
|
|
113
|
+
// Do NOT fall back to parameter.default here — each input type handles undefined individually.
|
|
114
|
+
// This preserves the distinction between "user cleared field" and "default value".
|
|
115
|
+
const currentValue = value;
|
|
116
|
+
const { list: variableList, lookup: variables } = useAvailableVariables(canvasId);
|
|
117
|
+
const channels = useEditorStore((s) => s.channels);
|
|
118
|
+
const memory = useEditorStore((s) => s.memory);
|
|
119
|
+
const models = useEditorStore((s) => s.models);
|
|
120
|
+
const availableModels = useEditorStore((s) => s.availableModels);
|
|
121
|
+
|
|
122
|
+
const renderInput = () => {
|
|
123
|
+
switch (parameter.type) {
|
|
124
|
+
case "variableSelect": {
|
|
125
|
+
const ref = currentValue as Reference | undefined;
|
|
126
|
+
const selectedKey = ref?.varId ? refToLookupKey(ref) : undefined;
|
|
127
|
+
const isStale = !!(selectedKey && !variables[selectedKey]);
|
|
128
|
+
const options = variableList.map((v) => ({ value: varKey(v), label: `${v.name} (${v.dataType})` }));
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<ReferenceSelect
|
|
132
|
+
value={selectedKey}
|
|
133
|
+
options={options}
|
|
134
|
+
isStale={isStale}
|
|
135
|
+
placeholder="Select variable..."
|
|
136
|
+
onChange={(key) => {
|
|
137
|
+
if (!key) {
|
|
138
|
+
onChange(undefined);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const variable = variables[key];
|
|
142
|
+
if (!variable) return;
|
|
143
|
+
const newRef: Reference =
|
|
144
|
+
variable.kind === "node"
|
|
145
|
+
? { srcId: variable.nodeId, varId: variable.outputId }
|
|
146
|
+
: variable.kind === "declared"
|
|
147
|
+
? { srcId: "declared", varId: variable.uid }
|
|
148
|
+
: { srcId: "fnarg", varId: variable.uid };
|
|
149
|
+
onChange(newRef);
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
case "expression": {
|
|
156
|
+
const exprParam = parameter as ExpressionParam;
|
|
157
|
+
// Resolve expressionType — static, args-only lambda, or derived from a referenced variable
|
|
158
|
+
const resolvedType: DataType = resolveExpressionType(exprParam, allArguments, variables);
|
|
159
|
+
// Ensure we have a valid expression object (create empty one if undefined for safety)
|
|
160
|
+
const exprValue: Expression =
|
|
161
|
+
currentValue && typeof currentValue === "object" && "expression" in currentValue
|
|
162
|
+
? (currentValue as Expression)
|
|
163
|
+
: { expression: "", references: [], dataType: resolvedType };
|
|
164
|
+
return (
|
|
165
|
+
<ExpressionInput
|
|
166
|
+
value={exprValue}
|
|
167
|
+
onChange={onChange}
|
|
168
|
+
expressionType={resolvedType}
|
|
169
|
+
availableVariables={variables}
|
|
170
|
+
placeholder={getExpressionPlaceholder(resolvedType)}
|
|
171
|
+
/>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
case "string":
|
|
176
|
+
if ((parameter as StringParam).multiline) {
|
|
177
|
+
return (
|
|
178
|
+
<Textarea
|
|
179
|
+
value={(currentValue as string) || ""}
|
|
180
|
+
onChange={(e) => onChange(e.target.value)}
|
|
181
|
+
placeholder={String(parameter.default ?? "")}
|
|
182
|
+
rows={4}
|
|
183
|
+
/>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return (
|
|
187
|
+
<Input
|
|
188
|
+
value={(currentValue as string) || ""}
|
|
189
|
+
onChange={(e) => onChange(e.target.value)}
|
|
190
|
+
placeholder={String(parameter.default ?? "")}
|
|
191
|
+
/>
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
case "int":
|
|
195
|
+
return (
|
|
196
|
+
<Input
|
|
197
|
+
type="number"
|
|
198
|
+
step={1}
|
|
199
|
+
value={currentValue != null ? (currentValue as number) : ""}
|
|
200
|
+
onChange={(e) => {
|
|
201
|
+
const numValue = parseInt(e.target.value, 10);
|
|
202
|
+
onChange(isNaN(numValue) ? undefined : numValue);
|
|
203
|
+
}}
|
|
204
|
+
placeholder={parameter.default?.toString() || "0"}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
case "float":
|
|
209
|
+
return (
|
|
210
|
+
<Input
|
|
211
|
+
type="number"
|
|
212
|
+
step="any"
|
|
213
|
+
className="[&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [-moz-appearance:textfield]"
|
|
214
|
+
value={currentValue != null ? (currentValue as number) : ""}
|
|
215
|
+
onChange={(e) => {
|
|
216
|
+
const numValue = parseFloat(e.target.value);
|
|
217
|
+
onChange(isNaN(numValue) ? undefined : numValue);
|
|
218
|
+
}}
|
|
219
|
+
placeholder={parameter.default?.toString() || "0"}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
case "bool": {
|
|
224
|
+
const boolValue = currentValue as boolean;
|
|
225
|
+
return (
|
|
226
|
+
<div className="flex items-center space-x-2">
|
|
227
|
+
<Switch checked={boolValue} onCheckedChange={onChange} />
|
|
228
|
+
<span className="text-sm text-muted-foreground">{boolValue ? "Enabled" : "Disabled"}</span>
|
|
229
|
+
</div>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
case "selection": {
|
|
234
|
+
const NONE = "__none__";
|
|
235
|
+
const selectValue = (currentValue as string) ?? (parameter.optional ? NONE : "");
|
|
236
|
+
return (
|
|
237
|
+
<Select value={selectValue} onValueChange={(v) => onChange(v === NONE ? undefined : v)}>
|
|
238
|
+
<SelectTrigger>
|
|
239
|
+
<SelectValue placeholder="Select..." />
|
|
240
|
+
</SelectTrigger>
|
|
241
|
+
<SelectContent>
|
|
242
|
+
{parameter.optional && (
|
|
243
|
+
<SelectItem value={NONE}>
|
|
244
|
+
<span className="text-muted-foreground italic pr-0.5">None</span>
|
|
245
|
+
</SelectItem>
|
|
246
|
+
)}
|
|
247
|
+
{parameter.options.map((option) => (
|
|
248
|
+
<SelectItem key={option.value} value={option.value}>
|
|
249
|
+
{option.label}
|
|
250
|
+
</SelectItem>
|
|
251
|
+
))}
|
|
252
|
+
</SelectContent>
|
|
253
|
+
</Select>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case "memorySelect": {
|
|
258
|
+
const memoryParam = parameter as ParameterEditorProps["parameter"] & MemorySelectParam;
|
|
259
|
+
const allowedTypes = resolveMemoryTypes(memoryParam, allArguments);
|
|
260
|
+
const matching = Object.values(memory).filter((m: Memory) => allowedTypes.includes(m.type));
|
|
261
|
+
|
|
262
|
+
const selectedId = currentValue as string | undefined;
|
|
263
|
+
const isStale = !!(selectedId && !matching.some((m) => m.id === selectedId));
|
|
264
|
+
const options = matching.map((m) => ({ value: m.id, label: m.label }));
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<ReferenceSelect
|
|
268
|
+
value={selectedId}
|
|
269
|
+
options={options}
|
|
270
|
+
isStale={isStale}
|
|
271
|
+
placeholder={t("selectMemory", "Select memory...")}
|
|
272
|
+
onChange={(v) => onChange(v)}
|
|
273
|
+
/>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
case "modelSelect": {
|
|
278
|
+
const modelParam = parameter as ParameterEditorProps["parameter"] & ModelSelectParam;
|
|
279
|
+
const allowedTypes = resolveModelTypes(modelParam, allArguments);
|
|
280
|
+
const requiredCaps = resolveCapabilities(modelParam, allArguments);
|
|
281
|
+
const hasAllCaps = (caps: ModelCapability[]) =>
|
|
282
|
+
!requiredCaps?.length || requiredCaps.every((c) => caps.includes(c));
|
|
283
|
+
|
|
284
|
+
// Static catalog (props): the always-available models the llmproxy supports.
|
|
285
|
+
const catalogOptions = availableModels
|
|
286
|
+
.filter((m) => hasAllCaps(m.capabilities))
|
|
287
|
+
.map((m) => ({ value: m.id, label: m.label }));
|
|
288
|
+
|
|
289
|
+
// Declared custom models of a compatible type (capabilities default to chat).
|
|
290
|
+
const customOptions = Object.values(models)
|
|
291
|
+
.filter(
|
|
292
|
+
(m) =>
|
|
293
|
+
allowedTypes.includes(m.type) && hasAllCaps((m.arguments.capabilities as ModelCapability[]) ?? ["chat"]),
|
|
294
|
+
)
|
|
295
|
+
.map((m) => ({ value: m.id, label: m.label }));
|
|
296
|
+
|
|
297
|
+
// Catalog first; drop customs shadowed by a catalog id.
|
|
298
|
+
const catalogIds = new Set(catalogOptions.map((o) => o.value));
|
|
299
|
+
const options = [...catalogOptions, ...customOptions.filter((o) => !catalogIds.has(o.value))];
|
|
300
|
+
|
|
301
|
+
const selectedId = currentValue as string | undefined;
|
|
302
|
+
const isStale = !!(selectedId && !options.some((o) => o.value === selectedId));
|
|
303
|
+
|
|
304
|
+
if (options.length === 0) {
|
|
305
|
+
return (
|
|
306
|
+
<Alert variant="destructive">
|
|
307
|
+
<AlertTriangle className="h-4 w-4" />
|
|
308
|
+
<AlertDescription>{t("noModelsAvailable")}</AlertDescription>
|
|
309
|
+
</Alert>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<ReferenceSelect
|
|
315
|
+
value={selectedId}
|
|
316
|
+
options={options}
|
|
317
|
+
isStale={isStale}
|
|
318
|
+
placeholder={t("selectModel", "Select model...")}
|
|
319
|
+
onChange={(v) => onChange(v)}
|
|
320
|
+
/>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
case "time":
|
|
325
|
+
return <Input type="time" value={(currentValue as string) ?? ""} onChange={(e) => onChange(e.target.value)} />;
|
|
326
|
+
|
|
327
|
+
case "weekdays": {
|
|
328
|
+
const DAYS = [
|
|
329
|
+
{ code: "mon", label: "Mon" },
|
|
330
|
+
{ code: "tue", label: "Tue" },
|
|
331
|
+
{ code: "wed", label: "Wed" },
|
|
332
|
+
{ code: "thu", label: "Thu" },
|
|
333
|
+
{ code: "fri", label: "Fri" },
|
|
334
|
+
{ code: "sat", label: "Sat" },
|
|
335
|
+
{ code: "sun", label: "Sun" },
|
|
336
|
+
];
|
|
337
|
+
const selected = (currentValue as string[]) || [];
|
|
338
|
+
const toggle = (code: string) => {
|
|
339
|
+
const next = selected.includes(code) ? selected.filter((d) => d !== code) : [...selected, code];
|
|
340
|
+
onChange(next);
|
|
341
|
+
};
|
|
342
|
+
return (
|
|
343
|
+
<div className="space-y-1.5">
|
|
344
|
+
<div className="flex gap-1">
|
|
345
|
+
{DAYS.map((day) => (
|
|
346
|
+
<button
|
|
347
|
+
key={day.code}
|
|
348
|
+
type="button"
|
|
349
|
+
onClick={() => toggle(day.code)}
|
|
350
|
+
className={`px-2 py-1 text-xs rounded-md border transition-colors ${
|
|
351
|
+
selected.includes(day.code)
|
|
352
|
+
? "bg-primary text-primary-foreground border-primary"
|
|
353
|
+
: "bg-field text-muted-foreground border-input hover:bg-muted/50"
|
|
354
|
+
}`}
|
|
355
|
+
>
|
|
356
|
+
{day.label}
|
|
357
|
+
</button>
|
|
358
|
+
))}
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
case "memory-refs": {
|
|
365
|
+
const refs = (currentValue as MemoryRef[] | undefined) ?? [];
|
|
366
|
+
// memory-refs bind to MemoryFile-type memories only.
|
|
367
|
+
const allFiles = Object.values(memory).filter((m) => m.type === "MemoryFile");
|
|
368
|
+
const allFilesById = new Map(allFiles.map((m) => [m.id, m]));
|
|
369
|
+
|
|
370
|
+
const replace = (index: number, next: MemoryRef) => onChange(refs.map((r, i) => (i === index ? next : r)));
|
|
371
|
+
const remove = (index: number) => onChange(refs.filter((_, i) => i !== index));
|
|
372
|
+
const add = () => {
|
|
373
|
+
// Pre-select the first unused memory file (if any) so adding a row
|
|
374
|
+
// immediately gives the user a valid binding to start tweaking.
|
|
375
|
+
const usedIds = new Set(refs.map((r) => r.id));
|
|
376
|
+
const firstUnused = allFiles.find((m) => !usedIds.has(m.id));
|
|
377
|
+
onChange([...refs, { id: firstUnused?.id ?? "", mode: "r" as const }]);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Always render existing refs (even when there are 0 memory files left)
|
|
381
|
+
// so the user can delete dangling references after the underlying memory
|
|
382
|
+
// file is removed. Mirror of the output-binding pattern in NodeConfigPanel.
|
|
383
|
+
const canAdd = allFiles.length > refs.length;
|
|
384
|
+
|
|
385
|
+
return (
|
|
386
|
+
<div className="space-y-2">
|
|
387
|
+
{refs.length === 0 && allFiles.length === 0 && (
|
|
388
|
+
<p className="text-xs text-muted-foreground italic px-2 py-1">
|
|
389
|
+
{t(
|
|
390
|
+
"noMemoryFilesForAgent",
|
|
391
|
+
"No memory files declared yet. Add one from the Memory tab in the sidebar.",
|
|
392
|
+
)}
|
|
393
|
+
</p>
|
|
394
|
+
)}
|
|
395
|
+
{refs.map((ref, index) => {
|
|
396
|
+
const file = ref.id ? allFilesById.get(ref.id) : undefined;
|
|
397
|
+
const isStale = !!(ref.id && !file);
|
|
398
|
+
const usedByOthers = new Set(refs.filter((_, i) => i !== index).map((r) => r.id));
|
|
399
|
+
const selectableFiles = allFiles.filter((m) => m.id === ref.id || !usedByOthers.has(m.id));
|
|
400
|
+
|
|
401
|
+
return (
|
|
402
|
+
<div key={index} className="rounded-lg bg-card shadow-sm border border-border p-2 space-y-2 transition-all hover:shadow-md">
|
|
403
|
+
<div className="flex items-center gap-2">
|
|
404
|
+
<Select value={ref.id || undefined} onValueChange={(id) => replace(index, { ...ref, id })}>
|
|
405
|
+
<SelectTrigger className="h-7 text-xs flex-1">
|
|
406
|
+
<SelectValue
|
|
407
|
+
placeholder={
|
|
408
|
+
isStale ? (
|
|
409
|
+
<span className="text-destructive">{t("memoryRefStale", "Deleted memory file")}</span>
|
|
410
|
+
) : (
|
|
411
|
+
t("selectMemoryFile", "Select memory file...")
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
/>
|
|
415
|
+
</SelectTrigger>
|
|
416
|
+
<SelectContent>
|
|
417
|
+
{selectableFiles.map((m) => (
|
|
418
|
+
<SelectItem key={m.id} value={m.id}>
|
|
419
|
+
{m.label}
|
|
420
|
+
</SelectItem>
|
|
421
|
+
))}
|
|
422
|
+
</SelectContent>
|
|
423
|
+
</Select>
|
|
424
|
+
<Button
|
|
425
|
+
variant="ghost"
|
|
426
|
+
size="icon"
|
|
427
|
+
className="h-7 w-7 shrink-0"
|
|
428
|
+
onClick={() => remove(index)}
|
|
429
|
+
aria-label={t("removeMemoryRef", "Remove memory ref")}
|
|
430
|
+
>
|
|
431
|
+
<Trash2 className="w-3.5 h-3.5" />
|
|
432
|
+
</Button>
|
|
433
|
+
</div>
|
|
434
|
+
<ToggleGroup
|
|
435
|
+
type="single"
|
|
436
|
+
value={ref.mode}
|
|
437
|
+
onValueChange={(v) => v && replace(index, { ...ref, mode: v as "r" | "rw" })}
|
|
438
|
+
className="gap-0 justify-start"
|
|
439
|
+
>
|
|
440
|
+
<ToggleGroupItem value="r" size="sm" variant="outline" className="h-7 px-3 text-xs rounded-r-none">
|
|
441
|
+
{t("memoryModeRead", "Read")}
|
|
442
|
+
</ToggleGroupItem>
|
|
443
|
+
<ToggleGroupItem
|
|
444
|
+
value="rw"
|
|
445
|
+
size="sm"
|
|
446
|
+
variant="outline"
|
|
447
|
+
className="h-7 px-3 text-xs rounded-l-none -ml-px"
|
|
448
|
+
>
|
|
449
|
+
{t("memoryModeReadWrite", "Read + Write")}
|
|
450
|
+
</ToggleGroupItem>
|
|
451
|
+
</ToggleGroup>
|
|
452
|
+
</div>
|
|
453
|
+
);
|
|
454
|
+
})}
|
|
455
|
+
{canAdd && <AddButton onClick={add}>{t("addMemoryRef", "Add memory ref")}</AddButton>}
|
|
456
|
+
</div>
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
case "channelSelect": {
|
|
461
|
+
const channelParam = parameter as ParameterEditorProps["parameter"] & ChannelSelectParam;
|
|
462
|
+
const allowedTypes = resolveChannelTypes(channelParam, allArguments);
|
|
463
|
+
const matching = Object.values(channels).filter((v: Channel) => allowedTypes.includes(v.type));
|
|
464
|
+
|
|
465
|
+
const selectedId = currentValue as string | undefined;
|
|
466
|
+
const isStale = !!(selectedId && !matching.some((v) => v.id === selectedId));
|
|
467
|
+
const options = matching.map((v) => ({ value: v.id, label: v.label }));
|
|
468
|
+
|
|
469
|
+
return (
|
|
470
|
+
<ReferenceSelect
|
|
471
|
+
value={selectedId}
|
|
472
|
+
options={options}
|
|
473
|
+
isStale={isStale}
|
|
474
|
+
placeholder={t("selectChannel")}
|
|
475
|
+
onChange={(v) => onChange(v)}
|
|
476
|
+
/>
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Exhaustiveness check - fails if a parameter type is not handled
|
|
481
|
+
default: {
|
|
482
|
+
const _exhaustive: never = parameter;
|
|
483
|
+
return _exhaustive;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const hasError = errors && errors.length > 0;
|
|
489
|
+
|
|
490
|
+
return (
|
|
491
|
+
<div className={`space-y-2 ${hasError ? "ring-1 ring-destructive rounded-md p-2" : ""}`}>
|
|
492
|
+
<Label className="text-sm font-medium">
|
|
493
|
+
{parameter.label}
|
|
494
|
+
{parameter.optional !== true && <span className="text-destructive ml-1">*</span>}
|
|
495
|
+
</Label>
|
|
496
|
+
{parameter.description && (
|
|
497
|
+
<p className="text-xs text-muted-foreground">
|
|
498
|
+
{translationPrefix ? getParamDescription(t, translationPrefix, parameter) : parameter.description}
|
|
499
|
+
</p>
|
|
500
|
+
)}
|
|
501
|
+
{renderInput()}
|
|
502
|
+
{hasError && (
|
|
503
|
+
<div className="space-y-0.5">
|
|
504
|
+
{errors.map((msg, i) => (
|
|
505
|
+
<p key={i} className="text-xs text-destructive">
|
|
506
|
+
{msg}
|
|
507
|
+
</p>
|
|
508
|
+
))}
|
|
509
|
+
</div>
|
|
510
|
+
)}
|
|
511
|
+
</div>
|
|
512
|
+
);
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
export default ParameterEditor;
|