@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
@@ -15,11 +15,19 @@ import { DEFAULT_WORKFLOW_FORMAT } from '../types/index.js';
15
15
  import { stripExecutionInfo } from '../utils/nodeStatus.js';
16
16
  import { playgroundForSave } from '../utils/playgroundChat.js';
17
17
  import { buildSaveBody } from '../utils/workflowDraft.js';
18
- import { apiToasts, workflowToasts, dismissToast, showInfo } from './toastService.js';
19
- import { checkImpact, impactSupported } from './impactService.js';
18
+ import { apiToasts, workflowToasts, dismissToast, showInfo, showSuccess } from './toastService.js';
19
+ import { logger } from '../utils/logger.js';
20
+ import { checkImpact, impactSupported, isSafeCopyUrl, parseImpactItems, saveAsCopy } from './impactService.js';
20
21
  import { confirmImpact, impactPending } from './impactGate.js';
21
22
  import { scopeSelector } from '../themes/scopedSkinCss.js';
22
23
  import { DEFAULT_FEATURES } from '../types/events.js';
24
+ function refusalOutcome(answer) {
25
+ return answer.action === 'copied'
26
+ ? 'copied'
27
+ : answer.action === 'discarded'
28
+ ? 'discarded'
29
+ : 'kept';
30
+ }
23
31
  // ---------------------------------------------------------------------------
24
32
  // Internal helpers
25
33
  // ---------------------------------------------------------------------------
@@ -47,6 +55,32 @@ function ensureApiConfiguration(fd) {
47
55
  });
48
56
  fd.api.configure(config);
49
57
  }
58
+ /** The error code of a save refused because things use the workflow and the change breaks them. */
59
+ const IN_USE_BREAKING = 'WORKFLOW_IN_USE_BREAKING';
60
+ /**
61
+ * The refused-state report for a save the backend refused with
62
+ * WORKFLOW_IN_USE_BREAKING, or `null` for any other error. What the refusal
63
+ * does not carry (the items, the copy URL) comes from the earlier check.
64
+ */
65
+ function inUseRefusal(error, earlier) {
66
+ const e = error;
67
+ if (e?.errorData?.error_code !== IN_USE_BREAKING)
68
+ return null;
69
+ const data = e.errorData;
70
+ const details = data.details;
71
+ const fromError = parseImpactItems(Array.isArray(details) ? details : (details?.items ?? data.items));
72
+ const copyUrl = data.copyUrl ?? data.copy_url;
73
+ return {
74
+ confirm: true,
75
+ interfaceLevel: earlier?.interfaceLevel ?? '',
76
+ interfaceBreaking: earlier?.interfaceBreaking ?? true,
77
+ items: fromError.length > 0 ? fromError : (earlier?.items ?? []),
78
+ refused: true,
79
+ refusedMessage: typeof data.error === 'string' && data.error ? data.error : null,
80
+ copyUrl: typeof copyUrl === 'string' && copyUrl ? copyUrl : (earlier?.copyUrl ?? null),
81
+ renames: []
82
+ };
83
+ }
50
84
  /** The error when a save was refused because the workflow changed on the server meanwhile. */
