@flowdrop/flowdrop 2.16.0 → 2.18.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 (130) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +6 -1
  3. package/dist/api/enhanced-client.d.ts +3 -1
  4. package/dist/api/enhanced-client.js +4 -2
  5. package/dist/commands/executor.js +9 -0
  6. package/dist/commands/storeIntegration.svelte.js +6 -0
  7. package/dist/commands/types.d.ts +8 -0
  8. package/dist/components/App.svelte +414 -105
  9. package/dist/components/App.svelte.d.ts +31 -0
  10. package/dist/components/CanvasToolbar.svelte +40 -3
  11. package/dist/components/CanvasToolbar.svelte.d.ts +5 -1
  12. package/dist/components/ConnectPortPicker.svelte +8 -4
  13. package/dist/components/DoctorMenu.svelte +208 -126
  14. package/dist/components/FlowDropZone.svelte +7 -1
  15. package/dist/components/FlowDropZone.svelte.d.ts +5 -0
  16. package/dist/components/ImpactConfirm.svelte +554 -0
  17. package/dist/components/ImpactConfirm.svelte.d.ts +22 -0
  18. package/dist/components/Input.svelte +8 -2
  19. package/dist/components/LockBanner.svelte +76 -0
  20. package/dist/components/LockBanner.svelte.d.ts +14 -0
  21. package/dist/components/LockFence.svelte +33 -0
  22. package/dist/components/LockFence.svelte.d.ts +19 -0
  23. package/dist/components/Navbar.svelte +77 -9
  24. package/dist/components/Navbar.svelte.d.ts +10 -0
  25. package/dist/components/NodeSidebar.svelte +36 -15
  26. package/dist/components/NodeSidebar.svelte.d.ts +2 -0
  27. package/dist/components/NodeSwapPicker.svelte +4 -14
  28. package/dist/components/RunBar.svelte +50 -3
  29. package/dist/components/RunBar.svelte.d.ts +5 -0
  30. package/dist/components/RunInputsDialog.svelte +198 -0
  31. package/dist/components/RunInputsDialog.svelte.d.ts +34 -0
  32. package/dist/components/Textarea.svelte +7 -1
  33. package/dist/components/WorkflowCompareDialog.svelte +177 -0
  34. package/dist/components/WorkflowCompareDialog.svelte.d.ts +10 -0
  35. package/dist/components/WorkflowEditor.svelte +120 -15
  36. package/dist/components/WorkflowEditor.svelte.d.ts +6 -0
  37. package/dist/components/WorkflowInterfaceEditor.svelte +17 -4
  38. package/dist/components/WorkflowInterfaceEntryCard.svelte +40 -7
  39. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +2 -0
  40. package/dist/components/WorkflowPlaygroundSettings.svelte +9 -1
  41. package/dist/components/form/FieldFactory.svelte +13 -6
  42. package/dist/components/form/FormArray.svelte +0 -1
  43. package/dist/components/form/FormArrayRows.svelte +4 -4
  44. package/dist/components/form/FormCodeEditor.svelte +18 -2
  45. package/dist/components/form/FormMarkdownEditor.svelte +22 -8
  46. package/dist/components/form/FormTemplateEditor.svelte +17 -1
  47. package/dist/components/form/readOnly.d.ts +13 -0
  48. package/dist/components/form/readOnly.js +18 -0
  49. package/dist/components/nodes/CaptionNode.svelte +1 -0
  50. package/dist/components/nodes/NodeCard.svelte +2 -2
  51. package/dist/components/primitives/Checkbox.svelte +5 -1
  52. package/dist/components/primitives/Select.svelte +6 -1
  53. package/dist/components/primitives/Switch.svelte +5 -1
  54. package/dist/components/toast/DismissibleToast.svelte +25 -6
  55. package/dist/components/toast/DismissibleToast.svelte.d.ts +3 -0
  56. package/dist/config/endpoints.d.ts +7 -0
  57. package/dist/config/endpoints.js +2 -1
  58. package/dist/editor/connectCandidates.d.ts +3 -0
  59. package/dist/editor/connectCandidates.js +14 -5
  60. package/dist/editor/index.d.ts +2 -1
  61. package/dist/editor/index.js +1 -1
  62. package/dist/helpers/workflowEditorHelper.d.ts +15 -0
  63. package/dist/helpers/workflowEditorHelper.js +9 -0
  64. package/dist/index.d.ts +2 -0
  65. package/dist/messages/defaults.d.ts +145 -0
  66. package/dist/messages/defaults.js +139 -1
  67. package/dist/openapi/v1/openapi.yaml +492 -0
  68. package/dist/registry/nodeComponentRegistry.d.ts +5 -0
  69. package/dist/schemas/v1/workflow.schema.json +2 -0
  70. package/dist/services/draftStorage.d.ts +24 -10
  71. package/dist/services/draftStorage.js +60 -35
  72. package/dist/services/globalSave.d.ts +45 -10
  73. package/dist/services/globalSave.js +296 -32
  74. package/dist/services/impactGate.d.ts +38 -0
  75. package/dist/services/impactGate.js +72 -0
  76. package/dist/services/impactService.d.ts +45 -0
  77. package/dist/services/impactService.js +157 -0
  78. package/dist/services/runsService.d.ts +9 -0
  79. package/dist/services/runsService.js +13 -0
  80. package/dist/services/toastQueue.d.ts +9 -0
  81. package/dist/services/toastService.d.ts +4 -0
  82. package/dist/services/toastService.js +9 -3
  83. package/dist/services/workflowLaunchService.d.ts +6 -0
  84. package/dist/services/workflowLaunchService.js +5 -1
  85. package/dist/settings/index.d.ts +2 -2
  86. package/dist/settings/index.js +1 -1
  87. package/dist/stores/doctorStore.svelte.d.ts +24 -1
  88. package/dist/stores/doctorStore.svelte.js +105 -2
  89. package/dist/stores/historyStore.svelte.d.ts +12 -2
  90. package/dist/stores/historyStore.svelte.js +25 -2
  91. package/dist/stores/instanceContainer.svelte.d.ts +23 -0
  92. package/dist/stores/instanceContainer.svelte.js +32 -2
  93. package/dist/stores/lockStore.svelte.d.ts +39 -0
  94. package/dist/stores/lockStore.svelte.js +109 -0
  95. package/dist/stores/runController.svelte.d.ts +2 -0
  96. package/dist/stores/runController.svelte.js +27 -11
  97. package/dist/stores/saveConflictStore.svelte.d.ts +62 -0
  98. package/dist/stores/saveConflictStore.svelte.js +169 -0
  99. package/dist/stores/workflowStore.svelte.d.ts +14 -4
  100. package/dist/stores/workflowStore.svelte.js +55 -18
  101. package/dist/styles/base.css +6 -0
  102. package/dist/styles/toast.css +10 -1
  103. package/dist/svelte-app.d.ts +33 -0
  104. package/dist/svelte-app.js +178 -22
  105. package/dist/types/doctor.d.ts +3 -1
  106. package/dist/types/events.d.ts +37 -0
  107. package/dist/types/events.js +2 -0
  108. package/dist/types/impact.d.ts +77 -0
  109. package/dist/types/impact.js +7 -0
  110. package/dist/types/lock.d.ts +35 -0
  111. package/dist/types/lock.js +13 -0
  112. package/dist/types/navbar.d.ts +6 -0
  113. package/dist/types/settings.d.ts +31 -0
  114. package/dist/types/settings.js +132 -0
  115. package/dist/utils/draftRestore.d.ts +27 -0
  116. package/dist/utils/draftRestore.js +36 -0
  117. package/dist/utils/interfaceTags.js +4 -1
  118. package/dist/utils/links.d.ts +29 -0
  119. package/dist/utils/links.js +63 -0
  120. package/dist/utils/nodeSearch.d.ts +10 -0
  121. package/dist/utils/nodeSearch.js +37 -0
  122. package/dist/utils/runOffer.d.ts +21 -0
  123. package/dist/utils/runOffer.js +13 -0
  124. package/dist/utils/workflowCompare.d.ts +35 -0
  125. package/dist/utils/workflowCompare.js +84 -0
  126. package/dist/utils/workflowInterface.d.ts +26 -1
  127. package/dist/utils/workflowInterface.js +91 -11
  128. package/dist/webmcp/runtime.js +16 -3
  129. package/dist/webmcp/types.d.ts +11 -1
  130. package/package.json +3 -2
