@flowdrop/flowdrop 2.0.0-beta.6 → 2.0.0-beta.7

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/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0-beta.7] - 2026-07-09
11
+
12
+ Seventh 2.0 beta, published under the npm `beta` dist-tag (`npm install @flowdrop/flowdrop@beta`). `latest` remains 1.15.0 until 2.0.0 GA. Dynamic config schemas become composable and self-refreshing. A dynamic-schema endpoint can now **layer onto** a node's static schema instead of replacing the whole form — merging in the fields it owns, or targeting a single region — so an endpoint only returns what it actually drives and the rest of the form stays exactly as authored. The fetched form also **refetches on its own** when a config value its URL depends on changes (e.g. picking a different trigger `event_type`), rather than loading only once on mount. All additive: the historical whole-form `replace` behaviour is still the default, so existing dynamic-schema configs are unchanged.
13
+
14
+ ### Added
15
+
16
+ - **Dynamic config schema can layer onto the static schema (`mergeStrategy` + `target`).** `DynamicSchemaEndpoint` gains two optional fields. `mergeStrategy: 'replace' | 'merge'` — `merge` combines the fetched schema with the node's static schema (`schema` prop / `metadata.configSchema`): properties are merged (fetched wins per key), `required` is unioned, so an endpoint only has to return the fields it drives. `target` — a dot-path of property keys (e.g. `"advanced"` or `"advanced.retry"`) that restricts the fetch to one region of the form, splicing the fetched schema in at that location and leaving every other field static; `mergeStrategy` then decides replace-vs-merge at that node. Both default to whole-form `replace`, matching prior behaviour. When `merge`/`target` is configured, the schema is now fetched even if a static schema is present (previously a static schema suppressed the fetch). New `applyFetchedSchema` util backs the combination.
17
+ - **Dynamic schema auto-refetches when its inputs change.** `ConfigForm` now watches the resolved endpoint URL — template variables substituted from the node context — as a reactive key and refetches whenever it changes, so choosing a different value that the endpoint depends on (e.g. a trigger's `event_type`) reloads the matching schema instead of showing the schema captured at mount. A fetch already in flight is left to settle before the next one runs, and the key only reflects what the URL actually references, so static endpoints never spuriously refetch. New `resolveDynamicSchemaKey` export.
18
+ - **Dynamic schema endpoints can return a companion `uiSchema`.** When the endpoint response includes a `uiSchema` (read from `uiSchema`, `data.uiSchema`, or `schema.uiSchema`), `ConfigForm` uses it to lay out the fetched schema and caches it alongside the schema. It takes precedence over the node's static-metadata `uiSchema` — which can only reference the static schema's fields and would mislay a server-hydrated form — while a directly-passed `uiSchema` prop still wins. `DynamicSchemaResult` and the cache entry gain an optional `uiSchema`.
19
+
20
+ ### Fixed
21
+
22
+ - **Config values are no longer silently dropped on save.** `ConfigForm` rebuilt the saved config solely from the active schema's properties, so any stored config key the schema didn't render — for example after a dynamic schema returned a narrower field set — was lost on the next blur/save. The commit paths (`onChange` on blur, and explicit save) now preserve config keys the active schema doesn't own, with the rendered fields still taking precedence.
23
+ - **`invalidateSchemaCache` now matches the fetch cache key.** It built the node context without the `workflowId`, so for endpoints whose URL references `{workflowId}` it resolved a different cache key than `fetchDynamicSchema` and failed to evict the entry — a manual schema refresh then re-served the stale cached schema. It now accepts `workflowId` (matching the fetch context); the context-building for schema-URL, external-edit-URL, and cache-key resolution was consolidated so they can no longer drift apart.
24
+
10
25
  ## [2.0.0-beta.6] - 2026-06-22
11
26
 
12
27
  Sixth 2.0 beta, published under the npm `beta` dist-tag (`npm install @flowdrop/flowdrop@beta`). `latest` remains 1.15.0 until 2.0.0 GA. This release unifies port **order** and **exposure** into a single per-instance `data.config.ports` value and makes exposure semantic — "what you see is what runs": a not-exposed port is hidden on the canvas, not wireable, and not runtime-overridable. The two older, separate mechanisms (`extensions.ui.portOrder` for order and `hideUnconnectedHandles` for visibility) are removed. A single combined "Ports" widget in the config panel now handles both reorder and expose/hide per port, and reserved ports (the `error` output and `trigger`/`tool` control ports) sort to the bottom automatically.
@@ -378,38 +378,49 @@ function executeInfo(command, context) {
378
378
  */
379
379
  function findPort(node, portId, preferDirection) {
380
380
  const metadata = node.data?.metadata;
381
- if (!metadata)
381
+ const config = node.data?.config;
382
+ if (!metadata && !config)
382
383
  return null;
383
- const outputPort = metadata.outputs?.find((p) => p.id === portId);
384
- const inputPort = metadata.inputs?.find((p) => p.id === portId);
385
- if (preferDirection === 'output') {
386
- if (outputPort)
387
- return { port: outputPort, direction: 'output' };
388
- if (inputPort)
389
- return { port: inputPort, direction: 'input' };
390
- }
391
- else if (preferDirection === 'input') {
384
+ // Resolve an output port from static metadata or config-driven ports. The
385
+ // latter are not in metadata.outputs: gateway branches live in config.branches
386
+ // and user-defined handles live in config.dynamicOutputs (both keyed by name).
387
+ const resolveOutput = () => {
388
+ const meta = metadata?.outputs?.find((p) => p.id === portId);
389
+ if (meta)
390
+ return meta;
391
+ const branch = config?.branches?.find((b) => b.name === portId);
392
+ if (branch)
393
+ return { id: portId, name: branch.label ?? portId, dataType: 'trigger' };
394
+ const dynamic = config?.dynamicOutputs?.find((p) => p.name === portId);
395
+ if (dynamic)
396
+ return { id: portId, name: dynamic.label ?? portId, dataType: dynamic.dataType };
397
+ return null;
398
+ };
399
+ // Resolve an input port from static metadata or config.dynamicInputs.
400
+ const resolveInput = () => {
401
+ const meta = metadata?.inputs?.find((p) => p.id === portId);
402
+ if (meta)
403
+ return meta;
404
+ const dynamic = config?.dynamicInputs?.find((p) => p.name === portId);
405
+ if (dynamic)
406
+ return { id: portId, name: dynamic.label ?? portId, dataType: dynamic.dataType };
407
+ return null;
408
+ };
409
+ const outputPort = resolveOutput();
410
+ const inputPort = resolveInput();
411
+ if (preferDirection === 'input') {
392
412
  if (inputPort)
393
413
  return { port: inputPort, direction: 'input' };
394
414
  if (outputPort)
395
415
  return { port: outputPort, direction: 'output' };
396
416
  }
397
417
  else {
418
+ // Default and explicit 'output' both prefer the output port first.
398
419
  if (outputPort)
399
420
  return { port: outputPort, direction: 'output' };
400
421
  if (inputPort)
401
422
  return { port: inputPort, direction: 'input' };
402
423
  }
403
- // Gateway nodes have dynamic branch ports stored in config.branches, not metadata.outputs
404
- if (metadata.type === 'gateway') {
405
- const branches = node.data.config?.branches;
406
- if (branches?.some((b) => b.name === portId)) {
407
- return {
408
- port: { id: portId, name: portId, dataType: 'trigger' },
409
- direction: 'output'
410
- };
411
- }
412
- }
413
424
  return null;
414
425
  }
415
426
  function executeConnect(command, context) {
@@ -483,6 +494,21 @@ function executeConnect(command, context) {
483
494
  const targetHandle = buildHandleId(targetNode.id, 'input', command.targetPort);
484
495
  // Generate edge ID
485
496
  const edgeId = `${sourceNode.id}-${sourceHandle}-${targetNode.id}-${targetHandle}`;
497
+ // Idempotency guard: re-applying the same connection (e.g. a second
498
+ // AI-assistant Apply that re-emits an existing edge) must not append a
499
+ // duplicate. Two edges sharing an id crash the canvas with Svelte's
500
+ // `each_key_duplicate`. Treat an existing identical connection as a no-op.
501
+ const alreadyConnected = workflow.edges.some((e) => e.id === edgeId ||
502
+ (e.source === sourceNode.id &&
503
+ e.target === targetNode.id &&
504
+ e.sourceHandle === sourceHandle &&
505
+ e.targetHandle === targetHandle));
506
+ if (alreadyConnected) {
507
+ return {
508
+ ok: true,
509
+ message: `Already connected ${toShortId(sourceNode.id)}:${command.sourcePort} → ${toShortId(targetNode.id)}:${command.targetPort}`
510
+ };
511
+ }
486
512
  // Build edge
487
513
  const edge = {
488
514
  id: edgeId,
@@ -37,6 +37,7 @@
37
37
  getEffectiveConfigEditOptions,
38
38
  fetchDynamicSchema,
39
39
  resolveExternalEditUrl,
40
+ resolveDynamicSchemaKey,
40
41
  invalidateSchemaCache,
41
42
  type DynamicSchemaResult
42
43
  } from '../services/dynamicSchemaService.js';
@@ -45,6 +46,7 @@
45
46
  import { getAvailableVariables } from '../services/variableService.js';
46
47
  import { logger } from '../utils/logger.js';
47
48
  import { mergeWithDefaults, cascadeClearAutocompleteDependents } from '../utils/formMerge.js';
49
+ import { applyFetchedSchema } from '../utils/schemaMerge.js';
48
50
 
49
51
  interface Props {
50
52
  /** Optional workflow node (if provided, schema and values are derived from it) */
@@ -120,6 +122,9 @@
120
122
  let dynamicSchemaLoading = $state(false);
121
123
  let dynamicSchemaError = $state<string | null>(null);
122
124
  let fetchedDynamicSchema = $state<ConfigSchema | null>(null);
125
+ // A uiSchema the endpoint returned alongside the schema (server-hydrated
126
+ // forms). Held next to fetchedDynamicSchema and cleared in lockstep with it.
127
+ let fetchedDynamicUiSchema = $state<UISchemaElement | null>(null);
123
128
 
124
129
  /**
125
130
  * Get the admin edit configuration for the node
@@ -154,38 +159,73 @@
154
159
  * Priority: fetchedDynamicSchema > direct schema prop > node metadata configSchema
155
160
  */
156
161
  const configSchema = $derived.by<ConfigSchema | undefined>(() => {
157
- // If we have a fetched dynamic schema, use it
162
+ const staticSchema = schema ?? (node?.data.metadata?.configSchema as ConfigSchema | undefined);
163
+ // A fetched dynamic schema is layered onto the static one per the endpoint's
164
+ // mergeStrategy/target (default 'replace' → fetched wins wholesale). With no
165
+ // static schema, the fetched schema is the form.
158
166
  if (fetchedDynamicSchema) {
159
- return fetchedDynamicSchema;
167
+ const endpoint = configEditOptions?.dynamicSchema;
168
+ return endpoint
169
+ ? applyFetchedSchema(staticSchema, fetchedDynamicSchema, endpoint)
170
+ : fetchedDynamicSchema;
160
171
  }
161
- // Otherwise use the direct prop or node metadata
162
- return schema ?? (node?.data.metadata?.configSchema as ConfigSchema | undefined);
172
+ return staticSchema;
163
173
  });
164
174
 
165
175
  /**
166
- * Get the UI schema from direct prop or node metadata
167
- * Priority: direct uiSchema prop > node metadata uiSchema
176
+ * Get the UI schema for the active configSchema.
177
+ * Priority: direct uiSchema prop > fetched dynamic uiSchema > node metadata.
178
+ *
179
+ * When the dynamic fetch returned a uiSchema, it wins over the node's static
180
+ * metadata uiSchema: the static one references only the static schema's
181
+ * properties, so it can't lay out a server-provided (hydrated) schema — its
182
+ * controls would point at fields that aren't rendered while the fetched
183
+ * fields would have no controls at all. The endpoint is expected to return a
184
+ * uiSchema describing the schema it served.
168
185
  */
169
186
  const configUISchema = $derived.by<UISchemaElement | undefined>(() => {
170
- return uiSchema ?? (node?.data.metadata?.uiSchema as UISchemaElement | undefined);
187
+ if (uiSchema) return uiSchema;
188
+ if (fetchedDynamicSchema && fetchedDynamicUiSchema) return fetchedDynamicUiSchema;
189
+ return node?.data.metadata?.uiSchema as UISchemaElement | undefined;
171
190
  });
172
191
 
173
192
  /**
174
- * Check if the node needs dynamic schema loading
175
- * Loads when: no static schema OR preferDynamicSchema is true
193
+ * Whether this node sources its schema dynamically: dynamic schema is
194
+ * configured and used, and it actually contributes to the form — either there
195
+ * is no static schema to fall back on, it is explicitly preferred, or it is
196
+ * configured to merge/target (in which case it layers onto the static schema
197
+ * rather than replacing it, so we fetch even when a static schema exists).
176
198
  */
177
- const needsDynamicSchemaLoad = $derived.by(() => {
178
- if (!node) return false;
199
+ const wantsDynamicSchema = $derived.by(() => {
200
+ if (!node || !useDynamicSchema) return false;
201
+ const endpoint = configEditOptions?.dynamicSchema;
202
+ const layersOntoStatic = endpoint?.mergeStrategy === 'merge' || endpoint?.target != null;
179
203
  const staticSchema = schema ?? node.data.metadata?.configSchema;
180
- // Need to load if: (no static schema OR preferDynamicSchema is true) AND dynamic schema is configured
181
- return (
182
- (!staticSchema || configEditOptions?.preferDynamicSchema === true) &&
183
- useDynamicSchema &&
184
- !fetchedDynamicSchema &&
185
- !dynamicSchemaLoading
186
- );
204
+ return !staticSchema || configEditOptions?.preferDynamicSchema === true || layersOntoStatic;
205
+ });
206
+
207
+ /**
208
+ * Resolved fetch key for the dynamic schema endpoint. Read from the committed
209
+ * `node.data.config` (not the in-flight `edits`/`configValues`), so it moves
210
+ * at the commit boundary: a field edit reaches it only once `handleFormBlur`
211
+ * fires `onChange` and the parent writes the value back onto the node. It
212
+ * therefore recomputes when a committed config value the endpoint's
213
+ * parameterMapping references changes (e.g. a trigger node's event_type),
214
+ * driving the auto-refetch effect below. Relies on `node` being a deep
215
+ * reactive proxy whose `.data.config` is mutated in place; a replaced node or
216
+ * a plain snapshot would not re-run this derived.
217
+ */
218
+ const dynamicSchemaKey = $derived.by<string | null>(() => {
219
+ if (!node || !configEditOptions?.dynamicSchema || !wantsDynamicSchema) return null;
220
+ return resolveDynamicSchemaKey(configEditOptions.dynamicSchema, node, workflowId);
187
221
  });
188
222
 
223
+ /**
224
+ * Key of the schema currently loaded or in flight. Guards the effect from
225
+ * re-fetching a schema whose inputs have not changed.
226
+ */
227
+ let loadedSchemaKey = $state<string | null>(null);
228
+
189
229
  /**
190
230
  * Get the current configuration from node or direct prop
191
231
  */
@@ -241,6 +281,7 @@
241
281
 
242
282
  if (result.success && result.schema) {
243
283
  fetchedDynamicSchema = result.schema;
284
+ fetchedDynamicUiSchema = result.uiSchema ?? null;
244
285
  } else {
245
286
  dynamicSchemaError =
246
287
  result.error ?? configEditOptions.errorMessage ?? 'Failed to load configuration schema';
@@ -262,8 +303,9 @@
262
303
  if (!node || !configEditOptions?.dynamicSchema) return;
263
304
 
264
305
  // Invalidate the cache first
265
- invalidateSchemaCache(node, configEditOptions.dynamicSchema);
306
+ invalidateSchemaCache(node, configEditOptions.dynamicSchema, workflowId);
266
307
  fetchedDynamicSchema = null;
308
+ fetchedDynamicUiSchema = null;
267
309
 
268
310
  // Reload the schema
269
311
  await loadDynamicSchema();
@@ -294,12 +336,31 @@
294
336
  }
295
337
 
296
338
  /**
297
- * Auto-load dynamic schema on mount if needed
339
+ * Load — and reload — the dynamic schema when its resolved key changes.
340
+ *
341
+ * Covers both the initial fetch (loadedSchemaKey starts null) and refetching
342
+ * after a config value the endpoint depends on changes (e.g. picking a
343
+ * different trigger event_type). A load already in flight is left to finish;
344
+ * the effect re-runs when it settles and picks up any newer key then.
345
+ *
346
+ * The `dynamicSchemaLoading` read is load-bearing in both directions: it
347
+ * guards against re-entering while a fetch is in flight, AND — because it is
348
+ * a tracked read — flipping back to false on settle is what re-runs this
349
+ * effect to pick up a newer key. Don't hoist or drop it; the settle-and-
350
+ * refetch depends on it.
351
+ *
352
+ * loadedSchemaKey is set BEFORE the fetch (not after success) on purpose: a
353
+ * failed load consumes the key so a persistent error can't loop the effect
354
+ * into a refetch storm. Recovery from an error is manual, via
355
+ * refreshDynamicSchema().
298
356
  */
299
357
  $effect(() => {
300
- if (needsDynamicSchemaLoad) {
301
- loadDynamicSchema();
358
+ const key = dynamicSchemaKey;
359
+ if (key === null || key === loadedSchemaKey || dynamicSchemaLoading) {
360
+ return;
302
361
  }
362
+ loadedSchemaKey = key;
363
+ loadDynamicSchema();
303
364
  });
304
365
 
305
366
  /**
@@ -336,7 +397,11 @@
336
397
  */
337
398
  function handleFormBlur(): void {
338
399
  if (onChange) {
339
- onChange({ ...configValues });
400
+ // Spread `initialConfig` first so config keys the active schema doesn't
401
+ // own (e.g. after a dynamic schema narrows the field set) pass through
402
+ // untouched instead of being silently dropped; `configValues` then wins
403
+ // for every field the schema actually renders.
404
+ onChange({ ...initialConfig, ...configValues });
340
405
  // Discharge the edits buffer at the commit boundary. Subsequent prop
341
406
  // changes (parent absorbing the commit, undo/redo, collaboration) then
342
407
  // flow through `initialConfig` cleanly instead of being shadowed by a
@@ -350,9 +415,12 @@
350
415
  * Collects config values and optionally saves the workflow.
351
416
  */
352
417
  async function handleSave(): Promise<void> {
353
- // Collect all form values including hidden fields
418
+ // Collect all form values including hidden fields. Start from
419
+ // `initialConfig` so keys the active schema doesn't own survive the save
420
+ // (see handleFormBlur); `configValues` and the DOM scrape below then take
421
+ // precedence for every field the schema renders.
354
422
  const form = document.querySelector('.config-form');
355
- const updatedConfig: Record<string, unknown> = { ...configValues };
423
+ const updatedConfig: Record<string, unknown> = { ...initialConfig, ...configValues };
356
424
 
357
425
  if (form) {
358
426
  const inputs = form.querySelectorAll('input, select, textarea');
@@ -29,18 +29,22 @@
29
29
 
30
30
  const isCollapsible = $derived(group.collapsible !== false);
31
31
  const isDefaultOpen = $derived(group.defaultOpen !== false);
32
+ const headerIcon = $derived(group.icon ?? 'heroicons:adjustments-horizontal');
32
33
  </script>
33
34
 
34
35
  {#if isCollapsible}
35
36
  <details class="flowdrop-details form-fieldset" open={isDefaultOpen}>
36
37
  <summary class="flowdrop-details__summary form-fieldset__summary">
37
- <div class="form-fieldset__label">
38
- <Icon icon="heroicons:chevron-right" class="form-fieldset__chevron" />
38
+ <span class="form-fieldset__label">
39
+ <Icon icon={headerIcon} class="form-fieldset__icon" />
39
40
  <span class="form-fieldset__title">{group.label}</span>
40
- </div>
41
- {#if group.description}
42
- <span class="form-fieldset__badge">{group.description}</span>
43
- {/if}
41
+ </span>
42
+ <span class="form-fieldset__meta">
43
+ {#if group.description}
44
+ <span class="form-fieldset__badge">{group.description}</span>
45
+ {/if}
46
+ <Icon icon="heroicons:chevron-right" class="form-fieldset__chevron" />
47
+ </span>
44
48
  </summary>
45
49
  <div class="flowdrop-details__content form-fieldset__content">
46
50
  <div class="form-fieldset__fields">
@@ -62,18 +66,48 @@
62
66
 
63
67
  <style>
64
68
  /* ============================================
65
- COLLAPSIBLE FIELDSET
66
- Extends .flowdrop-details from base.css
69
+ COLLAPSIBLE FIELDSET — filled header bar
70
+ Extends .flowdrop-details from base.css, overriding the summary
71
+ into a distinct header bar (subtle fill + bottom divider when open)
72
+ over a card body. Scoped to .form-fieldset so other .flowdrop-details
73
+ consumers (e.g. NodeSidebar) are unaffected.
67
74
  ============================================ */
68
75
 
69
76
  .form-fieldset__summary {
70
- gap: var(--fd-space-xs);
77
+ gap: var(--fd-space-sm);
78
+ padding: var(--fd-space-md) var(--fd-space-xl);
79
+ background: var(--fd-subtle);
80
+ border-radius: 0;
81
+ }
82
+
83
+ .form-fieldset__summary:hover {
84
+ background-color: var(--fd-muted);
85
+ }
86
+
87
+ /* Divider between header bar and body — only while expanded */
88
+ details.form-fieldset[open] > .form-fieldset__summary {
89
+ border-bottom: 1px solid var(--fd-border-muted);
71
90
  }
72
91
 
73
92
  .form-fieldset__label {
74
93
  display: flex;
75
94
  align-items: center;
76
95
  gap: var(--fd-space-xs);
96
+ min-width: 0;
97
+ }
98
+
99
+ .form-fieldset__meta {
100
+ display: flex;
101
+ align-items: center;
102
+ gap: var(--fd-space-sm);
103
+ flex-shrink: 0;
104
+ }
105
+
106
+ .form-fieldset :global(.form-fieldset__icon) {
107
+ width: 1rem;
108
+ height: 1rem;
109
+ color: var(--fd-muted-foreground);
110
+ flex-shrink: 0;
77
111
  }
78
112
 
79
113
  .form-fieldset__title {
@@ -106,7 +140,7 @@
106
140
  }
107
141
 
108
142
  .form-fieldset__content {
109
- padding-top: var(--fd-space-xs);
143
+ padding: var(--fd-space-xl);
110
144
  }
111
145
 
112
146
  .form-fieldset__fields {
@@ -37,7 +37,7 @@
37
37
  value = 0,
38
38
  min = 0,
39
39
  max = 100,
40
- step = 1,
40
+ step,
41
41
  required = false,
42
42
  disabled = false,
43
43
  ariaDescribedBy,
@@ -56,6 +56,40 @@
56
56
  return isNaN(parsed) ? min : parsed;
57
57
  });
58
58
 
59
+ /** Count the decimal places of a finite number (e.g. 0.7 -> 1, 3 -> 0). */
60
+ function decimalPlaces(n: number): number {
61
+ if (!Number.isFinite(n)) return 0;
62
+ const text = String(n);
63
+ const dot = text.indexOf('.');
64
+ return dot === -1 ? 0 : text.length - dot - 1;
65
+ }
66
+
67
+ /**
68
+ * Resolve the step the native input should use.
69
+ *
70
+ * The backend often omits `step`, and a default of 1 makes the browser snap a
71
+ * fractional value (0.7) to the nearest integer (1) — the thumb jumps to that
72
+ * snapped position while our fill/label still show the raw value, so they
73
+ * disagree on load. When no step is given, infer one from the precision of the
74
+ * initial value/min/max so a value like 0.7 yields a step of 0.1.
75
+ *
76
+ * Granularity is a property of the field, not the live value, so it is captured
77
+ * ONCE. Recomputing from the live value would coarsen the step back to 1 the
78
+ * instant the user drags onto a whole number (e.g. 1.0), stranding the slider
79
+ * on integer increments.
80
+ */
81
+ const initialNumeric = typeof value === 'number' ? value : Number(value);
82
+ const inferredStep = ((): number => {
83
+ const places = Math.max(
84
+ decimalPlaces(Number.isNaN(initialNumeric) ? min : initialNumeric),
85
+ decimalPlaces(min),
86
+ decimalPlaces(max)
87
+ );
88
+ return places > 0 ? Math.pow(10, -places) : 1;
89
+ })();
90
+
91
+ const effectiveStep = $derived(typeof step === 'number' && step > 0 ? step : inferredStep);
92
+
59
93
  /**
60
94
  * Compute the percentage position for the filled track
61
95
  * Used to show visual progress of the slider
@@ -79,14 +113,20 @@
79
113
 
80
114
  <div class="form-range-container">
81
115
  <div class="form-range-slider">
116
+ <!--
117
+ Order matters: min/max/step must be applied BEFORE value. A range input
118
+ defaults to step=1, so setting value=0.7 first snaps it to 1, and the later
119
+ step=0.1 does not re-validate the already-snapped value. Setting the bounds
120
+ and step first lets the value land truthfully.
121
+ -->
82
122
  <input
83
123
  {id}
84
124
  type="range"
85
125
  class="form-range-field"
86
- value={numericValue}
87
126
  {min}
88
127
  {max}
89
- {step}
128
+ step={effectiveStep}
129
+ value={numericValue}
90
130
  {disabled}
91
131
  {required}
92
132
  aria-describedby={ariaDescribedBy}
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @module services/dynamicSchemaService
7
7
  */
8
- import type { ConfigSchema, DynamicSchemaEndpoint, ExternalEditLink, ConfigEditOptions, WorkflowNode } from '../types/index.js';
8
+ import type { ConfigSchema, DynamicSchemaEndpoint, ExternalEditLink, ConfigEditOptions, UISchemaElement, WorkflowNode } from '../types/index.js';
9
9
  import type { EndpointConfig } from '../config/endpoints.js';
10
10
  /**
11
11
  * Result of a dynamic schema fetch operation
@@ -15,11 +15,33 @@ export interface DynamicSchemaResult {
15
15
  success: boolean;
16
16
  /** The fetched config schema (if successful) */
17
17
  schema?: ConfigSchema;
18
+ /**
19
+ * The fetched uiSchema, when the endpoint returns one alongside the schema.
20
+ * Lets a server-hydrated response carry its own field grouping/layout so the
21
+ * form isn't stuck with the node's static-metadata uiSchema (which only
22
+ * references the static schema's properties).
23
+ */
24
+ uiSchema?: UISchemaElement;
18
25
  /** Error message (if failed) */
19
26
  error?: string;
20
27
  /** Whether the schema was loaded from cache */
21
28
  fromCache?: boolean;
22
29
  }
30
+ /**
31
+ * Resolves the fetch key for a node's dynamic-schema endpoint: the endpoint URL
32
+ * with all template variables substituted from the node context.
33
+ *
34
+ * The key changes whenever a config value the endpoint's `parameterMapping`
35
+ * references changes (e.g. a trigger node's `event_type`). Callers watch it to
36
+ * refetch the schema when the inputs that shape it change, keeping the rendered
37
+ * form in step with the current configuration.
38
+ *
39
+ * @param endpoint - The dynamic schema endpoint configuration
40
+ * @param node - The workflow node instance
41
+ * @param workflowId - Optional workflow ID for context
42
+ * @returns The resolved endpoint URL, used as a reactive refetch key
43
+ */
44
+ export declare function resolveDynamicSchemaKey(endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): string;
23
45
  /**
24
46
  * Fetches a dynamic configuration schema from a REST endpoint.
25
47
  *
@@ -82,10 +104,15 @@ export declare function clearSchemaCache(pattern?: string): void;
82
104
  /**
83
105
  * Invalidates a specific schema cache entry for a node.
84
106
  *
107
+ * The workflow ID must match the value passed when the schema was fetched:
108
+ * endpoints whose URL references `{workflowId}` resolve to a different cache key
109
+ * without it, so omitting it here would miss the entry the fetch created.
110
+ *
85
111
  * @param node - The workflow node to invalidate cache for
86
112
  * @param endpoint - The dynamic schema endpoint configuration
113
+ * @param workflowId - Optional workflow ID, matching the fetch context
87
114
  */
88
- export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint): void;
115
+ export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint, workflowId?: string): void;
89
116
  /**
90
117
  * Checks if a node has config edit options configured.
91
118
  *
@@ -104,6 +104,44 @@ function generateCacheKey(endpoint, context) {
104
104
  const url = resolveTemplate(endpoint.url, endpoint.parameterMapping, context);
105
105
  return `schema:${url}`;
106
106
  }
107
+ /**
108
+ * Builds the template-resolution context for a node.
109
+ *
110
+ * Shared by every function that resolves a dynamic-schema URL, external-edit
111
+ * URL, or cache key, so they all read identical values — and therefore compute
112
+ * matching keys — from a single place.
113
+ *
114
+ * @param node - The workflow node instance
115
+ * @param workflowId - Optional workflow ID for context
116
+ * @returns The node context used for template resolution
117
+ */
118
+ function buildNodeContext(node, workflowId) {
119
+ return {
120
+ id: node.id,
121
+ type: node.type,
122
+ metadata: node.data.metadata,
123
+ config: node.data.config,
124
+ extensions: node.data.extensions,
125
+ workflowId
126
+ };
127
+ }
128
+ /**
129
+ * Resolves the fetch key for a node's dynamic-schema endpoint: the endpoint URL
130
+ * with all template variables substituted from the node context.
131
+ *
132
+ * The key changes whenever a config value the endpoint's `parameterMapping`
133
+ * references changes (e.g. a trigger node's `event_type`). Callers watch it to
134
+ * refetch the schema when the inputs that shape it change, keeping the rendered
135
+ * form in step with the current configuration.
136
+ *
137
+ * @param endpoint - The dynamic schema endpoint configuration
138
+ * @param node - The workflow node instance
139
+ * @param workflowId - Optional workflow ID for context
140
+ * @returns The resolved endpoint URL, used as a reactive refetch key
141
+ */
142
+ export function resolveDynamicSchemaKey(endpoint, node, workflowId) {
143
+ return resolveTemplate(endpoint.url, endpoint.parameterMapping, buildNodeContext(node, workflowId));
144
+ }
107
145
  /**
108
146
  * Checks if a cached schema is still valid (not expired).
109
147
  *
@@ -138,14 +176,7 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
138
176
  */
139
177
  export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflowId) {
140
178
  // Build the context from the node
141
- const context = {
142
- id: node.id,
143
- type: node.type,
144
- metadata: node.data.metadata,
145
- config: node.data.config,
146
- extensions: node.data.extensions,
147
- workflowId
148
- };
179
+ const context = buildNodeContext(node, workflowId);
149
180
  // Generate cache key
150
181
  const cacheKey = generateCacheKey(endpoint, context);
151
182
  // Check cache first (if caching is enabled)
@@ -155,6 +186,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
155
186
  return {
156
187
  success: true,
157
188
  schema: cached.schema,
189
+ uiSchema: cached.uiSchema,
158
190
  fromCache: true
159
191
  };
160
192
  }
@@ -232,10 +264,15 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
232
264
  error: 'Invalid schema format received from endpoint'
233
265
  };
234
266
  }
267
+ // A companion uiSchema may ride alongside the schema (server-hydrated
268
+ // forms). Look for it next to wherever the schema was found — sibling of
269
+ // the envelope, or nested in the same `data`/`schema` wrapper.
270
+ const uiSchema = (data.uiSchema ?? data.data?.uiSchema ?? data.schema?.uiSchema);
235
271
  // Cache the schema (if caching is enabled)
236
272
  if (endpoint.cacheSchema !== false) {
237
273
  schemaCache.set(cacheKey, {
238
274
  schema,
275
+ uiSchema,
239
276
  cachedAt: Date.now(),
240
277
  cacheKey
241
278
  });
@@ -243,6 +280,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
243
280
  return {
244
281
  success: true,
245
282
  schema,
283
+ uiSchema,
246
284
  fromCache: false
247
285
  };
248
286
  }
@@ -288,14 +326,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
288
326
  */
289
327
  export function resolveExternalEditUrl(link, node, workflowId, callbackUrl) {
290
328
  // Build the context from the node
291
- const context = {
292
- id: node.id,
293
- type: node.type,
294
- metadata: node.data.metadata,
295
- config: node.data.config,
296
- extensions: node.data.extensions,
297
- workflowId
298
- };
329
+ const context = buildNodeContext(node, workflowId);
299
330
  // Resolve the URL with template variables
300
331
  let url = resolveTemplate(link.url, link.parameterMapping, context);
301
332
  // Append callback URL if configured
@@ -367,18 +398,16 @@ export function clearSchemaCache(pattern) {
367
398
  /**
368
399
  * Invalidates a specific schema cache entry for a node.
369
400
  *
401
+ * The workflow ID must match the value passed when the schema was fetched:
402
+ * endpoints whose URL references `{workflowId}` resolve to a different cache key
403
+ * without it, so omitting it here would miss the entry the fetch created.
404
+ *
370
405
  * @param node - The workflow node to invalidate cache for
371
406
  * @param endpoint - The dynamic schema endpoint configuration
407
+ * @param workflowId - Optional workflow ID, matching the fetch context
372
408
  */
373
- export function invalidateSchemaCache(node, endpoint) {
374
- const context = {
375
- id: node.id,
376
- type: node.type,
377
- metadata: node.data.metadata,
378
- config: node.data.config,
379
- extensions: node.data.extensions
380
- };
381
- const cacheKey = generateCacheKey(endpoint, context);
409
+ export function invalidateSchemaCache(node, endpoint, workflowId) {
410
+ const cacheKey = generateCacheKey(endpoint, buildNodeContext(node, workflowId));
382
411
  schemaCache.delete(cacheKey);
383
412
  }
384
413
  /**
@@ -478,9 +478,14 @@ export class WorkflowStore {
478
478
  }
479
479
  /** Add an edge. */
480
480
  addEdge(edge) {
481
- this.#pushToHistory('Add connection');
482
481
  if (!this.#workflow)
483
482
  return;
483
+ // Never append an edge whose id already exists — SvelteFlow keys edges by id
484
+ // and a duplicate throws `each_key_duplicate`, taking down the canvas. Guard
485
+ // before touching history so a no-op stays a no-op.
486
+ if (this.#workflow.edges.some((e) => e.id === edge.id))
487
+ return;
488
+ this.#pushToHistory('Add connection');
484
489
  this.#workflow = {
485
490
  ...this.#workflow,
486
491
  edges: [...this.#workflow.edges, edge],
@@ -415,6 +415,35 @@ export interface DynamicSchemaEndpoint {
415
415
  * @default true
416
416
  */
417
417
  cacheSchema?: boolean;
418
+ /**
419
+ * How the fetched schema combines with the node's static schema
420
+ * (the direct `schema` prop or `metadata.configSchema`).
421
+ *
422
+ * - `"replace"` (default): the fetched schema is used as-is and the static
423
+ * schema is ignored. This is the historical behaviour.
424
+ * - `"merge"`: the fetched schema is layered onto the static schema —
425
+ * properties are merged (fetched wins per key) and `required` is unioned —
426
+ * so the endpoint only has to return the fields it actually drives.
427
+ *
428
+ * When there is no static schema to combine with, both strategies behave
429
+ * identically: the fetched schema is the form.
430
+ *
431
+ * @default "replace"
432
+ */
433
+ mergeStrategy?: 'replace' | 'merge';
434
+ /**
435
+ * Restricts the fetched schema to a region of the static schema instead of
436
+ * the whole form. A dot-path of property keys descending through nested
437
+ * object `properties` (e.g. `"advanced"` or `"advanced.retry"`); the fetched
438
+ * schema is spliced in at that location and every other field stays static.
439
+ *
440
+ * Use this to make just one section (or one field) server-driven while
441
+ * authoring the rest of the form locally. `mergeStrategy` then decides whether
442
+ * the fetched schema replaces or merges into the property at that path.
443
+ *
444
+ * When omitted, the fetch applies at the form root (per `mergeStrategy`).
445
+ */
446
+ target?: string;
418
447
  }
419
448
  /**
420
449
  * External edit link configuration
@@ -124,6 +124,11 @@ export interface UISchemaGroup extends UISchemaElementBase {
124
124
  * @default true
125
125
  */
126
126
  defaultOpen?: boolean;
127
+ /**
128
+ * Optional Iconify icon name shown in the group's header bar.
129
+ * Falls back to a neutral default when omitted.
130
+ */
131
+ icon?: string;
127
132
  }
128
133
  /**
129
134
  * Union type of all supported UISchema elements.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Combines a dynamically-fetched config schema with a node's static schema.
3
+ *
4
+ * Dynamic schema used to be all-or-nothing: the fetched schema replaced the
5
+ * whole form, so an endpoint had to re-serve every field even to drive one, and
6
+ * a narrower response silently dropped fields (and their values) the form no
7
+ * longer rendered. `applyFetchedSchema` lets the fetch instead *layer onto* the
8
+ * static schema — merging fields or targeting a single region — so the rest of
9
+ * the form stays exactly as authored.
10
+ *
11
+ * Kept as a standalone pure function so it can be unit-tested directly against
12
+ * the same code `ConfigForm` runs, rather than through the component.
13
+ */
14
+ import type { ConfigSchema, DynamicSchemaEndpoint } from '../types/index.js';
15
+ /**
16
+ * Resolves the schema `ConfigForm` should render from a node's static schema
17
+ * and a freshly-fetched dynamic schema, per the endpoint's `mergeStrategy` and
18
+ * `target`.
19
+ *
20
+ * @param base - The node's static schema (`schema` prop or `metadata.configSchema`), if any
21
+ * @param fetched - The schema returned by the dynamic endpoint
22
+ * @param endpoint - Supplies `mergeStrategy` (default `"replace"`) and optional `target`
23
+ * @returns The effective schema to render
24
+ */
25
+ export declare function applyFetchedSchema(base: ConfigSchema | undefined, fetched: ConfigSchema, endpoint: Pick<DynamicSchemaEndpoint, 'mergeStrategy' | 'target'>): ConfigSchema;
@@ -0,0 +1,61 @@
1
+ /** Union two `required` arrays, dropping duplicates; `undefined` when neither has entries. */
2
+ function unionRequired(a, b) {
3
+ if (!a?.length && !b?.length)
4
+ return undefined;
5
+ return Array.from(new Set([...(a ?? []), ...(b ?? [])]));
6
+ }
7
+ /**
8
+ * Layers `fetched` onto `base`: fetched top-level attributes win, `properties`
9
+ * are shallow-merged per key (a field is wholly static or wholly fetched, never
10
+ * half of each), and `required` is unioned.
11
+ */
12
+ function mergeNodes(base, fetched) {
13
+ const merged = { ...base, ...fetched };
14
+ if (base.properties || fetched.properties) {
15
+ merged.properties = { ...(base.properties ?? {}), ...(fetched.properties ?? {}) };
16
+ }
17
+ const required = unionRequired(base.required, fetched.required);
18
+ if (required)
19
+ merged.required = required;
20
+ else
21
+ delete merged.required;
22
+ return merged;
23
+ }
24
+ /**
25
+ * Places `fetched` at `segments` within `base`, cloning each node along the
26
+ * path so the input is never mutated. At the leaf the strategy decides between
27
+ * replacing the existing node outright and merging into it.
28
+ */
29
+ function spliceAtPath(base, fetched, segments, strategy) {
30
+ if (segments.length === 0) {
31
+ return strategy === 'merge' ? mergeNodes(base, fetched) : fetched;
32
+ }
33
+ const [head, ...rest] = segments;
34
+ const properties = base.properties ?? {};
35
+ const existing = (properties[head] ?? {});
36
+ return {
37
+ ...base,
38
+ properties: {
39
+ ...properties,
40
+ [head]: spliceAtPath(existing, fetched, rest, strategy)
41
+ }
42
+ };
43
+ }
44
+ /**
45
+ * Resolves the schema `ConfigForm` should render from a node's static schema
46
+ * and a freshly-fetched dynamic schema, per the endpoint's `mergeStrategy` and
47
+ * `target`.
48
+ *
49
+ * @param base - The node's static schema (`schema` prop or `metadata.configSchema`), if any
50
+ * @param fetched - The schema returned by the dynamic endpoint
51
+ * @param endpoint - Supplies `mergeStrategy` (default `"replace"`) and optional `target`
52
+ * @returns The effective schema to render
53
+ */
54
+ export function applyFetchedSchema(base, fetched, endpoint) {
55
+ const strategy = endpoint.mergeStrategy ?? 'replace';
56
+ // Nothing to combine with: the fetched schema is the whole form.
57
+ if (!base)
58
+ return fetched;
59
+ const segments = endpoint.target ? endpoint.target.split('.').filter(Boolean) : [];
60
+ return spliceAtPath(base, fetched, segments, strategy);
61
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A drop-in visual workflow editor for any web application. You own the backend. You own the data. You own the orchestration.",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "2.0.0-beta.6",
6
+ "version": "2.0.0-beta.7",
7
7
  "author": "Shibin Das (D34dMan)",
8
8
  "bugs": {
9
9
  "url": "https://github.com/flowdrop-io/flowdrop/issues"