51
85
  function isSaveConflict(error) {
52
86
  const e = error;
@@ -129,11 +163,27 @@ async function runSave(fd, options) {
129
163
  const { eventHandlers, onMarkAsSaved, onSaved } = options;
130
164
  const features = { ...DEFAULT_FEATURES, ...options.features };
131
165
  const readWorkflow = () => fd.workflow.current;
166
+ // What the impact check said, and whether the person asked renames to be followed.
167
+ let lastReport;
168
+ let followRenames;
169
+ let draftForCopy;
170
+ // The edit version the snapshot was taken at (set once the body is built).
171
+ let snapshotVersion;
132
172
  // A save while the impact question is open is dropped, not queued: the open
133
173
  // dialog is the one answer. Checked before the flush, which would blur its
134
174
  // focused button.
135
175
  if (impactPending(fd))
136
176
  return false;
177
+ // A locked workflow is not saved: it cannot have changed, and the host asked for no edits.
178
+ // A person's save says so: a host's own Save button is not disabled by the lock.
179
+ if (fd.workflow.locked) {
180
+ if (options.interactive !== false && features.showToasts) {
181
+ showInfo(fd.messages().lock.saveRefused, {
182
+ id: `flowdrop:save-locked:${fd.skinScope ?? ''}`
183
+ });
184
+ }
185
+ return false;
186
+ }
137
187
  // Flush pending form changes (single location for this logic)
138
188
  await flushPendingFormChanges();
139
189
  // Get current workflow from the instance's store after flush
@@ -164,6 +214,8 @@ async function runSave(fd, options) {
164
214
  const finalWorkflow = buildSaveBody(currentWorkflow, workflowId);
165
215
  // What this snapshot contains: only up to here may be marked saved.
166
216
  let savedVersion = fd.workflow.editVersion;
217
+ draftForCopy = finalWorkflow;
218
+ snapshotVersion = savedVersion;
167
219
  // Ask what this save changes for what uses the workflow. A backend
168
220
  // without the route (or that does not know the workflow) leaves the save
169
221
  // unasked; a failed check is shown and the person decides.
@@ -173,7 +225,13 @@ async function runSave(fd, options) {
173
225
  // This instance's editor (a page may hold several), for the dialog's skin.
174
226
  const host = (fd.skinScope ? document.querySelector(scopeSelector(fd.skinScope)) : null) ??
175
227
  document.body;
176
- const needsAnswer = (result.status === 'ok' && result.report.confirm) || result.status === 'error';
228
+ if (result.status === 'ok')
229
+ lastReport = result.report;
230
+ const needsAnswer = (result.status === 'ok' &&
231
+ (result.report.confirm ||
232
+ result.report.refused === true ||
233
+ (result.report.renames ?? []).some((r) => r.places.length > 0))) ||
234
+ result.status === 'error';
177
235
  if (needsAnswer) {
178
236
  if (!interactive) {
179
237
  // Say so once per version, then stay quiet until something changes.
@@ -188,10 +246,19 @@ async function runSave(fd, options) {
188
246
  error: result.status === 'error' ? result.message : undefined,
189
247
  host,
190
248
  instance: fd,
191
- messages: fd.messages
249
+ messages: fd.messages,
250
+ ...refusalActions(fd, options, result.status === 'ok' ? result.report : undefined, finalWorkflow)
192
251
  });
193
- if (!answer)
252
+ if (result.status === 'ok' && result.report.refused === true) {
253
+ options.onRefused?.(refusalOutcome(answer));
254
+ }
255
+ if (answer.action === 'copied') {
256
+ await afterSavedAsCopy(answer.copy, finalWorkflow, fd, options, features.showToasts);
257
+ return false;
258
+ }
259
+ if (answer.action !== 'save')
194
260
  return false;
261
+ followRenames = answer.followRenames;
195
262
  }
196
263
  }
197
264
  // Allow the parent to cancel the save (after the impact question, so a
@@ -207,7 +274,9 @@ async function runSave(fd, options) {
207
274
  // id-presence (computed above) decides update vs create — never UUID-regex.
208
275
  const apiClient = fd.api.client;
209
276
  const savedWorkflow = isExistingWorkflow
210
- ? await apiClient.updateWorkflow(finalWorkflow.id, finalWorkflow)
277
+ ? followRenames === undefined
278
+ ? await apiClient.updateWorkflow(finalWorkflow.id, finalWorkflow)
279
+ : await apiClient.updateWorkflow(finalWorkflow.id, finalWorkflow, { followRenames })
211
280
  : await apiClient.saveWorkflow(finalWorkflow);
212
281
  // If the server assigned a new ID, sync the store
213
282
  if (savedWorkflow.id && savedWorkflow.id !== finalWorkflow.id) {
@@ -262,6 +331,36 @@ async function runSave(fd, options) {
262
331
  if (loadingToast)
263
332
  dismissToast(loadingToast);
264
333
  const errorObj = error instanceof Error ? error : new Error('Unknown error occurred');
334
+ // Things use the workflow and this change breaks them: say so, instead of
335
+ // a failure toast. The refusal is decided before anything reports a failed
336
+ // save, because it is an answer, not a failure, and is not rethrown.
337
+ const refusal = draftForCopy ? inUseRefusal(error, lastReport) : null;
338
+ if (refusal && draftForCopy) {
339
+ if (!interactive) {
340
+ // Autosave never asks: say so once per version, then stay quiet until
341
+ // something changes (the same as a check that needs an answer).
342
+ const version = snapshotVersion;
343
+ if (autosaveRefusedAt.get(fd) !== version && features.showToasts) {
344
+ showInfo(fd.messages().autoSave.waiting, { id: autosaveToastId(fd) });
345
+ }
346
+ autosaveRefusedAt.set(fd, version);
347
+ return false;
348
+ }
349
+ const host = (fd.skinScope ? document.querySelector(scopeSelector(fd.skinScope)) : null) ??
350
+ document.body;
351
+ const answer = await confirmImpact({
352
+ report: refusal,
353
+ host,
354
+ instance: fd,
355
+ messages: fd.messages,
356
+ ...refusalActions(fd, options, refusal, draftForCopy)
357
+ });
358
+ options.onRefused?.(refusalOutcome(answer));
359
+ if (answer.action === 'copied') {
360
+ await afterSavedAsCopy(answer.copy, draftForCopy, fd, options, features.showToasts);
361
+ }
362
+ return false;
363
+ }
265
364
  // onSaveError hook
266
365
  const currentWorkflowForError = readWorkflow();
267
366
  if (eventHandlers?.onSaveError && currentWorkflowForError) {
@@ -296,6 +395,67 @@ async function runSave(fd, options) {
296
395
  throw error;
297
396
  }
298
397
  }
398
+ /**
399
+ * What the refused state offers: "Save as a copy" when the backend named a
400
+ * safe `copyUrl`, "Discard my changes" when the draft has an id to load the
401
+ * saved version by. Discarding drops every unsaved edit and the undo history.
402
+ */
403
+ function refusalActions(fd, options, report, draft) {
404
+ const config = fd.api.config;
405
+ const copyUrl = report?.copyUrl;
406
+ return {
407
+ saveAsCopy: report?.refused && copyUrl && config && isSafeCopyUrl(config, copyUrl)
408
+ ? () => saveAsCopy(config, fd.api.authProvider, copyUrl, draft)
409
+ : undefined,
410
+ discard: report?.refused && draft.id
411
+ ? async () => {
412
+ const loaded = await fd.api.client.loadWorkflow(draft.id);
413
+ fd.workflow.initialize(loaded);
414
+ // Discarding resets the edit versions, so a refusal remembered
415
+ // for a version number no longer describes anything.
416
+ autosaveRefusedAt.delete(fd);
417
+ dismissToast(autosaveToastId(fd));
418
+ fd.doctor.schedule();
419
+ // The edits are gone: so is their stored draft. The host hears of the load as of any other.
420
+ options.onDiscardDraft?.();
421
+ options.eventHandlers?.onWorkflowLoad?.(loaded);
422
+ }
423
+ : undefined
424
+ };
425
+ }
426
+ /**
427
+ * The draft now lives on as a new workflow. The host's `onSavedAsCopy` takes
428
+ * over when it has one. Otherwise the editor follows the copy's editor URL,
429
+ * after clearing the unsaved state so the leave guard stays quiet and the
430
+ * original's draft is not offered again; with no URL it says the copy exists
431
+ * and stays as it is. A failure here never counts as a failed save: the copy
432
+ * exists.
433
+ */
434
+ async function afterSavedAsCopy(copy, draft, fd, options, showToasts) {
435
+ try {
436
+ const handler = options.eventHandlers?.onSavedAsCopy;
437
+ if (handler) {
438
+ await handler(copy, draft);
439
+ return;
440
+ }
441
+ if (copy.editorUrl && typeof window !== 'undefined') {
442
+ const version = fd.workflow.editVersion;
443
+ if (options.onMarkAsSaved)
444
+ options.onMarkAsSaved(version);
445
+ else
446
+ fd.workflow.markAsSaved(version);
447
+ options.onDiscardDraft?.();
448
+ window.location.assign(copy.editorUrl);
449
+ return;
450
+ }
451
+ if (showToasts) {
452
+ showSuccess(fd.messages().impact.refused.copied);
453
+ }
454
+ }
455
+ catch (error) {
456
+ logger.error('Handling the saved copy failed', error);
457
+ }
458
+ }
299
459
  /**
300
460
  * Export the current workflow as a downloadable JSON file.
301
461
  *
@@ -9,7 +9,7 @@
9
9
  * @module services/impactGate
10
10
  */
11
11
  import { type Messages } from '../messages/index.js';
12
- import type { ImpactReport } from '../types/impact.js';
12
+ import type { ImpactAnswer, ImpactReport, SavedCopy } from '../types/impact.js';
13
13
  import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
14
14
  export interface ConfirmImpactOptions {
15
15
  /** What the check found. */
@@ -27,8 +27,12 @@ export interface ConfirmImpactOptions {
27
27
  * second ask while one is open resolves `false` and opens no second dialog.
28
28
  */
29
29
  instance?: FlowDropInstance;
30
+ /** Saves the draft as a new workflow; offered in the refused state when the report has a `copyUrl`. */
31
+ saveAsCopy?: () => Promise<SavedCopy>;
32
+ /** Throws away the unsaved edits and loads the saved version; offered in the refused state. */
33
+ discard?: () => Promise<void>;
30
34
  }
31
35
  /** Whether this instance has an impact question open. */
32
36
  export declare function impactPending(instance: FlowDropInstance): boolean;
33
- /** Ask whether the save may go ahead. Resolves `true` to save, `false` to cancel. */
34
- export declare function confirmImpact(options: ConfirmImpactOptions): Promise<boolean>;
37
+ /** Ask whether the save may go ahead, and answer what the person chose. */
38
+ export declare function confirmImpact(options: ConfirmImpactOptions): Promise<ImpactAnswer>;
@@ -18,15 +18,15 @@ const pending = new WeakSet();
18
18
  export function impactPending(instance) {
19
19
  return pending.has(instance);
20
20
  }
21
- /** Ask whether the save may go ahead. Resolves `true` to save, `false` to cancel. */
21
+ /** Ask whether the save may go ahead, and answer what the person chose. */
22
22
  export function confirmImpact(options) {
23
23
  if (typeof document === 'undefined') {
24
24
  // No DOM to ask in: refuse rather than silently save.
25
- return Promise.resolve(false);
25
+ return Promise.resolve({ action: 'cancel' });
26
26
  }
27
27
  const key = options.instance;
28
28
  if (key && pending.has(key))
29
- return Promise.resolve(false);
29
+ return Promise.resolve({ action: 'cancel' });
30
30
  if (key)
31
31
  pending.add(key);
32
32
  return new Promise((resolve) => {
@@ -42,7 +42,7 @@ export function confirmImpact(options) {
42
42
  document.body.appendChild(element);
43
43
  let component = null;
44
44
  let forget = null;
45
- const finish = (save) => {
45
+ const finish = (answer) => {
46
46
  if (settled)
47
47
  return;
48
48
  settled = true;
@@ -53,7 +53,7 @@ export function confirmImpact(options) {
53
53
  void unmount(component);
54
54
  theme?.destroy();
55
55
  element.remove();
56
- resolve(save);
56
+ resolve(answer);
57
57
  };
58
58
  component = mount(ImpactConfirm, {
59
59
  target: element,
@@ -61,10 +61,12 @@ export function confirmImpact(options) {
61
61
  props: {
62
62
  report: options.report ?? null,
63
63
  error: options.error,
64
- onResolve: finish
64
+ onResolve: finish,
65
+ onSaveAsCopy: options.saveAsCopy,
66
+ onDiscard: options.discard
65
67
  }
66
68
  });
67
69
  // The instance going away takes the question with it.
68
- forget = key?.onDestroy(() => finish(false)) ?? null;
70
+ forget = key?.onDestroy(() => finish({ action: 'cancel' })) ?? null;
69
71
  });
70
72
  }
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import type { EndpointConfig } from '../config/endpoints.js';
11
11
  import type { AuthProvider } from '../types/auth.js';
12
- import type { ImpactReport } from '../types/impact.js';
12
+ import type { ImpactItem, ImpactReport, SavedCopy } from '../types/impact.js';
13
13
  import type { Workflow } from '../types/index.js';
14
14
  export type ImpactResult = {
15
15
  status: 'ok';
@@ -24,5 +24,22 @@ export type ImpactResult = {
24
24
  };
25
25
  /** Whether the configuration offers the impact check at all. */
26
26
  export declare function impactSupported(config: EndpointConfig | null | undefined): boolean;
27
+ /** Read a list of impact items; entries without a label and message are skipped. */
28
+ export declare function parseImpactItems(raw: unknown): ImpactItem[];
29
+ export declare function parseReport(data: unknown): ImpactReport;
27
30
  /** Ask what saving `draft` over the saved workflow `workflowId` would change. */
28
31
  export declare function checkImpact(config: EndpointConfig, authProvider: AuthProvider | undefined, workflowId: string, draft: Workflow): Promise<ImpactResult>;
32
+ /**
33
+ * Whether a `copyUrl` may receive the draft and the auth headers: a path on
34
+ * this site (one `/`, not `//` or `/\`), or an `http(s)` address on this
35
+ * site's origin or the API's.
36
+ */
37
+ export declare function isSafeCopyUrl(config: EndpointConfig, copyUrl: string): boolean;
38
+ /**
39
+ * Save the draft as a new workflow: POST it to the `copyUrl` the impact check
40
+ * named (a path on this site, or a full URL on this site's or the API's
41
+ * origin). Throws with the backend's
42
+ * reason when it refuses. The answer names the copy as `{ data: { id,
43
+ * editorUrl } }`; either may be missing.
44
+ */
45
+ export declare function saveAsCopy(config: EndpointConfig, authProvider: AuthProvider | undefined, copyUrl: string, draft: Workflow): Promise<SavedCopy>;
@@ -9,19 +9,19 @@
9
9
  */
10
10
  import { buildEndpointUrl } from '../config/endpoints.js';
11
11
  import { authenticatedFetch } from '../utils/fetchWithAuth.js';
12
+ import { resolveRequestUrl, safeLinkUrl } from '../utils/links.js';
12
13
  const SEVERITIES = ['breaks', 'changes', 'info'];
13
14
  /** Whether the configuration offers the impact check at all. */
14
15
  export function impactSupported(config) {
15
16
  return !!config?.endpoints?.workflows?.impact;
16
17
  }
17
- function parseReport(data) {
18
- const d = (typeof data === 'object' && data !== null ? data : {});
19
- const iface = (typeof d.interface === 'object' && d.interface !== null ? d.interface : {});
18
+ /** Read a list of impact items; entries without a label and message are skipped. */
19
+ export function parseImpactItems(raw) {
20
20
  const items = [];
21
- for (const raw of Array.isArray(d.items) ? d.items : []) {
22
- if (typeof raw !== 'object' || raw === null)
21
+ for (const entry of Array.isArray(raw) ? raw : []) {
22
+ if (typeof entry !== 'object' || entry === null)
23
23
  continue;
24
- const i = raw;
24
+ const i = entry;
25
25
  if (typeof i.label !== 'string' || typeof i.message !== 'string')
26
26
  continue;
27
27
  items.push({
@@ -34,11 +34,63 @@ function parseReport(data) {
34
34
  url: typeof i.url === 'string' ? i.url : null
35
35
  });
36
36
  }
37
+ return items;
38
+ }
39
+ /** Read the places a rename touches; only a label is required. */
40
+ function parseRenamePlaces(raw) {
41
+ const places = [];
42
+ for (const entry of Array.isArray(raw) ? raw : []) {
43
+ if (typeof entry !== 'object' || entry === null)
44
+ continue;
45
+ const p = entry;
46
+ if (typeof p.label !== 'string' || p.label === '')
47
+ continue;
48
+ places.push({
49
+ kind: typeof p.kind === 'string' ? p.kind : '',
50
+ label: p.label,
51
+ url: typeof p.url === 'string' && p.url ? p.url : null,
52
+ ...(typeof p.message === 'string' && p.message ? { message: p.message } : {}),
53
+ ...(typeof p.enabled === 'boolean' ? { enabled: p.enabled } : {})
54
+ });
55
+ }
56
+ return places;
57
+ }
58
+ function parseRenames(raw) {
59
+ const renames = [];
60
+ const seen = new Set();
61
+ for (const entry of Array.isArray(raw) ? raw : []) {
62
+ if (typeof entry !== 'object' || entry === null)
63
+ continue;
64
+ const r = entry;
65
+ if (typeof r.from !== 'string' || typeof r.to !== 'string')
66
+ continue;
67
+ const direction = r.direction === 'output' ? 'output' : 'input';
68
+ // The dialog keys its rows by direction and name: the first one wins.
69
+ const key = `${direction}:${r.from}`;
70
+ if (seen.has(key))
71
+ continue;
72
+ seen.add(key);
73
+ renames.push({
74
+ direction,
75
+ from: r.from,
76
+ to: r.to,
77
+ places: parseRenamePlaces(r.places)
78
+ });
79
+ }
80
+ return renames;
81
+ }
82
+ export function parseReport(data) {
83
+ const d = (typeof data === 'object' && data !== null ? data : {});
84
+ const iface = (typeof d.interface === 'object' && d.interface !== null ? d.interface : {});
37
85
  return {
38
86
  confirm: d.confirm === true,
39
87
  interfaceLevel: typeof iface.level === 'string' ? iface.level : '',
40
88
  interfaceBreaking: iface.breaking === true,
41
- items
89
+ items: parseImpactItems(d.items),
90
+ refused: d.refused === true,
91
+ refusedMessage: typeof d.refusedMessage === 'string' && d.refusedMessage ? d.refusedMessage : null,
92
+ copyUrl: typeof d.copyUrl === 'string' && d.copyUrl ? d.copyUrl : null,
93
+ renames: parseRenames(d.renames)
42
94
  };
43
95
  }
44
96
  async function errorMessage(response) {
@@ -69,3 +121,37 @@ export async function checkImpact(config, authProvider, workflowId, draft) {
69
121
  return { status: 'error', message: error instanceof Error ? error.message : String(error) };
70
122
  }
71
123
  }
124
+ /**
125
+ * Whether a `copyUrl` may receive the draft and the auth headers: a path on
126
+ * this site (one `/`, not `//` or `/\`), or an `http(s)` address on this
127
+ * site's origin or the API's.
128
+ */
129
+ export function isSafeCopyUrl(config, copyUrl) {
130
+ return resolveRequestUrl(copyUrl, config.baseUrl) !== null;
131
+ }
132
+ /**
133
+ * Save the draft as a new workflow: POST it to the `copyUrl` the impact check
134
+ * named (a path on this site, or a full URL on this site's or the API's
135
+ * origin). Throws with the backend's
136
+ * reason when it refuses. The answer names the copy as `{ data: { id,
137
+ * editorUrl } }`; either may be missing.
138
+ */
139
+ export async function saveAsCopy(config, authProvider, copyUrl, draft) {
140
+ // A path is a path on this site, as the backend wrote it, not one under the API base.
141
+ const url = resolveRequestUrl(copyUrl, config.baseUrl);
142
+ if (url === null)
143
+ throw new Error('The copy address is not on this server');
144
+ const response = await authenticatedFetch(url, { method: 'POST', body: JSON.stringify(draft) }, { config, endpointKey: 'workflows.copy', authProvider });
145
+ if (!response.ok)
146
+ throw new Error(await errorMessage(response));
147
+ const body = (await response.json().catch(() => null));
148
+ if (body?.success === false)
149
+ throw new Error(body.error ?? 'Saving a copy failed');
150
+ const data = body?.data ?? {};
151
+ const editorUrl = data.editorUrl ?? data.editor_url;
152
+ const id = data.id;
153
+ return {
154
+ id: typeof id === 'string' || typeof id === 'number' ? String(id) : null,
155
+ editorUrl: typeof editorUrl === 'string' ? safeLinkUrl(editorUrl) : null
156
+ };
157
+ }
@@ -36,6 +36,15 @@ export declare function listRuns(config: EndpointConfig, workflowId: string, pag
36
36
  }, authProvider?: AuthProvider): Promise<RunSummary[]>;
37
37
  /** The status of one run (`pipelines.status`), or `undefined` when it cannot be read. */
38
38
  export declare function readRunStatus(config: EndpointConfig, pipelineId: string, authProvider?: AuthProvider): Promise<string | undefined>;
39
+ /**
40
+ * The status of one run plus what the site says is happening to it
41
+ * (`activity.kind`, for example `waiting_for_worker`), or `undefined` when it
42
+ * cannot be read. Older backends send no activity.
43
+ */
44
+ export declare function readRunState(config: EndpointConfig, pipelineId: string, authProvider?: AuthProvider): Promise<{
45
+ status: string | undefined;
46
+ activityKind: string | null;
47
+ } | undefined>;
39
48
  /** Re-run a finished run; the answer names the new pipeline. */
40
49
  export declare function rerunRun(config: EndpointConfig, pipelineId: string, authProvider?: AuthProvider): Promise<RunActionResult>;
41
50
  /** Cancel a run that has not finished. */
@@ -52,6 +52,19 @@ export async function readRunStatus(config, pipelineId, authProvider) {
52
52
  const body = (await response.json().catch(() => null));
53
53
  return body?.data?.status;
54
54
  }
55
+ /**
56
+ * The status of one run plus what the site says is happening to it
57
+ * (`activity.kind`, for example `waiting_for_worker`), or `undefined` when it
58
+ * cannot be read. Older backends send no activity.
59
+ */
60
+ export async function readRunState(config, pipelineId, authProvider) {
61
+ const url = buildEndpointUrl(config, config.endpoints.pipelines.status, { id: pipelineId });
62
+ const response = await authenticatedFetch(url, { method: 'GET' }, { config, endpointKey: 'pipelines.status', authProvider });
63
+ if (!response.ok)
64
+ return undefined;
65
+ const body = (await response.json().catch(() => null));
66
+ return { status: body?.data?.status, activityKind: body?.data?.activity?.kind ?? null };
67
+ }
55
68
  /** Re-run a finished run; the answer names the new pipeline. */
56
69
  export async function rerunRun(config, pipelineId, authProvider) {
57
70
  const path = config.endpoints.pipelines.rerun;
@@ -70,6 +70,12 @@ export interface LaunchOptions {
70
70
  * server's own refusal. Value type/schema checking stays with the server.
71
71
  */
72
72
  workflow?: Workflow;
73
+ /**
74
+ * Tell the backend where the run was started from, so its run page can say
75
+ * so. Only `'editor'` is sent today; a backend that does not know the field
76
+ * ignores it.
77
+ */
78
+ origin?: 'editor';
73
79
  }
74
80
  declare class WorkflowLaunchService {
75
81
  /** True when this configuration exposes an explicit launch verb. */
@@ -47,6 +47,8 @@ class WorkflowLaunchService {
47
47
  body.inputs = options.inputs;
48
48
  if (options.sessionId)
49
49
  body.sessionId = options.sessionId;
50
+ if (options.origin)
51
+ body.origin = options.origin;
50
52
  const response = await authenticatedFetch(url, {
51
53
  method: 'POST',
52
54
  headers: { 'Content-Type': 'application/json' },
@@ -81,6 +81,14 @@ export declare class HistoryStore {
81
81
  * how the owner of that state flushes it first.
82
82
  */
83
83
  setBeforeNavigateCallback(callback: (() => void) | null): void;
84
+ /**
85
+ * Set the check that freezes history. While it returns true, `undo()` and
86
+ * `redo()` change nothing (the history position stays, the restore callback
87
+ * is not called) and return false. Pass `null` to remove the check.
88
+ */
89
+ setIsBlockedCheck(check: (() => boolean) | null): void;
90
+ /** Whether history is frozen right now. */
91
+ get isBlocked(): boolean;
84
92
  /**
85
93
  * Release the history service subscription.
86
94
  * Called by the owning instance's destroy(); safe to call repeatedly.
@@ -99,7 +107,8 @@ export declare class HistoryStore {
99
107
  *
100
108
  * Restores the previous workflow state and invokes the restore callback.
101
109
  *
102
- * @returns true if undo was successful, false if at beginning of history
110
+ * @returns true if undo was successful, false if at beginning of history or
111
+ * while history is frozen (see {@link setIsBlockedCheck})
103
112
  */
104
113
  undo(): boolean;
105
114
  /**
@@ -107,7 +116,8 @@ export declare class HistoryStore {
107
116
  *
108
117
  * Restores the next workflow state and invokes the restore callback.
109
118
  *
110
- * @returns true if redo was successful, false if at end of history
119
+ * @returns true if redo was successful, false if at end of history or
120
+ * while history is frozen (see {@link setIsBlockedCheck})
111
121
  */
112
122
  redo(): boolean;
113
123
  /**
@@ -39,6 +39,11 @@ export class HistoryStore {
39
39
  * session into a committed history step (see {@link setBeforeNavigateCallback}).
40
40
  */
41
41
  #onBeforeNavigate = null;
42
+ /**
43
+ * Answers whether history is frozen (for example while the editor is locked).
44
+ * While it says yes, undo and redo do nothing.
45
+ */
46
+ #isBlocked = null;
42
47
  /** Unsubscribe handle for the service subscription. */
43
48
  #unsubscribe;
44
49
  /** The underlying (non-reactive) history service. */
@@ -119,6 +124,18 @@ export class HistoryStore {
119
124
  setBeforeNavigateCallback(callback) {
120
125
  this.#onBeforeNavigate = callback;
121
126
  }
127
+ /**
128
+ * Set the check that freezes history. While it returns true, `undo()` and
129
+ * `redo()` change nothing (the history position stays, the restore callback
130
+ * is not called) and return false. Pass `null` to remove the check.
131
+ */
132
+ setIsBlockedCheck(check) {
133
+ this.#isBlocked = check;
134
+ }
135
+ /** Whether history is frozen right now. */
136
+ get isBlocked() {
137
+ return this.#isBlocked?.() ?? false;
138
+ }
122
139
  /**
123
140
  * Release the history service subscription.
124
141
  * Called by the owning instance's destroy(); safe to call repeatedly.
@@ -146,9 +163,12 @@ export class HistoryStore {
146
163
  *
147
164
  * Restores the previous workflow state and invokes the restore callback.
148
165
  *
149
- * @returns true if undo was successful, false if at beginning of history
166
+ * @returns true if undo was successful, false if at beginning of history or
167
+ * while history is frozen (see {@link setIsBlockedCheck})
150
168
  */
151
169
  undo() {
170
+ if (this.isBlocked)
171
+ return false;
152
172
  // Flush any pending edit session into a committed step first, so undo reverts
153
173
  // exactly that step rather than skipping over an uncommitted edit.
154
174
  this.#onBeforeNavigate?.();
@@ -164,9 +184,12 @@ export class HistoryStore {
164
184
  *
165
185
  * Restores the next workflow state and invokes the restore callback.
166
186
  *
167
- * @returns true if redo was successful, false if at end of history
187
+ * @returns true if redo was successful, false if at end of history or
188
+ * while history is frozen (see {@link setIsBlockedCheck})
168
189
  */
169
190
  redo() {
191
+ if (this.isBlocked)
192
+ return false;
170
193
  // A pending edit session invalidates the redo stack (it is a new change), so
171
194
  // finalize it first; redo then correctly reports nothing to redo.
172
195
  this.#onBeforeNavigate?.();
@@ -28,6 +28,7 @@ import { PortCoordinateStore } from './portCoordinateStore.svelte.js';
28
28
  import { PipelinePanelStore } from './pipelinePanelStore.svelte.js';
29
29
  import { InlineEditStore } from './inlineEditStore.svelte.js';
30
30
  import { EditorModeStore } from './editorModeStore.svelte.js';
31
+ import { EditorLockStore } from './lockStore.svelte.js';
31
32
  import { AttachedRunStore } from './attachedRunStore.svelte.js';
32
33
  import { NodeHighlightStore } from './nodeHighlightStore.svelte.js';
33
34
  import { ConnectDragStore } from './connectDragStore.svelte.js';
@@ -117,6 +118,12 @@ export interface FlowDropInstance {
117
118
  * writes the same store.
118
119
  */
119
120
  readonly editorMode: EditorModeStore;
121
+ /**
122
+ * The lock on this editor: why the workflow is read-only and which actions
123
+ * the banner offers. `fd.lock.set({ reasons, actions })` locks it, `set(null)`
124
+ * unlocks it. While it is set, every edit is refused.
125
+ */
126
+ readonly lock: EditorLockStore;
120
127
  /**
121
128
  * The run attached to the Assistant (`fd.attachedRun.attach(id)`): the chat
122
129
  * request carries it as `attachedRunId`, and the Assistant's run tools read it.