@flowdrop/flowdrop 2.17.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 (77) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/enhanced-client.d.ts +3 -1
  3. package/dist/api/enhanced-client.js +4 -2
  4. package/dist/commands/executor.js +9 -0
  5. package/dist/commands/storeIntegration.svelte.js +6 -0
  6. package/dist/commands/types.d.ts +8 -0
  7. package/dist/components/App.svelte +209 -106
  8. package/dist/components/App.svelte.d.ts +29 -0
  9. package/dist/components/FlowDropZone.svelte +7 -1
  10. package/dist/components/FlowDropZone.svelte.d.ts +5 -0
  11. package/dist/components/ImpactConfirm.svelte +246 -33
  12. package/dist/components/ImpactConfirm.svelte.d.ts +13 -3
  13. package/dist/components/Input.svelte +8 -2
  14. package/dist/components/LockBanner.svelte +76 -0
  15. package/dist/components/LockBanner.svelte.d.ts +14 -0
  16. package/dist/components/LockFence.svelte +33 -0
  17. package/dist/components/LockFence.svelte.d.ts +19 -0
  18. package/dist/components/Navbar.svelte +35 -6
  19. package/dist/components/Navbar.svelte.d.ts +6 -0
  20. package/dist/components/RunBar.svelte +16 -4
  21. package/dist/components/Textarea.svelte +7 -1
  22. package/dist/components/WorkflowEditor.svelte +32 -9
  23. package/dist/components/WorkflowInterfaceEditor.svelte +3 -0
  24. package/dist/components/WorkflowInterfaceEntryCard.svelte +21 -4
  25. package/dist/components/WorkflowPlaygroundSettings.svelte +9 -1
  26. package/dist/components/form/FieldFactory.svelte +13 -6
  27. package/dist/components/form/FormArray.svelte +0 -1
  28. package/dist/components/form/FormArrayRows.svelte +4 -4
  29. package/dist/components/form/FormCodeEditor.svelte +18 -2
  30. package/dist/components/form/FormMarkdownEditor.svelte +22 -8
  31. package/dist/components/form/FormTemplateEditor.svelte +17 -1
  32. package/dist/components/form/readOnly.d.ts +13 -0
  33. package/dist/components/form/readOnly.js +18 -0
  34. package/dist/components/nodes/CaptionNode.svelte +1 -0
  35. package/dist/components/primitives/Checkbox.svelte +5 -1
  36. package/dist/components/primitives/Select.svelte +6 -1
  37. package/dist/components/primitives/Switch.svelte +5 -1
  38. package/dist/editor/index.d.ts +1 -0
  39. package/dist/index.d.ts +2 -1
  40. package/dist/messages/defaults.d.ts +45 -0
  41. package/dist/messages/defaults.js +51 -3
  42. package/dist/openapi/v1/openapi.yaml +492 -0
  43. package/dist/registry/nodeComponentRegistry.d.ts +5 -0
  44. package/dist/schemas/v1/workflow.schema.json +2 -0
  45. package/dist/services/globalSave.d.ts +17 -0
  46. package/dist/services/globalSave.js +166 -6
  47. package/dist/services/impactGate.d.ts +7 -3
  48. package/dist/services/impactGate.js +9 -7
  49. package/dist/services/impactService.d.ts +18 -1
  50. package/dist/services/impactService.js +93 -7
  51. package/dist/services/runsService.d.ts +9 -0
  52. package/dist/services/runsService.js +13 -0
  53. package/dist/services/workflowLaunchService.d.ts +6 -0
  54. package/dist/services/workflowLaunchService.js +2 -0
  55. package/dist/stores/historyStore.svelte.d.ts +12 -2
  56. package/dist/stores/historyStore.svelte.js +25 -2
  57. package/dist/stores/instanceContainer.svelte.d.ts +7 -0
  58. package/dist/stores/instanceContainer.svelte.js +10 -0
  59. package/dist/stores/lockStore.svelte.d.ts +39 -0
  60. package/dist/stores/lockStore.svelte.js +109 -0
  61. package/dist/stores/runController.svelte.d.ts +2 -0
  62. package/dist/stores/runController.svelte.js +27 -11
  63. package/dist/stores/workflowStore.svelte.d.ts +7 -1
  64. package/dist/stores/workflowStore.svelte.js +41 -13
  65. package/dist/styles/base.css +6 -0
  66. package/dist/svelte-app.d.ts +31 -0
  67. package/dist/svelte-app.js +110 -26
  68. package/dist/types/events.d.ts +17 -0
  69. package/dist/types/impact.d.ts +52 -0
  70. package/dist/types/lock.d.ts +35 -0
  71. package/dist/types/lock.js +13 -0
  72. package/dist/types/navbar.d.ts +6 -0
  73. package/dist/utils/links.d.ts +29 -0
  74. package/dist/utils/links.js +63 -0
  75. package/dist/webmcp/runtime.js +16 -3
  76. package/dist/webmcp/types.d.ts +11 -1
  77. package/package.json +1 -1