@@ -6,7 +6,7 @@
6
6
 
7
7
  <script lang="ts">
8
8
  import type { ContextMenuOptions } from '../editor/contextMenu.js';
9
- import { onMount, tick, untrack } from 'svelte';
9
+ import { onDestroy, onMount, tick, untrack } from 'svelte';
10
10
  import { MediaQuery } from 'svelte/reactivity';
11
11
  import { on } from 'svelte/events';
12
12
  import MainLayout from './layouts/MainLayout.svelte';
@@ -21,11 +21,18 @@
21
21
  import ConfigForm from './ConfigForm.svelte';
22
22
  import NodeInspector from './NodeInspector.svelte';
23
23
  import WorkflowSettingsPanel from './WorkflowSettingsPanel.svelte';
24
+ import WorkflowCompareDialog from './WorkflowCompareDialog.svelte';
25
+ import RunInputsDialog from './RunInputsDialog.svelte';
24
26
  import ConfigPanel from './ConfigPanel.svelte';
25
27
  import WorkflowInterfaceEditor from './WorkflowInterfaceEditor.svelte';
26
28
  import WorkflowPlaygroundSettings from './WorkflowPlaygroundSettings.svelte';
27
- import { withPlaygroundChat, withoutInterfaceTurns } from '../utils/playgroundChat.js';
29
+ import {
30
+ resolvePlaygroundChat,
31
+ withPlaygroundChat,
32
+ withoutInterfaceTurns
33
+ } from '../utils/playgroundChat.js';
28
34
  import ReadOnlyDetails from './ReadOnlyDetails.svelte';
35
+ import LockFence from './LockFence.svelte';
29
36
  import CommandConsole from './console/CommandConsole.svelte';
30
37
  import ConsoleStrip from './console/ConsoleStrip.svelte';