@@ -20,7 +20,7 @@ import { logger } from './utils/logger.js';
20
20
  import { globalSaveWorkflow, globalExportWorkflow } from './services/globalSave.js';
21
21
  import { whenWorkflowLoaded } from './utils/whenWorkflowLoaded.svelte.js';
22
22
  import { draftOffer, draftTimeLabel } from './utils/draftRestore.js';
23
- import { showWarning } from './services/toastService.js';
23
+ import { showInfo, showWarning } from './services/toastService.js';
24
24
  import { parseCommand } from './commands/parser.js';
25
25
  import { executeCommand } from './commands/executor.js';
26
26
  import { isSessionLine } from './commands/session.js';
@@ -66,6 +66,16 @@ function releaseInstance(fd, isDefault) {
66
66
  fd.destroy();
67
67
  }
68
68
  }
69
+ /**
70
+ * Forget the lock of a released default instance. A lock belongs to the mount
71
+ * that set it; the next mount starts unlocked unless its own options say
72
+ * otherwise. Called after the component is unmounted, so a blur during the
73
+ * unmount cannot write into the instance once it is unlocked again.
74
+ */
75
+ function releaseLock(fd, isDefault) {
76
+ if (isDefault)
77
+ fd.lock.clear();
78
+ }
69
79
  /**
70
80
  * Resolve endpoint config, port config and categories from mount options and
71
81
  * apply them to the given instance (API context, port-compatibility checker,
@@ -256,6 +266,18 @@ function createRunCommand(fd, isDestroyed, registerCancel, onBaseline) {
256
266
  }
257
267
  });
258
268
  }
269
+ /**
270
+ * What the default `onSave` tells an agent when the backend refused the save
271
+ * because things use the workflow, by what the person chose in the dialog.
272
+ */
273
+ const SAVE_REFUSED_MESSAGES = {
274
+ kept: 'Nothing was saved: the change breaks places that use this workflow, so the server refused it. ' +
275
+ 'The person was shown those places and kept editing; tell them, do not retry.',
276
+ copied: 'The workflow itself was not changed: the change breaks places that use it, so the server ' +
277
+ 'refused it, and the person saved the draft as a new workflow instead.',
278
+ discarded: 'Nothing was saved: the change breaks places that use this workflow, so the server refused it, ' +
279
+ 'and the person discarded the unsaved changes. The editor now holds the saved version.'
280
+ };
259
281
  /**
260
282
  * Mount the full FlowDrop App with navbar, sidebars, and workflow editor
261
283
  *
@@ -281,7 +303,7 @@ function createRunCommand(fd, isDestroyed, registerCancel, onBaseline) {
281
303
  * ```
282
304
  */