31
38
  import {
@@ -80,7 +87,10 @@
80
87
  import { provideInstance } from '../stores/getInstance.svelte.js';
81
88
  import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
82
89
  import { globalSaveWorkflow, globalExportWorkflow } from '../services/globalSave.js';
83
- import { apiToasts, dismissToast } from '../services/toastService.js';
90
+ import { apiToasts, dismissToast, showError, showInfo } from '../services/toastService.js';
91
+ import { workflowLaunchService } from '../services/workflowLaunchService.js';
92
+ import { canOfferRun } from '../utils/runOffer.js';
93
+ import { collectInterfaceInputs, interfaceFormEntriesFor } from '../utils/workflowInterface.js';
84
94
  import { initAutoSave } from '../services/autoSaveService.js';
85
95
  import {
86
96
  getUiSettings,
@@ -102,6 +112,7 @@
102
112
  import type { SettingsCategory, SurfacePlacement } from '../types/settings.js';
103
113
  import type { EditorPlaygroundConfig } from '../types/playground.js';
104
114
  import type { EditorMode } from '../stores/editorModeStore.svelte.js';
115
+ import type { EditorLock } from '../types/lock.js';
105
116
  import { defaultMessages, mergeMessages, setMessages, m } from '../messages/index.js';
106
117
  import type { MessagesOverride } from '../messages/index.js';
107
118
 
@@ -172,6 +183,25 @@
172
183
  * @default 'edit'
173
184
  */
174
185
  editorMode?: EditorMode;
186
+ /**
187
+ * Lock the editor: the workflow becomes read-only and a banner above the
188
+ * canvas lists the `reasons` and offers the `actions` (buttons the host
189
+ * answers through `onLockAction`). While locked, nothing can change the
190
+ * workflow (canvas, config panels, console, shortcuts, undo) and Save is
191
+ * disabled (a host's own Save action stays enabled; pressing it saves nothing
192
+ * and says the editor is locked); selecting, panning, zooming and inspecting
193
+ * still work. `null`
194
+ * removes the lock. Seeds `instance.lock`, which holds it afterwards
195
+ * (`instance.lock.set(...)`); passing a different value later sets it
196
+ * again, passing the same one does not. Unset, nothing changes.
197
+ */
198
+ lock?: EditorLock | null;
199
+ /**
200
+ * Called with the action's `id` when a person presses a button on the lock
201
+ * banner. The host decides what it does; an "Edit" action is answered by
202
+ * removing the lock.
203
+ */
204
+ onLockAction?: (id: string) => void;
175
205
  /**
176
206
  * Called when the Edit | Test mode changes after mount (the canvas toolbar switch,
177
207
  * the T shortcut, the run pill's "Open", `instance.editorMode.set`). Not called for the
@@ -191,6 +221,8 @@
191
221
  refreshTrigger?: number;
192
222
  /** Custom navbar title */
193
223
  navbarTitle?: string;
224
+ /** Heading level of the navbar title: 1 renders it as the page's H1 (default 2) */
225
+ navbarTitleLevel?: 1 | 2;
194
226
  /** Custom navbar actions */
195
227
  navbarActions?: NavbarAction[];
196
228
  /** White-label logo for the navbar (replaces the FlowDrop wordmark) */
@@ -217,6 +249,15 @@
217
249
  onBeforeSave?: FlowDropEventHandlers['onBeforeSave'];
218
250
  /** Called after a successful save. */
219
251
  onAfterSave?: FlowDropEventHandlers['onAfterSave'];
252
+ /** Called after a refused save was saved as a copy; replaces following the copy's editor URL. */
253
+ onSavedAsCopy?: FlowDropEventHandlers['onSavedAsCopy'];
254
+ /**
255
+ * Called when the unsaved edits are gone for good: just before the editor
256
+ * follows a saved copy's editor URL (after the workflow is marked saved), or
257
+ * after "Discard my changes" loaded the saved version. The mount API uses it
258
+ * to drop the stored draft.
259
+ */
260
+ onDiscardDraft?: () => void;
220
261
  /** Called when a save fails. */
221
262
  onSaveError?: FlowDropEventHandlers['onSaveError'];
222
263
  /** Called on any API error — return true to suppress the default toast. */
@@ -281,11 +322,14 @@
281
322
  configPlacement: configPlacementProp,
282
323
  consolePlacement: consolePlacementProp,
283
324
  mode = 'edit',
325
+ lock: lockProp,
326
+ onLockAction,
284
327
  editorMode: editorModeProp,
285
328
  onEditorModeChange,
286
329
  pipelineId,
287
330
  refreshTrigger = 0,
288
331
  navbarTitle,
332
+ navbarTitleLevel = 2,
289
333
  navbarActions = [],
290
334
  branding,
291
335
  navbarEnd,
@@ -296,6 +340,8 @@
296
340
  authProvider,
297
341
  onBeforeSave,
298
342
  onAfterSave,
343
+ onSavedAsCopy,
344
+ onDiscardDraft,
299
345
  onSaveError,
300
346
  onApiError,
301
347
  onWorkflowLoad,
@@ -341,18 +387,40 @@
341
387
  // read when it fires, so a changed callback prop is the one used.
342
388
  onMount(() => fd.editorMode.onChange((mode) => onEditorModeChange?.(mode)));
343
389
 
390
+ // The lock: `instance.lock` holds it. The `lock` prop seeds it and sets it
391
+ // again only when the host passes a different value, so the prop and
392
+ // `instance.lock.set(...)` take turns rather than fight: the last one wins.
393
+ // `undefined` means "no opinion".
394
+ // svelte-ignore state_referenced_locally
395
+ let appliedLockProp = lockProp;
396
+ // svelte-ignore state_referenced_locally
397
+ if (lockProp !== undefined) fd.lock.set(lockProp);
398
+ $effect.pre(() => {
399
+ const requested = lockProp;
400
+ if (requested === undefined || requested === appliedLockProp) return;
401
+ appliedLockProp = requested;
402
+ untrack(() => fd.lock.set(requested));
403
+ });
404
+ onMount(() => fd.lock.onAction((id) => onLockAction?.(id)));
405
+
344
406
  // `mode` is the public API; internally the canvas only cares whether editing
345
407
  // is disabled. 'readonly' and 'locked' both disable the same interactions
346
- // (see the `mode` prop JSDoc for the full matrix).
347
- const canvasEditable = $derived(mode === 'edit');
408
+ // (see the `mode` prop JSDoc for the full matrix). A lock on the editor does
409
+ // the same as `mode="locked"` while it lasts.
410
+ const effectiveMode = $derived(fd.lock.isLocked ? 'locked' : mode);
411
+ const canvasEditable = $derived(effectiveMode === 'edit');
412
+ // Save's unsaved marker follows the host's mode, not the lock: edits made
413
+ // before a lock arrived are still unsaved (the leave prompt and Run say so).
414
+ const showUnsaved = $derived(mode === 'edit' && fd.workflow.isDirty);
348
415
 
349
416
  /**
350
- * Test mode can be entered: it is offered, the canvas is editable, this is
417
+ * Test mode can be entered: it is offered, the host's mode is `edit`, this is
351
418
  * not a pipeline view, and the workflow is saved (the Playground runs the
352
- * saved workflow's id).
419
+ * saved workflow's id). A lock does not remove it: a locked workflow can still
420
+ * be tested, the canvas just stays read-only.
353
421
  */
354
422
  const testModeAvailable = $derived(
355
- features.testMode && canvasEditable && !pipelineId && !!fd.workflow.current?.id
423
+ features.testMode && mode === 'edit' && !pipelineId && !!fd.workflow.current?.id
356
424
  );
357
425
  /** Test mode is in effect: requested, and available. */
358
426
  const testMode = $derived(testModeAvailable && fd.editorMode.isTest);
@@ -462,6 +530,10 @@
462
530
  // — Svelte enforces that. The context value is a getter that closes over
463
531
  // the live $derived, so child components always read the current tree.
464
532
  setMessages(() => mergedMessages);
533
+ // Code outside the component tree (the impact dialog) reads the same tree from the instance.
534
+ fd.setMessages(() => mergedMessages);
535
+ // Do not leave the instance holding a getter into this destroyed component.
536
+ onDestroy(() => fd.setMessages(() => defaultMessages));
465
537
 
466
538
  // Default navbar primary actions — used when no `navbarActions` prop is supplied.
467
539
  // Derived so the labels track locale changes.
@@ -471,6 +543,7 @@
471
543
  href: '#save',
472
544
  icon: 'mdi:file-download-outline',
473
545
  variant: 'primary' as const,
546
+ disabled: fd.lock.isLocked,
474
547
  onclick: (e: Event) => {
475
548
  e.preventDefault();
476
549
  saveWorkflow();
@@ -491,6 +564,7 @@
491
564
  href: '#import',
492
565
  icon: 'mdi:upload',
493
566
  variant: 'outline' as const,
567
+ disabled: !canvasEditable,
494
568
  onclick: (e: Event) => {
495
569
  e.preventDefault();
496
570
  fileInputRef?.click();
@@ -566,6 +640,129 @@
566
640
  let error = $state<string | null>(null);
567
641
  let endpointConfig = $state<EndpointConfig | null>(null);
568
642
 
643
+ /**
644
+ * The Edit canvas offers a Run button: the host's mode is `edit`, saved, and
645
+ * either the host supplies `onRun` or the backend has the `workflows.run`
646
+ * endpoint. A lock does not remove it: a locked workflow can still be run (the
647
+ * saved version; `startRun` says so when there are unsaved changes).
648
+ */
649
+ const runOffered = $derived(
650
+ canOfferRun({
651
+ runButton: features.runButton,
652
+ canvasEditable: mode === 'edit',
653
+ pipelineId,
654
+ workflowId: fd.workflow.current?.id,
655
+ hostCanRun: !!fd.host.current.onRun,
656
+ backendCanRun: workflowLaunchService.isSupported(endpointConfig)
657
+ })
658
+ );
659
+ let runStarting = $state(false);
660
+
661
+ // The Run form: open while it asks for the inputs; the values stay per workflow id for the page.
662
+ let runDialogOpen = $state(false);
663
+ let runDialogValues = $state<Record<string, unknown>>({});
664
+ let runDialogError = $state<string | null>(null);
665
+ const runInputValues = new Map<string, Record<string, unknown>>();
666
+
667
+ /** The inputs a person fills in before a run: the interface inputs the chat binding does not fill. */
668
+ const runInputEntries = $derived.by(() => {
669
+ const workflow = fd.workflow.current;
670
+ if (!workflow) return [];
671
+ // Every input the chat does not fill, also in the Playground's legacy mode (no turn ports, no
672
+ // settings): the server refuses a run that leaves a required input out.
673
+ return interfaceFormEntriesFor(workflow.interface, resolvePlaygroundChat(workflow));
674
+ });
675
+
676
+ /**
677
+ * Start the run with these inputs through `host.onRun` or the `workflows.run` endpoint and show it
678
+ * as the shown run. Returns the reason when the run did not start, `null` otherwise.
679
+ */
680
+ async function launchRun(inputs: Record<string, unknown>): Promise<string | null> {
681
+ const workflow = fd.workflow.current;
682
+ if (!workflow?.id) return null;
683
+ try {
684
+ const hostOnRun = fd.host.current.onRun;
685
+ if (hostOnRun) {
686
+ const envelope = await fd.runs.wrapHostHooks(fd.host.current).onRun!(inputs);
687
+ if (envelope.ok && (envelope.data as { queued?: boolean } | undefined)?.queued) {
688
+ showInfo(mergedMessages.runButton.queued);
689
+ }
690
+ return envelope.ok ? null : (envelope.message ?? mergedMessages.runButton.failed);
691
+ }
692
+ const result = await workflowLaunchService.launch(
693
+ endpointConfig,
694
+ workflow.id,
695
+ { inputs, workflow, origin: 'editor' },
696
+ authProvider
697
+ );
698
+ if (result.status === 'launched') {
699
+ fd.runs.openRun(result.pipelineId, result.runStatus);
700
+ if (result.queued) showInfo(mergedMessages.runButton.queued);
701
+ return null;
702
+ }
703
+ if (result.status === 'unsupported') return null;
704
+ return 'message' in result ? result.message : mergedMessages.runButton.failed;
705
+ } catch (error) {
706
+ return error instanceof Error ? error.message : mergedMessages.runButton.failed;
707
+ }
708
+ }
709
+
710
+ /**
711
+ * Run the workflow from the canvas: save unsaved changes first, then start the run. A workflow
712
+ * with inputs opens the Run form; one without runs at once. A refusal shows the server's message.
713
+ */
714
+ async function startRun(): Promise<void> {
715
+ if (runStarting) return;
716
+ runStarting = true;
717
+ try {
718
+ if (fd.workflow.isDirty) {
719
+ if (fd.lock.isLocked) {
720
+ // A locked editor cannot save: run the saved workflow and say so.
721
+ showInfo(mergedMessages.runButton.lockedUnsaved);
722
+ } else if (!(await saveWorkflow())) {
723
+ // The save toast already explains a failed save.
724
+ return;
725
+ }
726
+ }
727
+ const workflow = fd.workflow.current;
728
+ if (!workflow?.id) return;
729
+ if (runInputEntries.length > 0) {
730
+ runDialogValues = runInputValues.get(workflow.id) ?? {};
731
+ runDialogError = null;
732
+ runDialogOpen = true;
733
+ return;
734
+ }
735
+ const refusal = await launchRun({});
736
+ if (refusal) showError(refusal);
737
+ } finally {
738
+ runStarting = false;
739
+ }
740
+ }
741
+
742
+ /** Run from the form: empty required inputs are refused here; a refusal from the server stays in the form. */
743
+ async function submitRunInputs(): Promise<void> {
744
+ const workflowId = fd.workflow.current?.id;
745
+ if (runStarting || !workflowId) return;
746
+ runInputValues.set(workflowId, runDialogValues);
747
+ const collected = collectInterfaceInputs(runInputEntries, runDialogValues);
748
+ if (!collected.ok) {
749
+ const names = (list: { id: string }[]) => list.map((entry) => entry.id).join(', ');
750
+ runDialogError = collected.missing.length
751
+ ? mergedMessages.runInputsDialog.missing({ names: names(collected.missing) })
752
+ : mergedMessages.runInputsDialog.invalid({ names: names(collected.invalid) });
753
+ return;
754
+ }
755
+ runStarting = true;
756
+ runDialogError = null;
757
+ try {
758
+ const refusal = await launchRun(collected.inputs);
759
+ if (refusal) runDialogError = refusal;
760
+ else runDialogOpen = false;
761
+ } finally {
762
+ runStarting = false;
763
+ }
764
+ }
765
+
569
766
  // ConfigSidebar state
570
767
  let isConfigSidebarOpen = $state(false);
571
768
  let selectedNodeId = $state<string | null>(null);
@@ -941,6 +1138,7 @@
941
1138
  return true;
942
1139
  }
943
1140
  $effect(() => fd.doctor.setFocusHandler(focusProblemNode));
1141
+ $effect(() => fd.doctor.setAutoApply(canvasEditable));
944
1142
 
945
1143
  // The Doctor diagnoses the draft a moment after each edit, and on load (and
946
1144
  // once the workflow has an id). Reading the version and the id is the trigger.
@@ -1172,15 +1370,26 @@
1172
1370
  : undefined
1173
1371
  );
1174
1372
 
1175
- async function saveWorkflow(): Promise<boolean> {
1373
+ async function saveWorkflow(options: { interactive?: boolean } = {}): Promise<boolean> {
1374
+ // A locked editor is refused inside globalSaveWorkflow, the one place that
1375
+ // decides it: quietly for autosave, with "nothing was saved" for a person.
1176
1376
  // Commit any in-flight config edit so the save and its history are
1177
1377
  // consistent (the value itself is already live in the store).
1178
1378
  flushNodeConfigEdit();
1179
1379
  return globalSaveWorkflow({
1180
- eventHandlers: { onBeforeSave, onAfterSave, onSaveError, onApiError },
1380
+ eventHandlers: {
1381
+ onBeforeSave,
1382
+ onAfterSave,
1383
+ onSavedAsCopy,
1384
+ onSaveError,
1385
+ onApiError,
1386
+ onWorkflowLoad
1387
+ },
1181
1388
  features,
1182
1389
  instance: fd,
1183
- onMarkAsSaved: () => fd.workflow.markAsSaved()
1390
+ interactive: options.interactive,
1391
+ onDiscardDraft,
1392
+ onMarkAsSaved: (version) => fd.workflow.markAsSaved(version)
1184
1393
  });
1185
1394
  }
1186
1395
 
@@ -1200,8 +1409,12 @@
1200
1409
  * Reads the selected file, validates its structure, and loads it into the workflow store.
1201
1410
  */
1202
1411
  function importWorkflow(file: File): void {
1412
+ // Import replaces the workflow: not while it is locked or read-only.
1413
+ if (!canvasEditable) return;
1203
1414
  const reader = new FileReader();
1204
1415
  reader.onload = (event) => {
1416
+ // A lock or read-only mode may have arrived while the file was being read.
1417
+ if (!canvasEditable) return;
1205
1418
  try {
1206
1419
  const text = event.target?.result;
1207
1420
  if (typeof text !== 'string') {
@@ -1342,7 +1555,8 @@
1342
1555
  const cleanupAutoSave = initAutoSave({
1343
1556
  isDirty: () => fd.workflow.isDirty,
1344
1557
  onSave: async () => {
1345
- await saveWorkflow();
1558
+ // A timer must not open a question: a save that needs an answer waits.
1559
+ await saveWorkflow({ interactive: false });
1346
1560
  },
1347
1561
  onError: (error) => {
1348
1562
  // Don't show toast for auto-save errors to avoid noise
@@ -1489,6 +1703,7 @@
1489
1703
  const consoleStripShown = $derived(consoleGroupOffered && canvasEditable);
1490
1704
  /** Id of the Console panel, for the strip's `aria-controls`. */
1491
1705
  const consolePanelId = `${scopeId}-console-panel`;
1706
+ const canvasRegionId = `${scopeId}-canvas`;
1492
1707
  /** Node-swap sub-flow occupies the right sidebar regardless of placement. */
1493
1708
  const swapActive = $derived(swapMode !== 'idle');
1494
1709
 
@@ -1778,34 +1993,41 @@
1778
1993
  -->
1779
1994
 
1780
1995
  {#snippet nodeConfigFormEl(node: WorkflowNode)}
1781
- <ConfigForm
1782
- {authProvider}
1783
- {node}
1784
- commitMode="live"
1785
- workflowId={fd.workflow.current?.id}
1786
- workflowNodes={fd.workflow.current?.nodes}
1787
- workflowEdges={fd.workflow.current?.edges}
1788
- onExternalEdit={externalEditForConfig}
1789
- onChange={(updatedConfig, meta) => {
1790
- if (!node.id) return;
1791
- const updatedData = { ...node.data, config: updatedConfig };
1792
-
1793
- // Blur / end-of-session: commit the coalesced undo step + fire the
1794
- // change event once, and refresh edges once.
1795
- if (meta?.commit) {
1796
- pendingConfigNodeId = node.id;
1797
- flushNodeConfigEdit();
1798
- return;
1799
- }
1996
+ <LockFence>
1997
+ <ConfigForm
1998
+ {authProvider}
1999
+ {node}
2000
+ commitMode="live"
2001
+ workflowId={fd.workflow.current?.id}
2002
+ workflowNodes={fd.workflow.current?.nodes}
2003
+ workflowEdges={fd.workflow.current?.edges}
2004
+ onExternalEdit={externalEditForConfig}
2005
+ onChange={(updatedConfig, meta) => {
2006
+ // A locked workflow takes no edits: the store would refuse them and the canvas must not move.
2007
+ if (!node.id || fd.lock.isLocked) return;
2008
+ const updatedData = { ...node.data, config: updatedConfig };
2009
+
2010
+ // Blur / end-of-session: commit the coalesced undo step + fire the
2011
+ // change event once, and refresh edges once.
2012
+ if (meta?.commit) {
2013
+ pendingConfigNodeId = node.id;
2014
+ flushNodeConfigEdit();
2015
+ return;
2016
+ }
1800
2017
 
1801
- // Live edit (every change): update the store cheaply — no history clone,
1802
- // no external event; both are deferred to the session flush above. Also
1803
- // reflect the change on the canvas immediately (e.g. nodeType changes).
1804
- pendingConfigNodeId = node.id;
1805
- fd.workflow.updateNodeConfig(node.id, { data: updatedData }, { fieldKey: meta?.fieldKey });
1806
- workflowEditorRef?.updateNodeData(node.id, updatedData);
1807
- }}
1808
- />
2018
+ // Live edit (every change): update the store cheaply — no history clone,
2019
+ // no external event; both are deferred to the session flush above. Also
2020
+ // reflect the change on the canvas immediately (e.g. nodeType changes).
2021
+ // The canvas mirrors the store, so it follows only an edit the store took.
2022
+ pendingConfigNodeId = node.id;
2023
+ if (
2024
+ fd.workflow.updateNodeConfig(node.id, { data: updatedData }, { fieldKey: meta?.fieldKey })
2025
+ ) {
2026
+ workflowEditorRef?.updateNodeData(node.id, updatedData);
2027
+ }
2028
+ }}
2029
+ />
2030
+ </LockFence>
1809
2031
  {/snippet}
1810
2032
 
1811
2033
  <!-- Last run of a failed node: take the run to the Assistant -->
@@ -1843,49 +2065,52 @@
1843
2065
  {/snippet}
1844
2066
 
1845
2067
  {#snippet workflowConfigFormEl()}
1846
- <ConfigForm
1847
- {authProvider}
1848
- schema={workflowConfigSchema}
1849
- values={workflowConfigValues}
1850
- commitMode="blur"
1851
- onChange={(config) => {
1852
- // Sync workflow settings changes immediately on field blur
1853
- const wf = fd.workflow.current;
1854
- if (wf) {
1855
- const currentFormat = wf.metadata?.format || DEFAULT_WORKFLOW_FORMAT;
1856
- // Fall back to the CURRENT format, not the default: when the field is
1857
- // hidden (host supports one format) config.format is absent, and
1858
- // applying name/description must not silently rewrite the format.
1859
- const newFormat = (config.format as string) || currentFormat;
1860
-
1861
- // Warn about incompatible nodes when format changes
1862
- if (newFormat !== currentFormat) {
1863
- const incompatibleNodes = wf.nodes?.filter((node) => {
1864
- const formats = node.data?.metadata?.formats;
1865
- return formats && formats.length > 0 && !formats.includes(newFormat);
1866
- });
1867
- if (incompatibleNodes && incompatibleNodes.length > 0) {
1868
- logger.warn(
1869
- `Format changed to '${newFormat}'. ${incompatibleNodes.length} node(s) are not compatible with this format and may not export correctly:`,
1870
- incompatibleNodes.map((n) => n.data?.label || n.type)
1871
- );
2068
+ <LockFence>
2069
+ <ConfigForm
2070
+ {authProvider}
2071
+ schema={workflowConfigSchema}
2072
+ values={workflowConfigValues}
2073
+ commitMode="blur"
2074
+ onChange={(config) => {
2075
+ if (fd.lock.isLocked) return;
2076
+ // Sync workflow settings changes immediately on field blur
2077
+ const wf = fd.workflow.current;
2078
+ if (wf) {
2079
+ const currentFormat = wf.metadata?.format || DEFAULT_WORKFLOW_FORMAT;
2080
+ // Fall back to the CURRENT format, not the default: when the field is
2081
+ // hidden (host supports one format) config.format is absent, and
2082
+ // applying name/description must not silently rewrite the format.
2083
+ const newFormat = (config.format as string) || currentFormat;
2084
+
2085
+ // Warn about incompatible nodes when format changes
2086
+ if (newFormat !== currentFormat) {
2087
+ const incompatibleNodes = wf.nodes?.filter((node) => {
2088
+ const formats = node.data?.metadata?.formats;
2089
+ return formats && formats.length > 0 && !formats.includes(newFormat);
2090
+ });
2091
+ if (incompatibleNodes && incompatibleNodes.length > 0) {
2092
+ logger.warn(
2093
+ `Format changed to '${newFormat}'. ${incompatibleNodes.length} node(s) are not compatible with this format and may not export correctly:`,
2094
+ incompatibleNodes.map((n) => n.data?.label || n.type)
2095
+ );
2096
+ }
1872
2097
  }
1873
- }
1874
2098
 
1875
- // Extract built-in fields; everything else belongs in workflow.config
1876
- const { name, description, format: _format, ...customConfig } = config;
1877
- fd.workflow.batchUpdate({
1878
- name: name as string,
1879
- description: description as string | undefined,
1880
- metadata: {
1881
- ...wf.metadata,
1882
- format: newFormat
1883
- },
1884
- ...(workflowSettingsSchema && { config: customConfig as Record<string, unknown> })
1885
- });
1886
- }
1887
- }}
1888
- />
2099
+ // Extract built-in fields; everything else belongs in workflow.config
2100
+ const { name, description, format: _format, ...customConfig } = config;
2101
+ fd.workflow.batchUpdate({
2102
+ name: name as string,
2103
+ description: description as string | undefined,
2104
+ metadata: {
2105
+ ...wf.metadata,
2106
+ format: newFormat
2107
+ },
2108
+ ...(workflowSettingsSchema && { config: customConfig as Record<string, unknown> })
2109
+ });
2110
+ }
2111
+ }}
2112
+ />
2113
+ </LockFence>
1889
2114
  {/snippet}
1890
2115
 
1891
2116
  <!--
@@ -1895,17 +2120,22 @@
1895
2120
  mutation.
1896
2121
  -->
1897
2122
  {#snippet workflowInterfaceEl()}
1898
- {#if fd.workflow.current}
1899
- <WorkflowInterfaceEditor
1900
- workflow={fd.workflow.current}
1901
- dataTypes={fd.portCompatibility.getEnabledDataTypes()}
1902
- checker={fd.portCompatibility}
1903
- onChange={(next, edit) => fd.workflow.editInterface(next, edit)}
1904
- onOpenPlaygroundSettings={fd.workflow.current.playground !== undefined
1905
- ? () => (workflowSettingsTab = 'playground')
1906
- : undefined}
1907
- />
1908
- {/if}
2123
+ <LockFence>
2124
+ {#if fd.workflow.current}
2125
+ <WorkflowInterfaceEditor
2126
+ workflow={fd.workflow.current}
2127
+ dataTypes={fd.portCompatibility.getEnabledDataTypes()}
2128
+ checker={fd.portCompatibility}
2129
+ onChange={(next, edit) => {
2130
+ if (fd.lock.isLocked) return;
2131
+ fd.workflow.editInterface(next, edit);
2132
+ }}
2133
+ onOpenPlaygroundSettings={fd.workflow.current.playground !== undefined
2134
+ ? () => (workflowSettingsTab = 'playground')
2135
+ : undefined}
2136
+ />
2137
+ {/if}
2138
+ </LockFence>
1909
2139
  {/snippet}
1910
2140
 
1911
2141
  <!--
@@ -1915,20 +2145,25 @@
1915
2145
  mark the workflow dirty and are saved with it.
1916
2146
  -->
1917
2147
  {#snippet workflowPlaygroundEl()}
1918
- {#if fd.workflow.current}
1919
- <WorkflowPlaygroundSettings
1920
- workflow={fd.workflow.current}
1921
- onChange={(next) => fd.workflow.batchUpdate({ playground: next })}
1922
- onMoveTurns={(chat) => {
1923
- const current = fd.workflow.current;
1924
- if (!current) return;
1925
- fd.workflow.batchUpdate({
1926
- playground: withPlaygroundChat(current.playground, chat),
1927
- interface: withoutInterfaceTurns(current.interface)
1928
- });
1929
- }}
1930
- />
1931
- {/if}
2148
+ <LockFence>
2149
+ {#if fd.workflow.current}
2150
+ <WorkflowPlaygroundSettings
2151
+ workflow={fd.workflow.current}
2152
+ onChange={(next) => {
2153
+ if (fd.lock.isLocked) return;
2154
+ fd.workflow.batchUpdate({ playground: next });
2155
+ }}
2156
+ onMoveTurns={(chat) => {
2157
+ const current = fd.workflow.current;
2158
+ if (!current || fd.lock.isLocked) return;
2159
+ fd.workflow.batchUpdate({
2160
+ playground: withPlaygroundChat(current.playground, chat),
2161
+ interface: withoutInterfaceTurns(current.interface)
2162
+ });
2163
+ }}
2164
+ />
2165
+ {/if}
2166
+ </LockFence>
1932
2167
  {/snippet}
1933
2168
 
1934
2169
  <!--
@@ -2032,6 +2267,7 @@
2032
2267
  activeFormat={fd.workflow.format}
2033
2268
  categoriesDefaultOpen={themeConfig?.sidebar?.categoriesDefaultOpen ?? false}
2034
2269
  listStyle={themeConfig?.display?.sidebarList}
2270
+ onadd={(n) => workflowEditorRef?.addNodeFromPalette(n)}
2035
2271
  />
2036
2272
  {/if}
2037
2273
  {/snippet}
@@ -2094,6 +2330,14 @@
2094
2330
 
2095
2331
  <!-- MainLayout wrapper for workflow editor -->
2096
2332
  <div class="flowdrop-root" data-fd-scope={scopeId} use:themeScope={{ mirror: true }}>
2333
+ <a
2334
+ class="flowdrop-skip-link"
2335
+ href={`#${canvasRegionId}`}
2336
+ onclick={(e) => {
2337
+ e.preventDefault();
2338
+ document.getElementById(canvasRegionId)?.focus();
2339
+ }}>{mergedMessages.layout.skipToCanvas}</a
2340
+ >
2097
2341
  <MainLayout
2098
2342
  {height}
2099
2343
  {width}
@@ -2126,12 +2370,18 @@
2126
2370
  {/snippet}
2127
2371
  <Navbar
2128
2372
  title={breadcrumbTitle}
2373
+ titleLevel={navbarTitleLevel}
2129
2374
  primaryActions={navbarActions.length > 0 ? navbarActions : defaultPrimaryActions}
2130
2375
  {showStatus}
2131
2376
  {showSettings}
2132
2377
  {branding}
2133
2378
  end={navbarEnd}
2134
2379
  saveShortcut
2380
+ onDisabledSave={() => {
2381
+ // Save is disabled by the lock: saving says so ("nothing was saved").
2382
+ if (fd.lock.isLocked) void saveWorkflow();
2383
+ }}
2384
+ dirty={showUnsaved}
2135
2385
  onWorkflowSettings={toggleWorkflowSettings}
2136
2386
  status={doctorStatus}
2137
2387
  workflowSettingsOpen={isWorkflowSettingsOpen}
@@ -2304,6 +2554,8 @@
2304
2554
  closeActiveConfig();
2305
2555
  } else closeConfigSidebar();
2306
2556
  }}
2557
+ id={canvasRegionId}
2558
+ tabindex="-1"
2307
2559
  role="region"
2308
2560
  aria-label={mergedMessages.layout.workflowCanvas}
2309
2561
  >
@@ -2402,6 +2654,7 @@
2402
2654
  activeFormat={fd.workflow.format}
2403
2655
  categoriesDefaultOpen={themeConfig?.sidebar?.categoriesDefaultOpen ?? false}
2404
2656
  listStyle={themeConfig?.display?.sidebarList}
2657
+ onadd={(n) => workflowEditorRef?.addNodeFromPalette(n)}
2405
2658
  />
2406
2659
  </div>
2407
2660
  {/if}
@@ -2424,6 +2677,8 @@
2424
2677
  editorMode={effectiveEditorMode}
2425
2678
  onEditorModeChange={testModeAvailable ? (next) => fd.editorMode.set(next) : undefined}
2426
2679
  onOpenTest={testModeAvailable ? () => fd.editorMode.set('test') : undefined}
2680
+ onRun={runOffered ? () => void startRun() : undefined}
2681
+ runBusy={runStarting}
2427
2682
  onAskAssistant={askAssistant}
2428
2683
  showRuns={testMode && features.runsList}
2429
2684
  adminLinks={features.adminLinks}
@@ -2431,6 +2686,33 @@
2431
2686
  />
2432
2687
  </div>
2433
2688
  </MainLayout>
2689
+
2690
+ {#if runOffered}
2691
+ <RunInputsDialog
2692
+ open={runDialogOpen}
2693
+ workflowName={fd.workflow.current?.name ?? ''}
2694
+ entries={runInputEntries}
2695
+ values={runDialogValues}
2696
+ onChange={(values) => {
2697
+ runDialogValues = values;
2698
+ const id = fd.workflow.current?.id;
2699
+ if (id) runInputValues.set(id, values);
2700
+ }}
2701
+ onRun={() => void submitRunInputs()}
2702
+ runBusy={runStarting}
2703
+ error={runDialogError}
2704
+ onClose={() => (runDialogOpen = false)}
2705
+ />
2706
+ {/if}
2707
+
2708
+ {#if fd.saveConflict.comparison}
2709
+ <WorkflowCompareDialog
2710
+ comparison={fd.saveConflict.comparison}
2711
+ onKeepMine={() => void fd.saveConflict.keepMine()}
2712
+ onLoadTheirs={() => fd.saveConflict.acceptTheirs()}
2713
+ onClose={() => fd.saveConflict.closeComparison()}
2714
+ />
2715
+ {/if}
2434
2716
  </div>
2435
2717
 
2436
2718
  <!--
@@ -2474,6 +2756,33 @@
2474
2756
  {/if}
2475
2757
 
2476
2758
  <style>
2759
+ /* Hidden until focused, then the first thing on screen. */
2760
+ .flowdrop-skip-link {
2761
+ position: absolute;
2762
+ width: 1px;
2763
+ height: 1px;
2764
+ overflow: hidden;
2765
+ clip-path: inset(50%);
2766
+ white-space: nowrap;
2767
+ }
2768
+
2769
+ .flowdrop-skip-link:focus {
2770
+ position: fixed;
2771
+ top: var(--fd-space-xs);
2772
+ left: var(--fd-space-xs);
2773
+ z-index: 1000;
2774
+ width: auto;
2775
+ height: auto;
2776
+ overflow: visible;
2777
+ clip-path: none;
2778
+ padding: var(--fd-space-xs) var(--fd-space-md);
2779
+ background: var(--fd-background);
2780
+ color: var(--fd-foreground);
2781
+ border-radius: var(--fd-radius-md);
2782
+ box-shadow: var(--fd-shadow-lg);
2783
+ font-size: var(--fd-text-sm);
2784
+ }
2785
+
2477
2786
  .flowdrop-root {
2478
2787
  display: contents;
2479
2788
  }