283
305
  export async function mountFlowDropApp(container, options = {}) {
284
- const { workflow, nodes, endpointConfig, portConfig, categories, height = '100vh', width = '100%', showNavbar = false, disableSidebar, configPlacement, consolePlacement, mode, editorMode, onEditorModeChange, playground, pipelineId, navbarTitle, navbarTitleLevel, navbarActions, branding, navbarEnd, showSettings, showStatus, authProvider, eventHandlers, features: userFeatures, settings: initialSettings, colorScheme, draftStorageKey: customDraftKey, draftStorage, formatAdapters, workflowFormats, workflowSettingsSchema, theme, settingsCategories, showSettingsSyncButton, showSettingsResetButton, instanceId, webmcp, host, contextMenu } = options;
306
+ const { workflow, nodes, endpointConfig, portConfig, categories, height = '100vh', width = '100%', showNavbar = false, disableSidebar, configPlacement, consolePlacement, mode, lock, onLockAction, editorMode, onEditorModeChange, playground, pipelineId, navbarTitle, navbarTitleLevel, navbarActions, branding, navbarEnd, showSettings, showStatus, authProvider, eventHandlers, features: userFeatures, settings: initialSettings, colorScheme, draftStorageKey: customDraftKey, draftStorage, formatAdapters, workflowFormats, workflowSettingsSchema, theme, settingsCategories, showSettingsSyncButton, showSettingsResetButton, instanceId, webmcp, host, contextMenu } = options;
285
307
  // The host's element callback becomes a snippet: one empty host element, handed
286
308
  // to the callback in `setup`, whose return value is the cleanup.
287
309
  if (navbarEnd && showNavbar !== true) {
@@ -379,6 +401,8 @@ export async function mountFlowDropApp(container, options = {}) {
379
401
  configPlacement,
380
402
  consolePlacement,
381
403
  mode,
404
+ lock,
405
+ onLockAction,
382
406
  editorMode,
383
407
  onEditorModeChange,
384
408
  playground,
@@ -399,6 +423,8 @@ export async function mountFlowDropApp(container, options = {}) {
399
423
  onBeforeSave: eventHandlers?.onBeforeSave,
400
424
  onAfterSave: eventHandlers?.onAfterSave,
401
425
  onSaveError: eventHandlers?.onSaveError,
426
+ onSavedAsCopy: eventHandlers?.onSavedAsCopy,
427
+ onDiscardDraft: () => state.draftManager?.markAsSaved(),
402
428
  onApiError: eventHandlers?.onApiError,
403
429
  onWorkflowLoad: eventHandlers?.onWorkflowLoad,
404
430
  onExternalEdit: eventHandlers?.onExternalEdit
@@ -447,7 +473,7 @@ export async function mountFlowDropApp(container, options = {}) {
447
473
  const offerKey = draftManager.getStorageKey();
448
474
  if (mode !== 'readonly' && mode !== 'locked' && !offerKey.endsWith(':new')) {
449
475
  const manager = draftManager;
450
- cancelDraftOffer = whenWorkflowLoaded(fd, (loaded) => {
476
+ const offerDraft = (loaded) => {
451
477
  const draft = loadDraft(offerKey, draftStorageAdapter);
452
478
  const offer = draftOffer(draft, loaded);
453
479
  if (!draft)
@@ -467,6 +493,14 @@ export async function mountFlowDropApp(container, options = {}) {
467
493
  label: text.restore,
468
494
  primary: true,
469
495
  onClick: () => {
496
+ // A locked workflow refuses the restore, and saving the draft
497
+ // now would write the saved version over it. Keep the hold, so
498
+ // the clean workflow does not delete the draft either: it is
499
+ // offered again when the workflow next opens.
500
+ if (fd.workflow.locked) {
501
+ showInfo(text.restoreLocked);
502
+ return;
503
+ }
470
504
  release();
471
505
  fd.workflow.batchUpdate({
472
506
  nodes: draft.workflow.nodes,
@@ -488,7 +522,27 @@ export async function mountFlowDropApp(container, options = {}) {
488
522
  }
489
523
  ]
490
524
  }, { id: `flowdrop:draft-offer:${offerKey}` });
491
- });
525
+ };
526
+ if (fd.lock.isLocked) {
527
+ // A locked editor cannot restore, so the offer waits for the lock to go.
528
+ // Meanwhile the workflow is clean and an autosave tick would delete the
529
+ // draft: hold it until then.
530
+ const releaseLockHold = manager.holdDraft();
531
+ const stopWatching = fd.lock.onChange((locked) => {
532
+ if (locked)
533
+ return;
534
+ stopWatching();
535
+ releaseLockHold();
536
+ cancelDraftOffer = whenWorkflowLoaded(fd, offerDraft);
537
+ });
538
+ cancelDraftOffer = () => {
539
+ stopWatching();
540
+ releaseLockHold();
541
+ };
542
+ }
543
+ else {
544
+ cancelDraftOffer = whenWorkflowLoaded(fd, offerDraft);
545
+ }
492
546
  }
493
547
  // When the user opts out, also remove the draft already in storage.
494
548
  unsubscribeDraftSettings = onSettingsChange((event) => {
@@ -527,9 +581,37 @@ export async function mountFlowDropApp(container, options = {}) {
527
581
  window.addEventListener('beforeunload', onBeforeUnload);
528
582
  removeLeaveGuard = () => window.removeEventListener('beforeunload', onBeforeUnload);
529
583
  }
584
+ /**
585
+ * The mount's Save (`app.save()`, the default WebMCP `onSave`). `onRefused` hears
586
+ * when the backend refused it because things use the workflow.
587
+ */
588
+ const saveFromMount = (onRefused) => globalSaveWorkflow({
589
+ instance: fd,
590
+ onRefused,
591
+ // The refused-save answers reach the host from here too, as from the Save button.
592
+ eventHandlers: {
593
+ onSavedAsCopy: eventHandlers?.onSavedAsCopy,
594
+ onWorkflowLoad: eventHandlers?.onWorkflowLoad
595
+ },
596
+ onDiscardDraft: () => state.draftManager?.markAsSaved(),
597
+ onSaved: (saved) => {
598
+ // globalSaveWorkflow does not write the server-assigned ID back to the
599
+ // workflow store, so we cannot read it from the store here.
600
+ // Instead we use the savedWorkflow returned by the API directly.
601
+ // This migrates '<prefix>:new' to a unique per-workflow key
602
+ // immediately after the first save, preventing cross-tab collisions
603
+ // when multiple new workflows are open simultaneously.
604
+ if (state.draftManager && !customDraftKey && saved.id) {
605
+ state.draftManager.updateStorageKey(getDraftStorageKey(saved.id, undefined, fd.storagePrefix));
606
+ }
607
+ // A saved workflow has no draft
608
+ state.draftManager?.markAsSaved();
609
+ }
610
+ });
530
611
  // Create the mounted app interface
531
612
  const mountedApp = {
532
613
  instance: fd,
614
+ setLock: (next) => fd.lock.set(next),
533
615
  get webmcp() {
534
616
  return webmcpHandle;
535
617
  },
@@ -571,6 +653,7 @@ export async function mountFlowDropApp(container, options = {}) {
571
653
  releaseInstance(fd, isDefault);
572
654
  // Unmount Svelte app
573
655
  unmount(state.svelteApp);
656
+ releaseLock(fd, isDefault);
574
657
  },
575
658
  isDirty: () => fd.workflow.isDirty,
576
659
  markAsSaved: () => {
@@ -598,24 +681,7 @@ export async function mountFlowDropApp(container, options = {}) {
598
681
  },
599
682
  // The re-baselined workflow is clean, so it is not a draft to restore.
600
683
  () => state.draftManager?.markAsSaved()),
601
- save: async () => {
602
- return globalSaveWorkflow({
603
- instance: fd,
604
- onSaved: (saved) => {
605
- // globalSaveWorkflow does not write the server-assigned ID back to the
606
- // workflow store, so we cannot read it from the store here.
607
- // Instead we use the savedWorkflow returned by the API directly.
608
- // This migrates '<prefix>:new' to a unique per-workflow key
609
- // immediately after the first save, preventing cross-tab collisions
610
- // when multiple new workflows are open simultaneously.
611
- if (state.draftManager && !customDraftKey && saved.id) {
612
- state.draftManager.updateStorageKey(getDraftStorageKey(saved.id, undefined, fd.storagePrefix));
613
- }
614
- // A saved workflow has no draft
615
- state.draftManager?.markAsSaved();
616
- }
617
- });
618
- },
684
+ save: async () => saveFromMount(),
619
685
  export: () => {
620
686
  globalExportWorkflow({ instance: fd });
621
687
  },
@@ -638,13 +704,24 @@ export async function mountFlowDropApp(container, options = {}) {
638
704
  // WebMCP is on: the chat panel's tool loop offers `save`, `run` and
639
705
  // `run_status` through them, so the built-in assistant and a browser agent
640
706
  // persist and run the same way.
641
- const defaultOnSave = async () => (await mountedApp.save())
642
- ? undefined
643
- : {
707
+ const defaultOnSave = async () => {
708
+ // The dialog answers through the callback, before the save resolves.
709
+ const heard = {};
710
+ if (await saveFromMount((outcome) => (heard.refused = outcome)))
711
+ return undefined;
712
+ if (heard.refused) {
713
+ return {
714
+ ok: false,
715
+ code: 'WORKFLOW_IN_USE_BREAKING',
716
+ message: SAVE_REFUSED_MESSAGES[heard.refused]
717
+ };
718
+ }
719
+ return {
644
720
  ok: false,
645
721
  code: 'UNAVAILABLE',
646
722
  message: 'Nothing was saved: the host cancelled the save or no workflow is loaded.'
647
723
  };
724
+ };
648
725
  // Hook keys are merged through `definedHostHooks` on both inputs, so an
649
726
  // explicit `onSave: undefined` in either never shadows the default.
650
727
  const webmcpGiven = webmcp === true || !webmcp ? {} : webmcp;
@@ -680,7 +757,7 @@ export async function mountFlowDropApp(container, options = {}) {
680
757
  * @returns Promise resolving to a MountedFlowDropApp instance
681
758
  */
682
759
  export async function mountWorkflowEditor(container, options = {}) {
683
- const { workflow, endpointConfig, portConfig, categories, authProvider, instanceId, builtinEditors, contextMenu } = options;
760
+ const { workflow, endpointConfig, portConfig, categories, authProvider, instanceId, builtinEditors, contextMenu, lock, onLockAction } = options;
684
761
  // Per-instance state container (see mountFlowDropApp)
685
762
  const { fd, isDefault } = acquireInstance(instanceId);
686
763
  // Resolve and apply endpoint config, port config and categories to this
@@ -696,6 +773,10 @@ export async function mountWorkflowEditor(container, options = {}) {
696
773
  if (workflow) {
697
774
  fd.workflow.initialize(workflow);
698
775
  }
776
+ // A lock does not stop `initialize`, so the order of the two does not matter.
777
+ if (lock !== undefined)
778
+ fd.lock.set(lock);
779
+ const unsubscribeLockAction = onLockAction ? fd.lock.onAction((id) => onLockAction(id)) : null;
699
780
  // Create the Svelte component
700
781
  const svelteApp = mount(WorkflowEditor, {
701
782
  target: container,
@@ -712,12 +793,15 @@ export async function mountWorkflowEditor(container, options = {}) {
712
793
  // Create the mounted app interface (simpler version)
713
794
  const mountedApp = {
714
795
  instance: fd,
796
+ setLock: (next) => fd.lock.set(next),
715
797
  destroy: () => {
716
798
  destroyed = true;
717
799
  for (const cancel of [...pendingRuns])
718
800
  cancel();
801
+ unsubscribeLockAction?.();
719
802
  releaseInstance(fd, isDefault);
720
803
  unmount(svelteApp);
804
+ releaseLock(fd, isDefault);
721
805
  },
722
806
  isDirty: () => fd.workflow.isDirty,
723
807
  markAsSaved: () => fd.workflow.markAsSaved(),
@@ -7,6 +7,7 @@
7
7
  * @module types/events
8
8
  */
9
9
  import type { Workflow, NodeExecutionInfo, WorkflowNode, ConfigValues, ExternalEditLink } from './index.js';
10
+ import type { SavedCopy } from './impact.js';
10
11
  import type { SwapEventContext, SwapResult } from '../utils/nodeSwap.js';
11
12
  /**
12
13
  * Types of workflow changes
@@ -91,6 +92,22 @@ export interface FlowDropEventHandlers {
91
92
  * @param workflow - The saved workflow (may include server-assigned IDs)
92
93
  */
93
94
  onAfterSave?: (workflow: Workflow) => Promise<void>;
95
+ /**
96
+ * Called after the refused save was saved as a copy instead ("Save as a copy"
97
+ * in the save dialog).
98
+ *
99
+ * The original workflow is unchanged and the editor still holds the draft.
100
+ * Without this handler the editor follows `copy.editorUrl` (when the backend
101
+ * sent one): it first marks the workflow as saved, so the leave prompt stays
102
+ * quiet, and drops the stored draft of the original. With no URL either, it
103
+ * shows a "saved a copy" toast and stays as it is. With this handler the host
104
+ * decides what happens next and the editor does nothing else. An error thrown
105
+ * here is logged and never counts as a failed save.
106
+ *
107
+ * @param copy - The new workflow: its id and editor URL, when the backend names them
108
+ * @param workflow - The draft that was copied
109
+ */
110
+ onSavedAsCopy?: (copy: SavedCopy, workflow: Workflow) => void | Promise<void>;
94
111
  /**
95
112
  * Called when save fails
96
113
  *
@@ -22,4 +22,56 @@ export interface ImpactReport {
22
22
  interfaceLevel: string;
23
23
  interfaceBreaking: boolean;
24
24
  items: ImpactItem[];
25
+ /** The save is refused while things use the workflow. Absent from an older backend: `false`. */
26
+ refused?: boolean;
27
+ /** The backend's own words for the refusal, when it gives them. */
28
+ refusedMessage?: string | null;
29
+ /** Where to POST the draft to save it as a new workflow instead (`Save as a copy`). */
30
+ copyUrl?: string | null;
31
+ /** Renamed inputs and outputs, with the places that follow when the person agrees. */
32
+ renames?: ImpactRename[];
25
33
  }
34
+ /** An interface input or output the draft renames. */
35
+ export interface ImpactRename {
36
+ direction: 'input' | 'output';
37
+ from: string;
38
+ to: string;
39
+ /** What uses the old name and is updated when the rename is followed. */
40
+ places: ImpactRenamePlace[];
41
+ }
42
+ /** One place that uses a renamed input or output. */
43
+ export interface ImpactRenamePlace {
44
+ kind: string;
45
+ label: string;
46
+ /** Where to look at the place, when the backend knows. */
47
+ url: string | null;
48
+ /** What the rename does to it, when the backend says. */
49
+ message?: string;
50
+ /** `false` when the place is switched off; absent when the backend does not say. */
51
+ enabled?: boolean;
52
+ }
53
+ /** The new workflow a `Save as a copy` made. */
54
+ export interface SavedCopy {
55
+ /** The new workflow id, when the backend names it. */
56
+ id: string | null;
57
+ /** The editor URL of the copy, when the backend names it. */
58
+ editorUrl: string | null;
59
+ }
60
+ /** What the person decided in the impact dialog. Internal: nothing public takes or returns it. */
61
+ export type ImpactAnswer =
62
+ /** Save. `followRenames` is set only when the dialog listed renames. */
63
+ {
64
+ action: 'save';
65
+ followRenames?: boolean;
66
+ } | {
67
+ action: 'cancel';
68
+ }
69
+ /** The draft was saved as a new workflow. */
70
+ | {
71
+ action: 'copied';
72
+ copy: SavedCopy;
73
+ }
74
+ /** The unsaved edits were thrown away and the saved version was loaded. */
75
+ | {
76
+ action: 'discarded';
77
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Editor lock: why a workflow is read-only, and what the person may do about it.
3
+ *
4
+ * A host passes a lock (the `lock` mount option, or `app.setLock(...)`) while
5
+ * something stops the workflow from being edited, for example a workflow that
6
+ * live users depend on, or one a module manages. The editor then refuses every
7
+ * edit and shows the reasons and the actions in a banner above the canvas. An
8
+ * action is only a button: the host answers `onLockAction(id)`, and "Edit
9
+ * anyway" is just an action the host answers by removing the lock.
10
+ *
11
+ * @module types/lock
12
+ */
13
+ /** One reason the workflow is locked. */
14
+ export interface EditorLockReason {
15
+ /** What kind of reason this is, for example `'in_use'` or `'managed'`. Free text; the editor does not interpret it. */
16
+ kind: string;
17
+ /** A plain sentence for the person. Shown as text, never as HTML. */
18
+ message: string;
19
+ /** Where to read more (for example the page that lists who uses the workflow). Only `http(s)` and site-relative links are drawn. */
20
+ url?: string | null;
21
+ }
22
+ /** One button on the lock banner. */
23
+ export interface EditorLockAction {
24
+ /** Handed to `onLockAction` when the button is pressed. */
25
+ id: string;
26
+ /** The button text. */
27
+ label: string;
28
+ /** Draw the button as the main one. */
29
+ primary?: boolean;
30
+ }
31
+ /** A lock on the editor. `null` (or no lock) means the editor is not locked. */
32
+ export interface EditorLock {
33
+ reasons: EditorLockReason[];
34
+ actions: EditorLockAction[];
35
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Editor lock: why a workflow is read-only, and what the person may do about it.
3
+ *
4
+ * A host passes a lock (the `lock` mount option, or `app.setLock(...)`) while
5
+ * something stops the workflow from being edited, for example a workflow that
6
+ * live users depend on, or one a module manages. The editor then refuses every
7
+ * edit and shows the reasons and the actions in a banner above the canvas. An
8
+ * action is only a button: the host answers `onLockAction(id)`, and "Edit
9
+ * anyway" is just an action the host answers by removing the lock.
10
+ *
11
+ * @module types/lock
12
+ */
13
+ export {};
@@ -10,6 +10,12 @@ export interface NavbarAction {
10
10
  icon?: string;
11
11
  variant?: 'primary' | 'secondary' | 'outline';
12
12
  onclick?: (event: Event) => void;
13
+ /**
14
+ * The action is shown but cannot be used right now (Save on a locked
15
+ * workflow): it is dimmed, announced as disabled, and ignores clicks and
16
+ * the Save shortcut.
17
+ */
18
+ disabled?: boolean;
13
19
  /** If true, opens link in new tab with `rel="noopener noreferrer"`. */
14
20
  external?: boolean;
15
21
  /**
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Links a backend or host hands the editor: which ones it may draw, follow or
3
+ * send a request to.
4
+ *
5
+ * One set of rules for every place that takes such a link (the lock banner,
6
+ * the save dialog, a saved copy's editor URL, the copy endpoint), so they
7
+ * cannot drift apart.
8
+ *
9
+ * @module utils/links
10
+ */
11
+ /**
12
+ * Whether `url` is a path on this site: it starts with one `/`. `//host` and
13
+ * `/\host` are not paths, browsers read both as another site.
14
+ */
15
+ export declare function isSitePath(url: string): boolean;
16
+ /**
17
+ * The link as given when it may be drawn or followed (a site path or an
18
+ * `http(s)` address), otherwise `null`.
19
+ */
20
+ export declare function safeLinkUrl(url: string | null | undefined): string | null;
21
+ /**
22
+ * Where a request may go when it carries the editor's draft and auth headers:
23
+ * a path on this site, or an `http(s)` address on this site's origin or on the
24
+ * API's origin. Answers the full address, or `null` when it may not go there.
25
+ *
26
+ * @param url - The address as the backend gave it
27
+ * @param apiBaseUrl - The API base URL (may itself be a path on this site)
28
+ */
29
+ export declare function resolveRequestUrl(url: string, apiBaseUrl: string): string | null;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Links a backend or host hands the editor: which ones it may draw, follow or
3
+ * send a request to.
4
+ *
5
+ * One set of rules for every place that takes such a link (the lock banner,
6
+ * the save dialog, a saved copy's editor URL, the copy endpoint), so they
7
+ * cannot drift apart.
8
+ *
9
+ * @module utils/links
10
+ */
11
+ /** Browsers drop tabs and line breaks inside a URL, so a link that holds one reads differently. */
12
+ function hasLineBreakOrTab(url) {
13
+ return /[\t\r\n]/.test(url);
14
+ }
15
+ /**
16
+ * Whether `url` is a path on this site: it starts with one `/`. `//host` and
17
+ * `/\host` are not paths, browsers read both as another site.
18
+ */
19
+ export function isSitePath(url) {
20
+ return !hasLineBreakOrTab(url) && /^\/(?![/\\])/.test(url);
21
+ }
22
+ /**
23
+ * The link as given when it may be drawn or followed (a site path or an
24
+ * `http(s)` address), otherwise `null`.
25
+ */
26
+ export function safeLinkUrl(url) {
27
+ if (!url || hasLineBreakOrTab(url))
28
+ return null;
29
+ if (isSitePath(url))
30
+ return url;
31
+ try {
32
+ const protocol = new URL(url).protocol;
33
+ return protocol === 'https:' || protocol === 'http:' ? url : null;
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * Where a request may go when it carries the editor's draft and auth headers:
41
+ * a path on this site, or an `http(s)` address on this site's origin or on the
42
+ * API's origin. Answers the full address, or `null` when it may not go there.
43
+ *
44
+ * @param url - The address as the backend gave it
45
+ * @param apiBaseUrl - The API base URL (may itself be a path on this site)
46
+ */
47
+ export function resolveRequestUrl(url, apiBaseUrl) {
48
+ if (!url || hasLineBreakOrTab(url) || typeof window === 'undefined')
49
+ return null;
50
+ const here = window.location.href;
51
+ try {
52
+ if (isSitePath(url))
53
+ return new URL(url, here).href;
54
+ const target = new URL(url);
55
+ if (target.protocol !== 'https:' && target.protocol !== 'http:')
56
+ return null;
57
+ const allowed = [new URL(here).origin, new URL(apiBaseUrl, here).origin];
58
+ return allowed.includes(target.origin) ? target.href : null;
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
@@ -82,6 +82,10 @@ function describeError(err) {
82
82
  const reasons = errorDetails(err);
83
83
  return reasons.length ? `${err.message}: ${reasons.join('; ')}` : err.message;
84
84
  }
85
+ /** The answer for a change a locked editor would refuse, given before any approval is asked. */
86
+ function lockedResult() {
87
+ return errorResult('LOCKED', 'The editor is locked (read-only), so this change was not made. Ask the user to unlock it.');
88
+ }
85
89
  function stripResult(result) {
86
90
  if (result.ok) {
87
91
  const out = { ok: true, message: result.message };
@@ -161,7 +165,9 @@ export function buildHostToolDescriptors(hooks) {
161
165
  verb: 'save',
162
166
  description: 'Save the workflow to the server. Nothing an agent changes is persisted until ' +
163
167
  'this runs or the person clicks Save. Asks for approval; cannot be undone from ' +
164
- 'the editor. Fails with FORBIDDEN when the user may not save, CONFLICT when the ' +
168
+ 'the editor. Fails with FORBIDDEN when the user may not save, LOCKED when the editor is ' +
169
+ 'locked (read-only), WORKFLOW_IN_USE_BREAKING when the change breaks places that use the ' +
170
+ 'workflow (the person was shown them; do not retry), CONFLICT when the ' +
165
171
  'server copy changed since it was loaded (reload the page), INVALID when the ' +
166
172
  'server rejected the workflow — the message says which node or port.',
167
173
  inputSchema: EMPTY_SCHEMA,
@@ -269,6 +275,9 @@ export function createToolRuntime(options) {
269
275
  const context = createStoreCommandContext(nodeTypes(), onUIAction, instance);
270
276
  if (!context)
271
277
  return errorResult('NO_WORKFLOW', 'No workflow is loaded in this editor');
278
+ // A locked editor refuses every change: say so now, do not ask first and refuse after.
279
+ if (instance.workflow.locked && needsApproval(commands))
280
+ return lockedResult();
272
281
  // D3: reads and view changes run; document changes wait for the gate.
273
282
  if (needsApproval(commands)) {
274
283
  let approved;
@@ -357,6 +366,9 @@ export function createToolRuntime(options) {
357
366
  if (workflowCan('save') === false) {
358
367
  return errorResult('FORBIDDEN', 'Saving this workflow is not permitted');
359
368
  }
369
+ // The editor refuses a save while locked; do not ask for approval first.
370
+ if (instance.workflow.locked)
371
+ return lockedResult();
360
372
  const refused = await askHostGate('save');
361
373
  if (refused)
362
374
  return refused;
@@ -460,12 +472,13 @@ export function createToolRuntime(options) {
460
472
  const host = hostByVerb.get(name);
461
473
  if (host) {
462
474
  const mutating = !host.readOnly;
475
+ const refused = name === 'save' && instance.workflow.locked;
463
476
  return {
464
477
  commands: [],
465
478
  skipped: [],
466
479
  mutating,
467
480
  consequential: host.consequential,
468
- asks: gate.asks && mutating
481
+ asks: gate.asks && mutating && !refused
469
482
  };
470
483
  }
471
484
  const descriptor = byVerb.get(name);
@@ -481,7 +494,7 @@ export function createToolRuntime(options) {
481
494
  skipped,
482
495
  mutating,
483
496
  consequential: false,
484
- asks: gate.asks && mutating && !gate.editsPreApproved
497
+ asks: gate.asks && mutating && !gate.editsPreApproved && !instance.workflow.locked
485
498
  };
486
499
  }
487
500
  return {
@@ -114,14 +114,17 @@ export interface ModelContextLike {
114
114
  * (`CONFLICT`, `NOT_FOUND`); the rest name what a browser agent must do next.
115
115
  *
116
116
  * - `FORBIDDEN` — the server refused; the agent should tell the user.
117
+ * - `LOCKED` — the editor is locked (read-only); nothing was changed and nobody was asked.
117
118
  * - `UNAVAILABLE` — nothing to act on yet (unsaved workflow, no runtime).
118
119
  * - `NEEDS_APPROVAL` — a person must approve in the UI first.
119
120
  * - `INVALID` — the workflow failed validation; `message` says where.
120
121
  * - `CONFLICT` — the server copy changed since it was loaded; reload.
122
+ * - `WORKFLOW_IN_USE_BREAKING` — the server refused the save because the change
123
+ * breaks places that use the workflow; the person has been shown them.
121
124
  * - `PENDING` — a run is paused for a person (never for the agent, D8).
122
125
  * - `NOT_FOUND` — the run id is unknown.
123
126
  */
124
- export type HostCode = 'FORBIDDEN' | 'UNAVAILABLE' | 'NEEDS_APPROVAL' | 'INVALID' | 'CONFLICT' | 'PENDING' | 'NOT_FOUND' | (string & Record<never, never>);
127
+ export type HostCode = 'FORBIDDEN' | 'LOCKED' | 'UNAVAILABLE' | 'NEEDS_APPROVAL' | 'INVALID' | 'CONFLICT' | 'PENDING' | 'NOT_FOUND' | (string & Record<never, never>);
125
128
  /**
126
129
  * What every host hook returns. `ok: false` needs a `code`; `ok: true` may
127
130
  * still carry one (`PENDING`). `can` lets a host refresh what the user may do
@@ -158,6 +161,13 @@ export interface RunStatus {
158
161
  pending?: RunPending | null;
159
162
  /** Why an execution budget paused the run, when it did. */
160
163
  pausedReason?: string | null;
164
+ /**
165
+ * What the site says is happening to the run. `kind: 'waiting_for_worker'`
166
+ * makes the run bar say the run waits for a worker.
167
+ */
168
+ activity?: {
169
+ kind?: string;
170
+ } | null;
161
171
  /** The run's output once it has one. Host-shaped. */
162
172
  outputs?: unknown;
163
173
  /** Per-node status once the host has it. Host-shaped. */
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.17.0",
6
+ "version": "2.18.0",
7
7
  "author": "Shibin Das (D34dMan)",
8
8
  "bugs": {
9
9
  "url": "https://github.com/flowdrop-io/flowdrop/issues"